我正在尝试这样:
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