-->
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: Driscriminator on same table
PostPosted: Fri Apr 22, 2011 2:02 pm 
Newbie

Joined: Fri Apr 22, 2011 1:50 pm
Posts: 2
I have a mapping of where I have a base table (Tasks) and then an extending table (CRS) but the CRS table actually have date for three different objects. Some of the fields are in common and some are unique. Ignoring the inheritance of the common fields to keep this simple, I have join statements in my three extending classes such as:

Code:
<class name="com.entities.Task" table="tasks"
    abstract="true" discriminator-value="0"

<id name="id" type="int" column="TASK_ID">
  <generator class="identity" />
</id>

<subclass name="com.entities.SoftwareChangeRequest"
    discriminator-value="SCR" extends="com.entities.Task">

  <join table="crs">
    <key column="TASK_ID" />
    .
    .
  </join>
</subclass>


<subclass name="com.entities.ToolChangeRequest"
    discriminator-value="TCR" extends="com.entities.Task">

  <join table="crs">
    <key column="TASK_ID" />
    .
    .
  </join>
</subclass>

</class>


Each of the three instances join on the CRS table and everything works correctly but when looking at the log I see that a join is performed 3 times on CRS table:

Code:
left outer join crs task0_1_ on task0_.TASK_ID=task0_1_.TASK_ID
left outer join crs task0_2_ on task0_.TASK_ID=task0_2_.TASK_ID
left outer join crs task0_3_ on task0_.TASK_ID=task0_3_.TASK_ID


I see why this is happening but I would think that Hibernate would be able to tell that the joined table is the same in all these instances and to just select all fields for all three concrete classes. Is there anyway around this?


Top
 Profile  
 
 Post subject: Re: Driscriminator on same table
PostPosted: Wed Apr 27, 2011 1:24 pm 
Newbie

Joined: Fri Apr 22, 2011 1:50 pm
Posts: 2
Posting this in case someone else runs into this same issue:

I never did find a good solution for this. I ended up creating an abstract object (ChangeRequest) which has all the things from CRS table defined on it through XML. I then set all the getters and setters on the ChangeRequest object to package/default access and made my final classes (with discriminator value still intact) all extend ChangeRequest and have public pass through methods for the items which users of the class should have access to.

Not an ideal solution by any means but except for abstracting the database out more (which may be a good idea but would still have more joins), this is the best solution I could come up with and it still stop the multiple join from occurring,


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.