0
当我使用hibernate.properties文件,我可以成功地从我的配置对象创建一个会话:Hibernate的编程配置不工作
Configuration configuration = new Configuration()
.addAnnotatedClass(WeatherResponse.class);
SessionFactory sessionFactory = configuration.buildSessionFactory();
代替hibernate.properties不过,我想使用类型安全的配置库中为了能够通过CONFIGS作为环境变量,所以我删除hibernate.properties和编程设置属性如下:
Configuration configuration = new Configuration()
.addAnnotatedClass(WeatherResponse.class)
.setProperty("hibernate.connection.username", config.getString("user"))
.setProperty("hibernate.connection.password", config.getString("pass"))
.setProperty("hibernate.connection.driver_class", config.getString("driver"))
.setProperty("hibernate.connection.url", config.getString("url"))
.setProperty("hibernate.dialect", config.getString("dialect"));
SessionFactory sessionFactory = configuration.buildSessionFactory();
但即使我设置的所有属性,我在我的属性文件,我得到错误:
16:49:55.338 [qtp550572371-22] INFO org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
16:49:55.340 [qtp550572371-22] INFO org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
16:49:55.379 [qtp550572371-22] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
16:49:55.486 [qtp550572371-22] WARN o.h.e.j.c.i.ConnectionProviderInitiator - HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
16:49:55.487 [qtp550572371-22] WARN o.h.e.j.e.i.JdbcEnvironmentInitiator - HHH000342: Could not obtain connection to query metadata : The application must supply JDBC connections
16:49:55.495 [qtp550572371-22] WARN o.e.jetty.servlet.ServletHandler - /weather/new+york
org.jboss.resteasy.spi.UnhandledException: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
我使用Hibernate的核心5.2.2.Final和休眠的注解3.5.6决赛和MySQL连接的Java 6.0.3和使用吉斯依赖注入,我不使用Spring。
你在使用'@ Configuration'吗? –
不知道我应该在哪里使用它,我使用Guice进行依赖注入,而不是Spring – iman
对不起,我只用它与春天。 –