-->
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: ont-to-one in joined-subclass
PostPosted: Wed Apr 11, 2007 2:28 pm 
Newbie

Joined: Wed Apr 11, 2007 2:11 pm
Posts: 10
Hi
I am using hibernate 3.x to persist a mySQL data base. This is my first project using hibernate I have created the mapping document POJOS and I can generate the database. However I have some doubts about the way the database is generated I have a Joined-subclass that has a one-to-one element. In the generated database tables I couldn’t find even a hint of the one-to-one mapping here are the tables and hbm.xml files.
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <joined-subclass name=" AcademicReport"
    extends="RestrictedAccess"
    table="academic_report">
        <key column="ra_id"/>   
        <set name="livecourses">
            <key column="adademic_report_id"/>
            <one-to-many class=" LiveCourse"/>
        </set>
        <one-to-one name="student"
              class="StudentUser"
              constrained="true"/>
    </joined-subclass>
</hibernate-mapping>


mysql> describe academic_report;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| ra_id | int(11) | NO   | PRI |         |       |
+-------+---------+------+-----+---------+-------+
1 row in set (1.02 sec)

mysql> describe student_user;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| uid       | varchar(255) | NO   | PRI |         |       |
| course_id | int(11)      | YES  | MUL | NULL    |       |
+-----------+--------------+------+-----+---------+-------+
2 rows in set (0.13 sec)

could you tell me if this is correct or how I should correct it


Last edited by sb5100 on Thu Apr 19, 2007 7:22 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 8:05 am 
Newbie

Joined: Wed Apr 11, 2007 2:11 pm
Posts: 10
Hi guys could anybody look at this and help me my problem is that there is a one-to-one mapping inside a joined-subclass. The generated tables do not seem to indicate this mapping.

The issue here is that one-to-one mappings use shared primary keys so does joined-subclass I cant imagine how the generated code is going to work so I really need some help to understand this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 7:25 pm 
Newbie

Joined: Wed Apr 11, 2007 2:11 pm
Posts: 10
can somebody look at this topic please :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 8:48 pm 
Newbie

Joined: Thu Apr 19, 2007 8:28 pm
Posts: 3
Please do a one-one mapping as per the documentation in the page
http://www.hibernate.org/hib_docs/v3/re ... tions.html
When two pojos have to be related by one to one mapping, determine, if you nedd a uni directional or a bi directional one to one

one option for bi drectional one to one between two pojo's Aand B
one to one mapping in Pojo A
many to one mapping with "unique constraint" in Pojo B
read the above doc for more info.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 9:48 pm 
Newbie

Joined: Wed Apr 11, 2007 2:11 pm
Posts: 10
I saw the documentation, it just didn’t catch my eye since it didn’t mention
any joined-subclass tags, but since you pointed it I managed to figure it out
and thanks a lot for the help.


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.