-->
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.  [ 7 posts ] 
Author Message
 Post subject: one-to-one association between two joined subclass?
PostPosted: Mon Nov 29, 2004 4:29 pm 
Newbie

Joined: Mon Nov 29, 2004 4:06 pm
Posts: 8
Below is my mapping of a superclass called Entity and two subclasses called Student and Demographic. In my domain model, Student is associated to Demographic (A student can have only one demographic instance). Given the current setup of my mapping file, is possible for my sublcasses to have a one-to-one mapping. If not, how can I go about setting that up? I have read Hibernate In Action and browsed the user forum and was unable to find a similar example (In book) or concern (in forum).


Hibernate version:
hibernate 2.1.7

Mapping documents:

<hibernate-mapping>

<class name="Entity" table="ENTITY">

<id name="id" column="entity_id" type="java.lang.Integer" unsaved-value="null">
<generator class="native" />
</id>
<version name="versionNumber" column="version_number" type="integer" unsaved-value="null" />

<property name="modifiedBy" column="modified_by" type="integer" not-null="true" />
<property name="modified" column="modified" type="timestamp" not-null="false" />

</class>

</hibernate-mapping>



<hibernate-mapping>
<joined-subclass
name="Student"
extends="Entity"
lazy="true"
table="STUDENT">

<key column="entity_id"/>

<one-to-one name="demographic" class="Demographic" cascade="save-update"/>

</joined-subclass>
</hibernate-mapping>





<hibernate-mapping>

<joined-subclass
name="Demographic"
extends="Entity"
table="DEMOGRAPHIC">

<key column="entity_id"/>

<!-- not to sure about this element mapping -->
<id name="id" column="student_id">
<generator class="foreign">
<param name="property">student</param>
</generator>
</id>

<one-to-one name="student" class="Student" constrained="true" />


</joined-subclass>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
None
Full stack trace of any exception that occurs:
None
Mysql 4

The generated SQL (show_sql=true):
None
Debug level Hibernate log excerpt:
None


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 11:01 pm 
Newbie

Joined: Mon Nov 29, 2004 4:06 pm
Posts: 8
Does anyone have any ideas on this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 3:24 am 
Newbie

Joined: Mon Nov 29, 2004 4:06 pm
Posts: 8
Has anyone encountered the above problem before?

Can two subclasses (joined-subclass), having the same parent, have an association together; whether it be one-to-one, one-to-many, etc.

Below is a unit test on the save method. I am not getting any errors, everything gets updated, however, the student id (entity_id) is not the same in the demographic table. They should be the same since it is a one-to-one association via the primary key. (See previous post for mapping). I know I can programatically assigned the key value to the demographic table, however that does not seem to be the correct way of doing it, since hibernate should be taking care of that for me.

Any help is greatly appreciated.

public void testSaveDemographic() throws Exception {
student = sdao.getStudent(new Integer(1));
demographic = new Demographic();

demographic.setStudent(student);
demographic.setFirstName("Curtney");
demographic.setLastName ("Jacobs");
demographic.setGender("M");
demographic.setDateOfBirth(new Date());
demographic.setModifiedBy (new Integer(070172));
ddao.saveDemographic(demographic);
.
.
.
etc.
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 04, 2004 5:42 pm 
Newbie

Joined: Mon Nov 29, 2004 4:06 pm
Posts: 8
Perhaps I am not stating my problem to clearly.


I have a root class (super class) called Entity. This root class stores versioning information for all of its subblcasses, i.e version, modifiedBy, and modifiedDate.

I have mapped this inheritance using hibernate's table per subclass mapping. This works fine!

However, some of my subclasses will have a one-to-one or many-to-one association with other subclasses. How do I mapped this relationship assoication between my subclasses?????

I know of one strategy (which I am currently using) that was described in Hibernate In Action. I am "using a foreign key association" for my one-to-one association between my joined subclass and my demographic joined subclass. This appears to be the only way.

I would like to use the "primary key association to mapped this relationship, however that seems impossible because my super class (Entity) assigns a primary to my sub tables (subclasses).


Please any suggestions, or comments are greatly appreciated.

Thanks inadvance,

Curtney Jacobs


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 5:03 am 
Beginner
Beginner

Joined: Thu Mar 03, 2005 5:01 am
Posts: 33
Location: Wrocław (Poland)
Did You solved this problem? I have exactly the same situation :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 11:13 pm 
Newbie

Joined: Mon Nov 29, 2004 4:06 pm
Posts: 8
Nope.

If you find a solution, please let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 19, 2005 7:44 pm 
Beginner
Beginner

Joined: Thu Mar 03, 2005 5:01 am
Posts: 33
Location: Wrocław (Poland)
curtney wrote:
If you find a solution, please let me know.


As You can see here :

http://forum.hibernate.org/viewtopic.php?t=939648&highlight=

there is some solution. But I dont know how to implement it :(

I was thinking, that I found solution - data was saved, but when I try to access this data I always got org.hibernate.PropertyAccessException...

My solution can You see here :
http://forum.hibernate.org/viewtopic.php?t=940132&highlight=

_________________
bimki


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