-->
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.  [ 2 posts ] 
Author Message
 Post subject: table-per-hierarchy 1:1 mapping doesn't use discriminator??
PostPosted: Fri Nov 12, 2004 11:15 am 
Newbie

Joined: Mon Jun 14, 2004 5:35 pm
Posts: 5
Location: Michigan
Hello,

I have a class (ProblemSolvingEntry) with one-to-one mappings to three other classes (ReframingEntry, CommunicatingEntry, DoingEntry). Each of the three classes have keys pointing back to ProblemSolvingEntry. All four of the classes are subclasses of the same superclass (notebook.Entry) and are stored in the same table (implementing the "table per class hierarchy" design). The three subclasses all use the same column to store their key pointing to ProblemSolvingEntry. The problem is, when hibernate attempts load ProblemSolvingEntry and then loads one of the three other classes, it does not use the discriminator in the query. The DB returns the rows for all three classes instead of just the one, and hibernate throws an exception because more than one row is returned for a one-to-one mapping. Is there any way I can get hibernate to add a check on the discriminator to the WHERE clause? Any help is greatly appreciated...

Hibernate version:
hibernate 2
Mapping documents:
<class name="edu.umich.med.cbtlite.notebook.Entry"
table="NotebookEntry" discriminator-value="ENTRY">
<!-- "My Challenges" subclass -->
<subclass name="edu.umich.med.cbtlite.notebook.MyChallengeEntry"
discriminator-value="MYCHALLENGE">
</subclass>

<!-- "Reframing" subclass -->
<subclass name="notebook.ReframingEntry"
discriminator-value="REFRAMING">
<many-to-one name="problemSolvingEntry" column="F1"
class="notebook.ProblemSolvingEntry"
unique="true"/>
</subclass>

<!-- "Communicating" subclass -->
<subclass name="notebook.CommunicatingEntry"
discriminator-value="COMMUNICATING">
<many-to-one name="problemSolvingEntry" column="F1"
class="notebook.ProblemSolvingEntry"
unique="true"/>
</subclass>

<!-- "Doing" subclass -->
<subclass name="notebook.DoingEntry"
discriminator-value="DOING">
<many-to-one name="problemSolvingEntry" column="F1"
class="notebook.ProblemSolvingEntry"
unique="true"/>
</subclass>

<!-- "Brainstorming" subclass -->
<subclass name="notebook.BrainstormingEntry"
discriminator-value="BRAINSTORMING">
<property name="favorable" column="Extra1"/>
<property name="realistic" column="Extra2"/>
<many-to-one name="problemSolvingEntry" column="F1"/>
</subclass>


<!-- "Problem Solving" subclass -->
<subclass name="notebook.ProblemSolvingEntry" discriminator-value="PROBLEMSOLVING">
<many-to-one name="plannedBehavior" column="F1"/>
<many-to-one name="myChallengeEntry" column="F2"/>
<set name="brainStormingEntries" inverse="true" cascade="all" lazy="true">
<key column="F1"/>
<one-to-many
class="notebook.BrainstormingEntry"/>
</set>
<one-to-one name="reframingEntry"
class="notebook.ReframingEntry"
property-ref="problemSolvingEntry"/>
<one-to-one name="communicatingEntry"
class="notebook.CommunicatingEntry
property-ref="problemSolvingEntry"/>
<one-to-one name="doingEntry"
class="notebook.DoingEntry"
property-ref="problemSolvingEntry"/>
</subclass>
</class>
Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
net.sf.hibernate.HibernateException: More than one row with the given identifier was found: 21430273, for class: notebook.ReframingEntry
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:71)
at net.sf.hibernate.loader.EntityLoader.loadByUniqueKey(EntityLoader.java:55)
at net.sf.hibernate.persister.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1103)
at net.sf.hibernate.impl.SessionImpl.loadByUniqueKey(SessionImpl.java:3839)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:235)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2194)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:240)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:836)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:856)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2106)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1980)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1909)
at Test.main(Test.java:95)
Name and version of the database you are using:
mySQL 4.0.20-standard
The generated SQL (show_sql=true):
Hibernate: select problemsol0_.id as id0_, problemsol0_.F1 as F10_, problemsol0_.F2 as F20_, problemsol0_.notebookId as notebookId0_, problemsol0_.timestamp as timestamp0_, problemsol0_.text as text0_ from NotebookEntry problemsol0_ where problemsol0_.id=?
Hibernate: select mychalleng0_.id as id0_, mychalleng0_.notebookId as notebookId0_, mychalleng0_.timestamp as timestamp0_, mychalleng0_.text as text0_ from NotebookEntry mychalleng0_ where mychalleng0_.id=?
Hibernate: select reframinge0_.id as id0_, reframinge0_.F1 as F10_, reframinge0_.notebookId as notebookId0_, reframinge0_.timestamp as timestamp0_, reframinge0_.text as text0_ from NotebookEntry reframinge0_ where reframinge0_.F1=?
Debug level Hibernate log excerpt:
09:52:12,084 DEBUG SessionImpl:2191 - resolving associations for [edu.umich.med.cbtlite.notebook.ReframingEntry#21430275]
09:52:12,084 DEBUG SessionImpl:1975 - loading [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,084 DEBUG SessionImpl:2072 - attempting to resolve [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,100 DEBUG SessionImpl:2088 - resolved object in session cache [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,100 DEBUG SessionImpl:1975 - loading [edu.umich.med.cbtlite.notebook.Notebook#13303809]
09:52:12,100 DEBUG SessionImpl:2215 - done materializing entity [edu.umich.med.cbtlite.notebook.ReframingEntry#21430275]
09:52:12,100 DEBUG SessionImpl:2191 - resolving associations for [edu.umich.med.cbtlite.notebook.ReframingEntry#21430276]
09:52:12,100 DEBUG SessionImpl:1975 - loading [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,100 DEBUG SessionImpl:2072 - attempting to resolve [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,100 DEBUG SessionImpl:2088 - resolved object in session cache [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,100 DEBUG SessionImpl:1975 - loading [edu.umich.med.cbtlite.notebook.Notebook#13303809]
09:52:12,115 DEBUG SessionImpl:2215 - done materializing entity [edu.umich.med.cbtlite.notebook.ReframingEntry#21430276]
09:52:12,115 DEBUG SessionImpl:2191 - resolving associations for [edu.umich.med.cbtlite.notebook.ReframingEntry#21430277]
09:52:12,115 DEBUG SessionImpl:1975 - loading [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,115 DEBUG SessionImpl:2072 - attempting to resolve [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,115 DEBUG SessionImpl:2088 - resolved object in session cache [edu.umich.med.cbtlite.notebook.ProblemSolvingEntry#21430273]
09:52:12,115 DEBUG SessionImpl:1975 - loading [edu.umich.med.cbtlite.notebook.Notebook#13303809]
09:52:12,115 DEBUG SessionImpl:2215 - done materializing entity [edu.umich.med.cbtlite.notebook.ReframingEntry#21430277]
09:52:12,131 DEBUG SessionImpl:560 - closing session
09:52:12,131 DEBUG SessionImpl:3327 - disconnecting session


Top
 Profile  
 
 Post subject: I forgot this, sorry...
PostPosted: Fri Nov 12, 2004 11:18 am 
Newbie

Joined: Mon Jun 14, 2004 5:35 pm
Posts: 5
Location: Michigan
Code between sessionFactory.openSession() and session.close():

ProblemSolvingEntry pse = (ProblemSolvingEntry) mySQLSession.load(ProblemSolvingEntry.class, new Long(21430273));


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

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.