Picked up the HibernateUtil from the JPA example.
Error Trace
Code:
org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: user
at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:44)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:186)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:437)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:194)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy13.merge(Unknown Source)
at com.test.dao.UserDAO.setUser(UserDAO.java:15)
at com.test.test.UserDAOTest.testDAO(UserDAOTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Info Log Trace
Code:
2008-02-26 15:31:22,274 INFO [org.hibernate.cfg.annotations.Version] - Hibernate Annotations 3.2.1.GA
2008-02-26 15:31:22,294 INFO [org.hibernate.cfg.Environment] - Hibernate 3.2.1
2008-02-26 15:31:22,299 INFO [org.hibernate.cfg.Environment] - hibernate.properties not found
2008-02-26 15:31:22,301 INFO [org.hibernate.cfg.Environment] - Bytecode provider name : cglib
2008-02-26 15:31:22,305 INFO [org.hibernate.cfg.Environment] - using JDK 1.4 java.sql.Timestamp handling
2008-02-26 15:31:22,421 INFO [org.hibernate.cfg.Configuration] - configuring from resource: /hibernate.cfg.xml
2008-02-26 15:31:22,421 INFO [org.hibernate.cfg.Configuration] - Configuration resource: /hibernate.cfg.xml
2008-02-26 15:31:22,678 INFO [org.hibernate.cfg.AnnotationConfiguration] - Mapping package com.test.pojo
2008-02-26 15:31:22,717 WARN [org.hibernate.cfg.AnnotationBinder] - Package not found or wo package-info.java: com.test.pojo
2008-02-26 15:31:22,723 INFO [org.hibernate.cfg.Configuration] - Configured SessionFactory: null
2008-02-26 15:31:22,788 INFO [org.hibernate.cfg.AnnotationBinder] - Binding entity from annotated class: com.test.pojo.User
2008-02-26 15:31:22,849 INFO [org.hibernate.cfg.annotations.EntityBinder] - Bind entity com.test.pojo.User on table user
2008-02-26 15:31:22,920 INFO [org.hibernate.cfg.AnnotationBinder] - Binding entity from annotated class: com.test.pojo.Demographic
2008-02-26 15:31:22,920 INFO [org.hibernate.cfg.annotations.EntityBinder] - Bind entity com.test.pojo.Demographic on table demographic
2008-02-26 15:31:23,059 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - Using Hibernate built-in connection pool (not for production use!)
2008-02-26 15:31:23,059 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - Hibernate connection pool size: 3
2008-02-26 15:31:23,060 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - autocommit mode: true
2008-02-26 15:31:23,067 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/chotatest?autoReconnect=true
2008-02-26 15:31:23,067 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - connection properties: {user=root, password=****, autocommit=true}
2008-02-26 15:31:23,355 INFO [org.hibernate.cfg.SettingsFactory] - RDBMS: MySQL, version: 5.0.45-Debian_1ubuntu3.1-log
2008-02-26 15:31:23,355 INFO [org.hibernate.cfg.SettingsFactory] - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.6 ( $Date: 2007-03-09 22:13:57 +0100 (Fri, 09 Mar 2007) $, $Revision: 6341 $ )
2008-02-26 15:31:23,372 INFO [org.hibernate.dialect.Dialect] - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
2008-02-26 15:31:23,378 INFO [org.hibernate.transaction.TransactionFactoryFactory] - Using default transaction strategy (direct JDBC transactions)
2008-02-26 15:31:23,381 INFO [org.hibernate.transaction.TransactionManagerLookupFactory] - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2008-02-26 15:31:23,381 INFO [org.hibernate.cfg.SettingsFactory] - Automatic flush during beforeCompletion(): disabled
2008-02-26 15:31:23,381 INFO [org.hibernate.cfg.SettingsFactory] - Automatic session close at end of transaction: disabled
2008-02-26 15:31:23,381 INFO [org.hibernate.cfg.SettingsFactory] - JDBC batch size: 15
2008-02-26 15:31:23,381 INFO [org.hibernate.cfg.SettingsFactory] - JDBC batch updates for versioned data: disabled
2008-02-26 15:31:23,382 INFO [org.hibernate.cfg.SettingsFactory] - Scrollable result sets: enabled
2008-02-26 15:31:23,382 INFO [org.hibernate.cfg.SettingsFactory] - JDBC3 getGeneratedKeys(): enabled
2008-02-26 15:31:23,382 INFO [org.hibernate.cfg.SettingsFactory] - Connection release mode: auto
2008-02-26 15:31:23,383 INFO [org.hibernate.cfg.SettingsFactory] - Maximum outer join fetch depth: 3
2008-02-26 15:31:23,383 INFO [org.hibernate.cfg.SettingsFactory] - Default batch fetch size: 1
2008-02-26 15:31:23,383 INFO [org.hibernate.cfg.SettingsFactory] - Generate SQL with comments: enabled
2008-02-26 15:31:23,383 INFO [org.hibernate.cfg.SettingsFactory] - Order SQL updates by primary key: disabled
2008-02-26 15:31:23,383 INFO [org.hibernate.cfg.SettingsFactory] - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2008-02-26 15:31:23,385 INFO [org.hibernate.hql.ast.ASTQueryTranslatorFactory] - Using ASTQueryTranslatorFactory
2008-02-26 15:31:23,386 INFO [org.hibernate.cfg.SettingsFactory] - Query language substitutions: {}
2008-02-26 15:31:23,386 INFO [org.hibernate.cfg.SettingsFactory] - JPA-QL strict compliance: disabled
2008-02-26 15:31:23,386 INFO [org.hibernate.cfg.SettingsFactory] - Second-level cache: enabled
2008-02-26 15:31:23,394 INFO [org.hibernate.cfg.SettingsFactory] - Query cache: disabled
2008-02-26 15:31:23,394 INFO [org.hibernate.cfg.SettingsFactory] - Cache provider: org.hibernate.cHibernate: ache.NoCacheProvider
2008-02-26 15:31:23,395 INFO [org.hibernate.cfg.SettingsFactory] - Optimize cache for minimal puts: disabled
2008-02-26 15:31:23,395 INFO [org.hibernate.cfg.SettingsFactory] - Structured second-level cache entries: disabled
2008-02-26 15:31:23,400 INFO [org.hibernate.cfg.SettingsFactory] - Echoing all SQL to stdout
2008-02-26 15:31:23,401 INFO [org.hibernate.cfg.SettingsFactory] - Statistics: disabled
2008-02-26 15:31:23,401 INFO [org.hibernate.cfg.SettingsFactory] - Deleted entity synthetic identifier rollback: disabled
2008-02-26 15:31:23,402 INFO [org.hibernate.cfg.SettingsFactory] - Default entity-mode: pojo
2008-02-26 15:31:23,449 INFO [org.hibernate.impl.SessionFactoryImpl] - building session factory
2008-02-26 15:31:23,775 INFO [org.hibernate.impl.SessionFactoryObjectFactory] - Not binding factory to JNDI, no JNDI name configured
2008-02-26 15:31:23,785 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] - Running hbm2ddl schema export
2008-02-26 15:31:23,786 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] - exporting generated schema to database
2008-02-26 15:31:23,856 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] - schema export complete
Hibernate:
/* insert com.test.pojo.User
*/ insert
into
user
(username, password, name, created)
values
(?, ?, ?, ?)
*********** THIS PART ON FROM DEBUG************
2008-02-26 15:34:06,864 DEBUG [com.test.data.HibernateUtil] - Hibernate initialized, call HibernateUtil.getSessionFactory()
2008-02-26 15:34:06,942 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 12040580469
2008-02-26 15:34:07,030 DEBUG [org.hibernate.transaction.JDBCTransaction] - begin
2008-02-26 15:34:07,030 DEBUG [org.hibernate.jdbc.ConnectionManager] - opening JDBC connection
2008-02-26 15:34:07,031 DEBUG [org.hibernate.transaction.JDBCTransaction] - current autocommit status: true
2008-02-26 15:34:07,031 DEBUG [org.hibernate.transaction.JDBCTransaction] - disabling autocommit
2008-02-26 15:34:07,050 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - executing identity-insert immediately
2008-02-26 15:34:07,051 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2008-02-26 15:34:07,054 DEBUG [org.hibernate.SQL] -
/* insert com.test.pojo.User
*/ insert
into
user
(username, password, name, created)
values
(?, ?, ?, ?)
Hibernate:
/* insert com.test.pojo.User
*/ insert
into
user
(username, password, name, created)
values
(?, ?, ?, ?)
2008-02-26 15:34:07,079 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] - Natively generated identity: 1
2008-02-26 15:34:07,079 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
So does not seem to be a problem with Spring...