• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Hibernate configuration issue: connection provider or hibernate.dialect issue

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You !
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Greenhorn
Posts: 1
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill, that solved my problem as well .
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic