-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem using subclass...
PostPosted: Mon Oct 24, 2005 10:56 am 
Newbie

Joined: Wed Oct 19, 2005 3:45 pm
Posts: 14
I have an architecture in wich there is a parent and various childs implemented as java clasess extends.
I´m using the strategy in wich i have one table per subclass using a discriminator.
The problem is when i have a many to one relation betweenn two children clasess hibernate is looking for the attributes on the parent class and i get a invalid field at database level..
Some help ????


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 11:13 am 
Newbie

Joined: Fri Jun 10, 2005 5:11 am
Posts: 7
You can use joined-subclass instead of a many-to-one associations.

For eg, if you classA is the super class and classB and classC both extends class A, then you can have a joined-subclass mapping under class A for each of the sub classes.

Ravi


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 11:20 am 
Newbie

Joined: Wed Oct 19, 2005 3:45 pm
Posts: 14
My problem is that.

My class A is the superClass
Class B, C and D extends form class A
Class B has a Set of C elements

I´m using table per subclass using discriminator but when i try to get the elements of the set he makes the reference to the class A intead of class B.

Is this a bug or what ???


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 11:31 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Can you show your mapping files ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 11:39 am 
Newbie

Joined: Wed Oct 19, 2005 3:45 pm
Posts: 14
Ok the parent is called ModelElement and the hbm is that:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.integration.core">
   <class name="ModelElement" table="model_element">
      <id name="uuid" type="string" column="uuid">
         <generator class="uuid"/>
      </id>
      <discriminator column="type" type="string"/>
      <property name="name" column="name" type="string" not-null="true"/>
      <property name="created" column="created" type="timestamp" update="false" not-null="true"/>
      <property name="stereotype" column="stereotype" type="string" not-null="true"/>
      <property name="description" column="description" type="string" not-null="false"/>
      <set name="attachments" table="attachment" lazy="true">
         <key column="uuid"/>
         <one-to-many class="com.integration.model.Attachment"/>
      </set>
      <many-to-one name="parent" class="ModelElement" access="property" cascade="save-update, persist, merge">
         <column name="parent_uuid" not-null="false"/>
      </many-to-one>
      <set name="childElements" access="property" cascade="all" inverse="true">
         <key column="parent_uuid"/>
         <one-to-many class="ModelElement"/>
      </set>
      <set name="associationsA" table="association" lazy="true">
         <key column="uuidA"/>
         <one-to-many class="com.integration.model.associations.Association"/>
      </set>
      <set name="associationsB" table="association" lazy="true">
         <key column="uuidB"/>
         <one-to-many class="com.integration.model.associations.Association"/>
      </set>
      <set name="designDecisions" table="modelElement_designDecision" lazy="true" cascade="save-update">
         <key column="model_element_id"/>
         <many-to-many class="com.integration.model.DesignDecision" column="design_decision_id"/>
      </set>
<subclass name="com.integration.model.Task" discriminator-value="task">
         <set name="issues" table="issue" inverse="true">
                  <key column="task_uuid"/>
                  <one-to-many class="com.integration.model.Issue"/>
         </set>
         <join table="task">
            <key column="uuid"/>
               <property name="assignedTo" column="assigned_to" type="string" not-null="true"/>
               <property name="priority" column="priority" type="string" not-null="true"/>
               <property name="percentCompleted" column="percent_completed" type="string" not-null="true"/>
               <property name="estimatedEffort" column="estimated_effort" type="string" not-null="true"/>
               <property name="executedEffort" column="executed_effort" type="string" not-null="true"/>
               <property name="status" column="status" type="string" not-null="true"/>
               <property name="initialDate" column="initial_date" type="string" not-null="true"/>
               <property name="finishDate" column="finish_date" type="string" not-null="true"/>
         </join>
      </subclass>
      <subclass name="com.integration.model.Issue" discriminator-value="issue">
         <join table="issue" fetch="select">
            <key column="uuid"/>
               <property name="impact" column="impact" type="string" not-null="true"/>
               <property name="openingDate" column="opening_date" type="string" not-null="true"/>
               <property name="commitmentDate" column="commitment_date" type="string" not-null="true"/>
               <property name="closingDate" column="closing_date" type="string" not-null="true"/>
               <property name="assignedTo" column="assigned_to" type="string" not-null="true"/>
               <property name="status" column="status" type="string" not-null="true"/>
               <property name="criticity" column="criticity" type="string" not-null="true"/>
               <many-to-one name="task" class="com.integration.model.Task" column="task_uuid"/>
         </join>
      </subclass>
</class>
</hibernate-mapping>

when i call
Code:
Task task = (Task)hsession.get(Task.class, "402880e60714fbbd010714fc6a2d0001");
            System.out.println("ASSIGNED TO: " +task.getAssignedTo());
            System.out.println("ISSUES.SIZE: " +task.getIssues().size());


i got the problem
thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.