-->
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: Strange hibernate behaviour
PostPosted: Thu May 31, 2007 6:58 am 
Newbie

Joined: Wed May 23, 2007 10:06 am
Posts: 5
Hello, I am trying to make project for studies and I am doing everything as tutorial says but I am getting strange exception:

org.hibernate.ObjectNotFoundException: No row with the given
identifier exists: [szzs.domain.registration.TaskTerm#203]
at org.hibernate.impl.SessionFactoryImpl
$1.handleEntityNotFound(SessionFactoryImpl.java:377)
at
org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:
79)
at
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:
68)
at
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:
111)
at
org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:
140)
at szzs.domain.registration.TaskTerm$$EnhancerByCGLIB$
$3122036f.getSubject(<generated>)
at szzs.tests.HBtest.testRegisterProject(HBtest.java:105)
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: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.OldTestClassRunner.run(OldTestClassRunner.java:
76)
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)

In situation like this:

Long idp, idt, idc, idr1, idr2;

Session session1 = HibernateUtil.openSession();
session1.beginTransaction();
ProjectGroup p1=new ProjectGroup();
TaskTerm t1=new TaskTerm();
ConsultationTerm c1=new ConsultationTerm();
Registry r1=new Registry();
Registry r2=new Registry();

t1.setSubject("TestSubject");
t1.getMembers().put(p1, r1);

c1.setSubject("TestSubjectofCON");
c1.getMembers().put(p1,r2);

idp=(Long) session1.save(p1);
idt=(Long) session1.save(t1);
idc=(Long) session1.save(c1);
idr1=(Long) session1.save(r1);
idr2=(Long) session1.save(r2);
session1.getTransaction().commit();
session1.close();

Session session2 = HibernateUtil.openSession();
session2.beginTransaction();

ProjectGroup p2=(ProjectGroup)
session2.load(ProjectGroup.class, idp);
TaskTerm t2=(TaskTerm) session2.load(TaskTerm.class, idt);
ConsultationTerm c2=(ConsultationTerm)
session2.load(ConsultationTerm.class, idc);

for (Engagement t : p2.getTaskTerms().keySet()){
System.out.println(t.getSubject()); <<<<<<<<<< Here the exception is thrown, moreover p2.getTaskTerms().keySet()) has 2 elements whereas it should have just one
}
My classes are (plus getters/setter and unimportant fields):

public abstract class Engagement {
private Long id;
private Map <ProjectGroup, Registry> members =new HashMap
<ProjectGroup, Registry> ();

}

public class ConsultationTerm extends Engagement {

}

public class TaskTerm extends Engagement{

}

public class ProjectGroup extends RegistrationGroup{

private Map <TaskTerm, Registry > TaskTerms= new HashMap <TaskTerm,
Registry>();//inverse
private Map <ConsultationTerm, Registry > consultationTerms= new
HashMap <ConsultationTerm, Registry>();//inverse

}

public class RegistrationGroup implements Group {
protected Long id;

}

public class Registry {
private Long id;

}

with mapping:

<class name="szzs.domain.registration.Engagement" abstract="true">
<id name="id" column="ENGAGEMENT_ID">
<generator class=...></id>

<map name="members">
<key column="ENGAGEMENT_ID" not-null="true"/>
<map-key-many-to-many column="PROJECTGROUP_ID"
class="szzs.domain.registration.ProjectGroup"/>
<one-to-many class="szzs.domain.registration.Registry"/>
</map>

<union-subclass name="szzs.domain.registration.TaskTerm"
table="TASKTERMS">
</union-subclass>

<union-subclass name="szzs.domain.registration.ConsultationTerm"
table="CONSULTATIONTERMS">
</union-subclass>
</class>

<class name="szzs.domain.registration.RegistrationGroup"
table="REGISTRATIONGROUPS">
<id name="id" column="REGISTRATIONGROUP_ID">
<generator class=...></id>

<joined-subclass name="szzs.domain.registration.ProjectGroup"
table="PROJECTGROUPS">
<key column="PROJECTGROUP_ID"/>

<map name="taskTerms" inverse="true">
<key column="PROJECTGROUP_ID" not-null="true"/>
<map-key-many-to-many column="ENGAGEMENT_ID"
class="szzs.domain.registration.TaskTerm"/>
<one-to-many class="szzs.domain.registration.Registry"/>
</map>

<map name="consultationTerms" inverse="true" >
<key column="PROJECTGROUP_ID" not-null="true"/>
<map-key-many-to-many column="ENGAGEMENT_ID"
class="szzs.domain.registration.ConsultationTerm"/>
<one-to-many class="szzs.domain.registration.Registry"/>
</map>
</joined-subclass>
</class>

<class name="szzs.domain.registration.Registry" table="REGISTRIES">
<id name="id" column="REGISTRY_ID">
<generator class=...></id>
</class>


I really ask for help how should i map my classes to make them work. For me it doesnt matter if i have to keep each of ProjectGroup - ConsultationTerm and ProjectGroup -TaskTerm associations information in different table, or to have one bonus column to remember to which class is the association (like in many-to-any). Still i would like to preserve explicite polymorphism, but not for all cost ofc.


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.