私はhibernate.cfg.xmlファイルを持ちたくありません。むしろ、以下のように私のコードを通してすべての設定をしたいと思っています。設定のためにhibernate.cfg.xmlファイルを持っていることは必須ですか
private static final SessionFactory factory;
private static final Properties properties;
static
{
properties = new Properties();
properties.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
properties.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/books");
properties.setProperty("hibernate.connection.username", "jhtp7");
properties.setProperty("hibernate.connection.password", "password");
properties.setProperty("hibernate.show_sql", "com.mysql.jdbc.Driver");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
factory = new Configuration().setProperties(properties).configure().
buildSessionFactory();
}
私は上記のアプローチを試みた。しかし、私は、ハイバネートが "./hibernate.cfg.xml file missing
"という例外をスローする問題に直面しています。
ファイルhibernate.cfg.xml
を保管することは本当に必須ですか?事前に
おかげで
コンソールでsqlクエリをログに記録する場合は、次のようにします。configuration.setProperty( "hibernate.show_sql"、 "true"); – Deepak
次にマッピングを指定する方法は? – digz6666
このようにして:configuration.addAnnotatedClass(org.gradle.Person.class); – Deepak