-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: composit-element
PostPosted: Wed Oct 27, 2004 3:04 am 
Newbie

Joined: Wed Jun 02, 2004 6:14 am
Posts: 6
Hello,

I mapped a Class Projekt, which have a List with RefProjektEntity Objects.
The RefProjektEntity Objects have a List with RefProjektDDEDDI-Objects.
When I map the second List, in the RefProjektEntity Class with the composit-element, the primary-key projekt_dde_ddi_id are not load from the database. When I explizit map this property, the key is load, but if I want to save a projekt Object I became the error dupicate column. Hibernate have in the insert- statement the projekt_dde_ddi_id doubeld.
Then I canged the mapping, and don't use the compostite-element. I use
<one-to-many class="RefProjektDDEDDI" />. This work's for getting the data but when I want to save a new Object then I get the error code behind.

I doen't know what to do. I must get all datas and save/update the Objects?

Thanks Claudia





Hibernate version:2

Mapping documents:
<class name="Projekt" table="DATA_PROJEKT">
<id name="projekt_id" type="java.lang.Long">
<column name="PROJEKT_ID" sql-type="number"not-null="true"/>
<generator class="sequence">
<param name="sequence">SEQ_DATA_PROJEKT</param>
</generator>
</id>
<list name="projektDDE" table="REF_PROJEKT_ENTITY" inverse="true" cascade="all-delete-orphan">
<key column="projekt_id"/>
<index column="projekt_entity_id"/>
<one-to-many class="RefProjektEntity" />
</list>
</class>

<class name="RefProjektEntity" table="REF_PROJEKT_ENTITY">
<id name="refProjektEntity_id" type="java.lang.Long">
<column name="PROJEKT_ENTITY_ID" sql-type="number" not-null="true" />
<generator class="sequence">
<param name="sequence">SEQ_REF_PROJEKT_ENTITY</param>
</generator>
</id>
<list name="items" table="REF_PROJEKT_DDE_DDI" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="projekt_entity_id"/>
<index column="projekt_dde_ddi_id"/>
<!--<one-to-many class="RefProjektDDEDDI" />-->
<composite-element class="RefProjektDDEDDI">
<!-- <property name="projekt_dde_ddi_id" type="java.lang.Long">
<column name="PROJEKT_DDE_DDI_ID" sql-type="NUMBER" />
</property>-->
<property name="info" type="string">
<column name="INFO" sql-type="VARCHAR(100)" />
</property>
</composite-element>
</list>
</class>

<class name="RefProjektDDEDDI" table="REF_PROJEKT_DDE_DDI">
<id name="projekt_dde_ddi_id" type="java.lang.Long">
<column name="PROJEKT_DDE_DDI_ID" sql-type="number" not-null="true" />
<generator class="sequence">
<param name="sequence">SEQ_REF_PROJEKT_DDE_DDI</param>
</generator>
</id>
<property name="info" type="string">
<column name="INFO" sql-type="VARCHAR(100)" />
</property>
<property name="projekt_entity_id" type="java.lang.Long">
<column name="PROJEKT_ENTITY_ID" sql-type="NUMBER" />
</property>
<many-to-one name="item" class="Item" column="ITEM_ID" />

</class>

Code between sessionFactory.openSession() and session.close():
save-code
Transaction tx=null;
session =this.getSession();
tx=session.beginTransaction();

Projekt p=_projekt.getProkekt();

Long gen=(Long)session.save(p);

List list=p.getProjektDDE();
for(int i=0;i<list.size() ;i++){
RefProjektEntity ref=(RefProjektEntity)list.get(i);
ref.setProjekt_id(gen);
Long key=(Long)session.save(ref);
}
session.flush();

tx.commit();

get-Code:

session =this.getSession();
projekt=(Projekt)session.createCriteria(Projekt.class).add(Expression.eq("projekt_id",_projekt_id)).uniqueResult();

Full stack trace of any exception that occurs:
Hibernate: select SEQ_DATA_PROJEKT.nextval from dual
Hibernate: select SEQ_REF_PROJEKT_ENTITY.nextval from dual
Hibernate: insert into DATA_PROJEKT (NAME, INFO, OWNER_USER_ID, LASTUPDATE, PROJEKT_ID) values (?, ?, ?, ?, ?)
Hibernate: insert into REF_PROJEKT_ENTITY (INFO, VARIANTE, entity_id, Projekt_ID, LASTUPDATE, PROJEKT_ENTITY_ID) values (?, ?, ?, ?, ?, ?)
Hibernate: update REF_PROJEKT_DDE_DDI set projekt_entity_id=?, projekt_dde_ddi_id=? where PROJEKT_DDE_DDI_ID=?
27.10.2004 08:48:36 net.sf.hibernate.impl.SessionImpl execute
SCHWERWIEGEND: Could not synchronize database state with session
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: de.vit.AdisAded.modelHibernate.beans.RefProjektDDEDDI
at net.sf.hibernate.impl.SessionImpl.throwTransientObjectException(SessionImpl.java:2759)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2751)
at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:46)
at net.sf.hibernate.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:384)
at net.sf.hibernate.collection.List.writeTo(List.java:299)
at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:523)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2364)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)
at de.vit.AdisAded.modelHibernate.builder.ProjektBuilder.save(ProjektBuilder.java:538)
at de.vit.AdisAded.modelHibernate.test.ProjektBuilderTest.testSave(ProjektBuilderTest.java:100)
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:324)
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.netbeans.modules.junit.testrunner.JUnitTestRunner.doRun(JUnitTestRunner.java:277)
at org.netbeans.modules.junit.testrunner.JUnitTestRunner.start(JUnitTestRunner.java:325)
at org.netbeans.modules.junit.testrunner.JUnitTestRunner.main(JUnitTestRunner.java:189)
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: de.vit.AdisAded.modelHibernate.beans.RefProjektDDEDDI
at net.sf.hibernate.impl.SessionImpl.throwTransientObjectException(SessionImpl.java:2759)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2751)
at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:46)
at net.sf.hibernate.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:384)
at net.sf.hibernate.collection.List.writeTo(List.java:299)
at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:523)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2364)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)
at de.vit.AdisAded.modelHibernate.builder.ProjektBuilder.save(ProjektBuilder.java:538)
at de.vit.AdisAded.modelHibernate.test.ProjektBuilderTest.testSave(ProjektBuilderTest.java:100)
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:324)
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.netbeans.modules.junit.testrunner.JUnitTestRunner.doRun(JUnitTestRunner.java:277)
at org.netbeans.modules.junit.testrunner.JUnitTestRunner.start(JUnitTestRunner.java:325)
at org.netbeans.modules.junit.testrunner.JUnitTestRunner.main(JUnitTestRunner.java:189)
Hibernate: select this.PROJEKT_ID as PROJEKT_ID0_, this.NAME as NAME0_, this.INFO as INFO0_, this.OWNER_USER_ID as OWNER_US4_0_, this.LASTUPDATE as LASTUPDATE0_ from DATA_PROJEKT this where this.PROJEKT_ID=?
Hibernate: select projektdde0_.PROJEKT_ENTITY_ID as PROJEKT_1___, projektdde0_.projekt_id as projekt_id__, projektdde0_.projekt_entity_id as projekt_8___, projektdde0_.PROJEKT_ENTITY_ID as PROJEKT_1_1_, projektdde0_.INFO as INFO1_, projektdde0_.VARIANTE as VARIANTE1_, projektdde0_.entity_id as entity_id1_, projektdde0_.Projekt_ID as Projekt_ID1_, projektdde0_.LASTUPDATE as LASTUPDATE1_, entity1_.ENTITY_ID as ENTITY_ID0_, entity1_.BESCHREIBUNG as BESCHREI2_0_, entity1_.DDE as DDE0_, entity1_.NAME as NAME0_, entity1_.JAHR as JAHR0_ from REF_PROJEKT_ENTITY projektdde0_, kat_entity entity1_ where projektdde0_.projekt_id=? and projektdde0_.entity_id=entity1_.ENTITY_ID(+)
Hibernate: select items0_.JAHR as JAHR__, items0_.item_id as item_id__, items0_.art_id as art_id__, items0_.entity_id as entity_id__, items0_.ref_entity_item_id as ref_enti5___, item1_.ITEM_ID as ITEM_ID0_, item1_.DDI as DDI0_, item1_.NAME as NAME0_, item1_.L


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.