Hibernate version: 2.1.6
I can connect throw a jdbc3 driver to my postgresql 7.4 but hibernate can open a jdbc connection.
I'm a new hibernate user and i tried some examples.
This same example that i am going to post here works with firebird 1.5 ss and MySQL 4.0.20 but fails with posgresql.
Even with firebird, and mysql i get a connection throw a jdbc connection without hibernate
I'm working on a gentoo linux 2.6.8.1
The driver is in the classpath..
Mapping documents:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="hello.Message" table="MESSAGES">
<id name="id" column="MESSAGE_ID">
<generator class="increment"/>
</id>
<property name="text" column="MESSAGE_TEXT"/>
<many-to-one name="nextMessage" cascade="all" column="NEXT_MESSAGE_ID"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
SessionFactory sf = getSessionFactory();
Session sess = sf.openSession();
Transaction trans = sess.beginTransaction();
Message newmsg = new Message("123 213 21333");
sess.save(newmsg);
trans.commit();
sess.close();
Full stack trace of any exception that occurs:
20:39:54,168 INFO Environment:469 - Hibernate 2.1.6
20:39:54,191 INFO Environment:503 - loaded properties from resource hibernate.properties: {hibernate.c3p0.timeout=300, hibernate.connection.driver_class=org.postgresql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.c3p0.max_size=20, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.c3p0.idle_test_period=3000, hibernate.c3p0.min_size=5, hibernate.connection.username=postgres, hibernate.connection.url=jdbc:postgresql://localhost:5432/mydb, hibernate.connection.password=8110humbi, hibernate.c3p0.max_statement=50}
20:39:54,223 INFO Environment:529 - using CGLIB reflection optimizer
20:39:54,244 INFO Configuration:895 - configuring from resource: /hibernate.cfg.xml
20:39:54,245 INFO Configuration:867 - Configuration resource: /hibernate.cfg.xml
20:39:55,564 INFO Configuration:331 - Mapping resource: hello/Message.hbm.xml
20:39:56,573 INFO Binder:229 - Mapping class: hello.Message -> MESSAGES
20:39:57,045 INFO Configuration:1053 - Configured SessionFactory: null
20:39:57,046 INFO Configuration:627 - processing one-to-many association mappings
20:39:57,051 INFO Configuration:636 - processing one-to-one association property references
20:39:57,052 INFO Configuration:661 - processing foreign key constraints
20:39:57,132 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
20:39:57,143 INFO SettingsFactory:63 - Use outer join fetching: true
20:39:57,155 INFO C3P0ConnectionProvider:48 - C3P0 using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/mydb
20:39:57,156 INFO C3P0ConnectionProvider:49 - Connection properties: {user=postgres, password=*******}
20:39:57,255 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@c980c9 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@4a6cbf [ acquireIncrement -> 1, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, maxIdleTime -> 1800, maxPoolSize -> 5, maxStatements -> 0, minPoolSize -> 3, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@12611a7 [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:postgresql://localhost/mydb, properties -> {user=postgres, password=*****i} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -> null, numHelperThreads -> 3 ]
20:39:58,094 WARN SettingsFactory:96 - Could not obtain connection metadata
java.sql.SQLException: ERROR: SET AUTOCOMMIT TO OFF is no longer supported
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$ProxyConnectionInvocationHandler.invoke(C3P0PooledConnection.java:733)
at com.mchange.v2.c3p0.impl.$Proxy0.setAutoCommit(Unknown Source)
at net.sf.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1155)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789)
at Runner.getSessionFactory(Runner.java:76)
at Runner.main(Runner.java:25)
20:39:58,098 INFO SettingsFactory:103 - Use scrollable result sets: false
20:39:58,098 INFO SettingsFactory:106 - Use JDBC3 getGeneratedKeys(): false
20:39:58,099 INFO SettingsFactory:109 - Optimize cache for minimal puts: false
20:39:58,100 INFO SettingsFactory:115 - echoing all SQL to stdout
20:39:58,101 INFO SettingsFactory:118 - Query language substitutions: {}
20:39:58,102 INFO SettingsFactory:129 - cache provider: net.sf.ehcache.hibernate.Provider
20:39:58,114 INFO Configuration:1116 - instantiating and configuring caches
20:39:58,669 INFO SessionFactoryImpl:118 - building session factory
20:39:58,996 INFO ReflectHelper:186 - reflection optimizer disabled for: hello.Message, IllegalArgumentException: Cannot find matching method/constructor
20:39:59,423 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
20:39:59,557 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: null
20:39:59,558 ERROR JDBCExceptionReporter:46 - ERROR: SET AUTOCOMMIT TO OFF is no longer supported
20:39:59,559 ERROR JDBCExceptionReporter:38 - Cannot open connection
java.sql.SQLException: ERROR: SET AUTOCOMMIT TO OFF is no longer supported
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$ProxyConnectionInvocationHandler.invoke(C3P0PooledConnection.java:733)
at com.mchange.v2.c3p0.impl.$Proxy0.setAutoCommit(Unknown Source)
at net.sf.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:286)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3326)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3286)
at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2231)
at Runner.main(Runner.java:28)
HibernateException
Cannot open connection
ERROR: SET AUTOCOMMIT TO OFF is no longer supported
hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Settings for a local PostgreSQL database. -->
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost/mydb</property>
<property name="connection.username">postgres</property>
<property name="connection.password">8110humbi</property>
<!-- Use the C3P0 connection pool.-->
<property name="c3p0.min_size">3</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.timeout">1800</property>
<!-- Use the Hibernate built-in pool for tests. -->
<property name="connection.pool_size">1</property>
<!-- Use EHCache but not the query cache. -->
<property name="cache.provider_class">net.sf.ehcache.hibernate.Provider</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_minimal_puts">false</property>
<!-- Print SQL to stdout. -->
<property name="show_sql">true</property>
<!-- CaveatEmptor mapping files. -->
<mapping resource="hello/Message.hbm.xml"/>
</session-factory>
</hibernate-configuration>
|