私はこのようにしようとしています:
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
hibernateProperties.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
hibernateProperties.setProperty("hibernate.connection.url", "jdbc:mysql://" + source.getHost() + "/" + source.getDataBase());
hibernateProperties.setProperty("hibernate.connection.username", source.getUsername());
hibernateProperties.setProperty("hibernate.connection.password", source.getPassword());
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", "validate");
Configuration configuration = new Configuration();
configuration.setProperties(hibernateProperties);
configuration.setProperty("packagesToScan", "com.company.comparer.entity");
SessionFactory sessionFactory = configuration.configure().buildSessionFactory(
new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry());
それは機能していません:)
4176 2012-11-28 17:48:52,583 - [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {4.1.1}
4178 2012-11-28 17:48:52,585 - [main] INFO org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
4179 2012-11-28 17:48:52,586 - [main] INFO org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
4195 2012-11-28 17:48:52,602 - [main] INFO org.hibernate.cfg.Configuration - HHH000043: Configuring from resource: /hibernate.cfg.xml
4195 2012-11-28 17:48:52,602 - [main] INFO org.hibernate.cfg.Configuration - HHH000040: Configuration resource: /hibernate.cfg.xml
私の最後の行の後、私のアプリケーションは機能から抜け出し、何もしません:)
デバッグすると、Spring によってキャッチされた次のような例外があることがわかります。
org.hibernate.HibernateException: /hibernate.cfg.xml not found
これを解決する適切な方法を教えてください。
エンティティ(javax として注釈が付けられているもの)のパッケージをスキャンしたいのですが、一部は使用hibernate.cfg.xml
せず、複数datasources
またはpersistence units
.. 動的であるため、プログラムで実行したいだけですdatasources