Please help me with following question, I am looking for several days now for an answer, I scanned a lot of forum-messages, in several languages, even languages I don't understand.
Thanks in advance
Bert
Hibernate version: 3.0.5
Mapping documents: 2 hbm-files:
----------------------
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.xxx.rm.common.archetyped.Archetyped" table="archetyped">
<id name="id" type="long">
<generator class="identity"/>
</id>
<property name="referenceModelVersion" column="reference_model_version" type="string" />
<many-to-one name="archetypeID" column="archetype_id" cascade="all" />
</class>
<query name="find.archetyped.by.archetypeid">
from org.xxx.rm.common.archetyped.Archetyped as a where a.archetypeID.value = ?
</query>
</hibernate-mapping>
-------------------------
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.openehr.rm.support.identification.ObjectID"
abstract="true"
table="object_id">
<id name="id" type="long">
<generator class="identity"/>
</id>
<discriminator/>
<property name="value" column="_value" type="string"/>
<subclass name="org.xxx.rm.support.identification.ArchetypeID"
discriminator-value="ArchetypeID"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
I use the springframework-class: HibernateDaoSupport:
public class ArchetypedDaoImpl extends HibernateDaoSupport
implements ArchetypedDao {
In this class I have a method save:
public void save(Archetyped archetyped) {
getHibernateTemplate().save(archetyped);
getHibernateTemplate().flush();
}
and a method find:
public Archetyped findByArchetypedID(ArchetypeID archetypedid){
List ret = getHibernateTemplate().findByNamedQuery(
"find.archetyped.by.archetypeid", archetypedid);
if(ret.isEmpty()) {
return null;
}
return (Archetyped) ret.get(0);
}
Name and version of the database you are using:
MySQL 4.1.10a
Full stack trace of any exception that occurs:
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: org.openehr.rm.support.identification.ArchetypeID; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.openehr.rm.support.identification.ArchetypeID
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.openehr.rm.support.identification.ArchetypeID
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:99)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:69)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1115)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1177)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.springframework.orm.hibernate3.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:893)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:884)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:880)
at se.acode.openehr.dao.orm.ArchetypedDaoImpl.findByArchetypedID(ArchetypedDaoImpl.java:37)
at se.acode.openehr.dao.orm.ArchetypedDaoTest.testFind(ArchetypedDaoTest.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
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)
The generated SQL (show_sql=true):
please look at debug-log below
Debug level Hibernate log excerpt:
The DEBUG-log from the save-action
DEBUG [main] (SessionFactoryUtils.java:329) - Opening Hibernate Session
DEBUG [main] (SessionImpl.java:250) - opened session at timestamp: 4774172045312001
DEBUG [main] (DefaultSaveOrUpdateEventListener.java:159) - saving transient instance
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [main] (AbstractSaveEventListener.java:133) - saving [org.xxx.rm.common.archetyped.Archetyped#<null>]
DEBUG [main] (AbstractSaveEventListener.java:195) - executing insertions
DEBUG [main] (Cascades.java:836) - processing cascade ACTION_SAVE_UPDATE for: org.xxx.rm.common.archetyped.Archetyped
DEBUG [main] (Cascades.java:153) - cascading to saveOrUpdate: org.xxx.rm.support.identification.ArchetypeID
DEBUG [main] (AbstractSaveEventListener.java:410) - transient instance of: org.xxx.rm.support.identification.ArchetypeID
DEBUG [main] (DefaultSaveOrUpdateEventListener.java:159) - saving transient instance
DEBUG [main] (AbstractSaveEventListener.java:133) - saving [org.xxx.rm.support.identification.ArchetypeID#<null>]
DEBUG [main] (AbstractSaveEventListener.java:195) - executing insertions
DEBUG [main] (BasicEntityPersister.java:1732) - Inserting entity: org.xxx.rm.support.identification.ArchetypeID (native id)
DEBUG [main] (AbstractBatcher.java:290) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main] (ConnectionManager.java:296) - opening JDBC connection
DEBUG [main] (AbstractBatcher.java:324) - insert into object_id (_value, class) values (?, 'ArchetypeID')
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (BasicEntityPersister.java:1612) - Dehydrating entity: [org.xxx.rm.support.identification.ArchetypeID#<null>]
DEBUG [main] (NullableType.java:59) - binding 'zorggemak-ehr_rm-entry.biochemistry_result_cholesterol-cholesterol.2' to parameter: 1
DEBUG [main] (IdentifierGeneratorFactory.java:37) - Natively generated identity: 36
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement
DEBUG [main] (Cascades.java:861) - done processing cascade ACTION_SAVE_UPDATE for: org.xxx.rm.common.archetyped.Archetyped
DEBUG [main] (BasicEntityPersister.java:1732) - Inserting entity: org.xxx.rm.common.archetyped.Archetyped (native id)
DEBUG [main] (AbstractBatcher.java:290) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main] (AbstractBatcher.java:324) - insert into archetyped (reference_model_version, archetype_id) values (?, ?)
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (BasicEntityPersister.java:1612) - Dehydrating entity: [org.xxx.rm.common.archetyped.Archetyped#<null>]
DEBUG [main] (NullableType.java:59) - binding '1.0' to parameter: 1
DEBUG [main] (NullableType.java:59) - binding '36' to parameter: 2
DEBUG [main] (IdentifierGeneratorFactory.java:37) - Natively generated identity: 36
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement
DEBUG [main] (Cascades.java:836) - processing cascade ACTION_SAVE_UPDATE for: org.xxx.rm.common.archetyped.Archetyped
DEBUG [main] (Cascades.java:861) - done processing cascade ACTION_SAVE_UPDATE for: org.xxx.rm.common.archetyped.Archetyped
DEBUG [main] (HibernateAccessor.java:393) - Eagerly flushing Hibernate session
DEBUG [main] (AbstractFlushingEventListener.java:52) - flushing session
DEBUG [main] (AbstractFlushingEventListener.java:102) - processing flush-time cascades
DEBUG [main] (Cascades.java:836) - processing cascade ACTION_SAVE_UPDATE for: org.xxx.rm.common.archetyped.Archetyped
DEBUG [main] (Cascades.java:153) - cascading to saveOrUpdate: org.xxx.rm.support.identification.ArchetypeID
DEBUG [main] (AbstractSaveEventListener.java:394) - persistent instance of: org.xxx.rm.support.identification.ArchetypeID
DEBUG [main] (DefaultSaveOrUpdateEventListener.java:103) - ignoring persistent instance
DEBUG [main] (DefaultSaveOrUpdateEventListener.java:140) - object already associated with session: [org.xxx.rm.support.identification.ArchetypeID#36]
DEBUG [main] (Cascades.java:861) - done processing cascade ACTION_SAVE_UPDATE for: org.xxx.rm.common.archetyped.Archetyped
DEBUG [main] (AbstractFlushingEventListener.java:150) - dirty checking collections
DEBUG [main] (AbstractFlushingEventListener.java:167) - Flushing entities and processing referenced collections
DEBUG [main] (AbstractFlushingEventListener.java:203) - Processing unreferenced collections
DEBUG [main] (AbstractFlushingEventListener.java:217) - Scheduling collection removes/(re)creates/updates
DEBUG [main] (AbstractFlushingEventListener.java:79) - Flushed: 0 insertions, 0 updates, 0 deletions to 2 objects
DEBUG [main] (AbstractFlushingEventListener.java:85) - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG [main] (Printer.java:83) - listing entities:
DEBUG [main] (Printer.java:90) - org.xxx.rm.support.identification.ArchetypeID{value=zorggemak-ehr_rm-entry.biochemistry_result_cholesterol-cholesterol.2, id=36}
DEBUG [main] (Printer.java:90) - org.xxx.rm.common.archetyped.Archetyped{referenceModelVersion=1.0, archetypeID=org.xxx.rm.support.identification.ArchetypeID#36, id=36}
DEBUG [main] (AbstractFlushingEventListener.java:267) - executing flush
DEBUG [main] (AbstractFlushingEventListener.java:294) - post flush
DEBUG [main] (SessionFactoryUtils.java:785) - Closing Hibernate Session
DEBUG [main] (SessionImpl.java:269) - closing session
DEBUG [main] (ConnectionManager.java:317) - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG [main] (JDBCContext.java:283) - after transaction completion
DEBUG [main] (SessionImpl.java:403) - after transaction completion
DEBUG [main] (SessionFactoryUtils.java:329) - Opening Hibernate Session
DEBUG [main] (SessionImpl.java:250) - opened session at timestamp: 4774172045950976
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [main] (HibernateAccessor.java:393) - Eagerly flushing Hibernate session
DEBUG [main] (SessionFactoryUtils.java:785) - Closing Hibernate Session
DEBUG [main] (SessionImpl.java:269) - closing session
the DEBUG-log from the find action
DEBUG [main] (SessionFactoryUtils.java:329) - Opening Hibernate Session
DEBUG [main] (SessionImpl.java:250) - opened session at timestamp: 4774172046012416
DEBUG [main] (SessionImpl.java:829) - find:
from org.xxx.rm.common.archetyped.Archetyped as a where a.archetypeID.value = ?
DEBUG [main] (QueryParameters.java:221) - parameters: [org.xxx.rm.support.identification.ArchetypeID#null]
DEBUG [main] (QueryParameters.java:224) - named parameters: {}
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [main] (QueryTranslatorImpl.java:113) - compile() : The query is already compiled, skipping...
DEBUG [main] (AbstractBatcher.java:290) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main] (ConnectionManager.java:296) - opening JDBC connection
DEBUG [main] (AbstractBatcher.java:324) - select archetyped0_.id as id, archetyped0_.reference_model_version as reference2_1_, archetyped0_.archetype_id as archetype3_1_ from archetyped archetyped0_, object_id archetypei1_ where archetyped0_.archetype_id=archetypei1_.id and archetypei1_._value=?
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement
DEBUG [main] (JDBCContext.java:322) - after autocommit
DEBUG [main] (SessionImpl.java:403) - after transaction completion
DEBUG [main] (SessionFactoryUtils.java:785) - Closing Hibernate Session
DEBUG [main] (SessionImpl.java:269) - closing session
DEBUG [main] (ConnectionManager.java:317) - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG [main] (JDBCContext.java:283) - after transaction completion
DEBUG [main] (SessionImpl.java:403) - after transaction completion
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html