hibernate - UnsupportedOperationException: The application must supply JDBC connections -


if dont set programmatically , call configuration configuration = new configuration().configure(); , use hibernate.properties (as below) works great. try provide username, password , connection url programmatically, weird exceptions, hinting @ hbm file. missing ?

this works

hibernate.connection.driver_class=com.mysql.jdbc.driver hibernate.connection.url=jdbc:mysql://myec2/mcruiseonserverdb?autoreconnect=true&failoverreadonly=false&maxreconnects=10 hsqldb.write_delay_millis=0 shutdown=true hibernate.connection.username=root hibernate.connection.password=mypwd hibernate.connection.pool_size=2 hibernate.dialect=org.hibernate.dialect.mysqlinnodbdialect hibernate.c3p0.idle_test_period=300 hibernate.c3p0.timeout=120 

as per @kshitij recommendation. doing mixed mode.

the hibernate.properties is

hibernate.connection.driver_class=com.mysql.jdbc.driver hsqldb.write_delay_millis=0 shutdown=true hibernate.connection.pool_size=2 hibernate.dialect=org.hibernate.dialect.mysqlinnodbdialect 

the code

string connection = "jdbc:mysql://"             + globals.dbserver             + "/mcruiseonserverdb?autoreconnect=true&failoverreadonly=false&maxreconnects=10";         configuration configuration = new configuration()                .setproperty("hibernate.connection.url", connection)                                             .setproperty("hibernate.connection.username", globals.db_user_name)                  .setproperty("hibernate.connection.password", globals.db_password);         configuration.configure();          sessionfactory = configuration                 .buildsessionfactory(new serviceregistrybuilder()             .buildserviceregistry()); 

the exception

i exception, 1 every mapping resource entry in hbm file.

11 may 2013 08:46:31,969 1300 [main] fatal readonlyoperations  - have chosen ignore runtime exception java.lang.unsupportedoperationexception: application must supply jdbc connections, may fatal, examine 11 may 2013 08:46:31,969 1300 [main] fatal readonlyoperations  - java.lang.unsupportedoperationexception: application must supply jdbc connections 

summary

if use hibernate.properties , no code (no .setproperty in code) works great. if use part hibernate.properties , part code (server, username, password) errors in hbm every mapping property.

i need me figure out missing. should basic.

wow, fixed problem.

sessionfactory = configuration.buildsessionfactory(new serviceregistrybuilder().applysettings(configuration.getproperties()).buildserviceregistry()); 

i missing

.applysettings(configuration.getproperties())

learnings

  1. configure() should called after setproperty
  2. use hibernate.connection.url , not connection.url if use hibernate.dialect=org.hibernate.dialect.mysqlinnodbdialect
  3. set log4j property hibernate logs all, can see more detailed issues
  4. to rid of warn recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. use namespace http://www.hibernate.org/dtd/ instead. refer hibernate 3.6 migration guide!, need replace http://www.hibernate.org/dtd/ in cfg.xml , hbm files too. dont forget teh hbm files, use same dtd.

lastly, referred this, fix this. last advice bill gorder superb.

private static sessionfactory configuresessionfactory()             throws hibernateexception {         configuration configuration = new configuration();         configuration.configure();         serviceregistry serviceregistry = new serviceregistrybuilder()                 .applysettings(configuration.getproperties())                 .buildserviceregistry();         return configuration.buildsessionfactory(serviceregistry);     }   

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -