my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes Hibernate configuration issue: connection provider or hibernate.dialect issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate configuration issue: connection provider or hibernate.dialect issue" Watch "Hibernate configuration issue: connection provider or hibernate.dialect issue" New topic
Author

Hibernate configuration issue: connection provider or hibernate.dialect issue

Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
I've been beating my head against this issue with hibernate all day. It appears to me that hibernate is not finding the properties that I'm setting and its complaining about 'hibernate.dialect' not being set. But its also complaining about 'no appropriate connection provider', so I'm not sure what the root issue is. In any case, I've boiled it down to a small test case the demonstrates the problem:



$ ls -1 lib
antlr-2.7.7.jar
c3p0-0.9.1.jar
classmate-0.5.4.jar
commons-beanutils-1.7.0.jar
commons-chain-1.1.jar
commons-collections-3.2.1.jar
commons-digester-1.8.jar
commons-lang-2.4.jar
commons-logging-1.1.jar
commons-validator-1.3.1.jar
dom4j-1.6.1.jar
hibernate-c3p0-4.0.0.Final.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.0.0.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
jandex-1.0.3.Final.jar
javassist-3.12.1.GA.jar
jboss-logging-3.1.0.CR2.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
oro-2.0.8.jar
servlet-api-2.5.jar
slf4j-api-1.6.1.jar
slf4j-simple-1.6.1.jar
sslext-1.2-0.jar
struts-core-1.3.8.jar
struts-taglib-1.3.8.jar
struts-tiles-1.3.8.jar
velocity-1.7.jar
velocity-tools-2.0.jar
xml-apis-1.0.b2.jar


$java test.HibernateConfig
Jan 11, 2012 10:28:35 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Jan 11, 2012 10:28:35 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.0.0.Final}
Jan 11, 2012 10:28:35 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jan 11, 2012 10:28:35 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jan 11, 2012 10:28:35 PM org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator initiateService
WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
Exception in thread "main" org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:170)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
at test.HibernateConfig.getHibernateSessionFactory(HibernateConfig.java:29)
at test.HibernateConfig.main(HibernateConfig.java:35)


All the jar files that I listed in the lib directory are in my classpath. Maybe I'm missing something. Maybe I don't have the syntax for the configuration correct. I can't figure it out at this point. Can anybody help?
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
Finally figured it out.

The problem is c.buildSessionFactory(new ServiceRegistryBuilder().buildServiceRegistry());

c.buildSessionFactory() is the way to go, even though it has been deprecated in hibernate 4.0.0.
Looking into what it does, it creates a serviceregistry and then copies the properties from the configuration over into the serviceregistry. It is not enough to use an empty service registry. It appears that the intent was to deprecate the entire Configuration class in hibernate 4.0.0. I have not found a hibernate configuration example that only uses the service registry and does not use configuration yet.

I chalk this up to the unhelpful deprecation documentation on c.buildSessionFactory().
Nadine Moranal
Greenhorn

Joined: Aug 23, 2012
Posts: 1
Thank You !
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1672
    
    7

NO. Don't go back to using deprecated stuff.

You need to call configure() on your configuration after setting the properties. When you create your ServiceRegistry make sure to call applySettings and pass it the properties from the configuration. See the example below.




[How To Ask Questions][Read before you PM me]
Ahmed el-Sawalhy
Greenhorn

Joined: Aug 15, 2011
Posts: 1

Thanks Bill, that solved my problem as well .
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate configuration issue: connection provider or hibernate.dialect issue