-->
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: xdoclet doesn't generate hibernate.column in one-to-one.
PostPosted: Wed Jan 25, 2006 12:42 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
Issues:
I just changed from @hibernate.many-to-one to @hibernate.one-to-one, and found that @hibernate.column and some attributes are missing such as update="false" insert="false" access="property". Do i need to do differently for one-to-one? what am i missing here?
Thanks.

Background:
Since table1/Class1 is a legacy table with 2 columns composit-id, we don't want table1/class1 'seeing' table2/class2 - no table2 association mapping in table1 - is not bidirectional mappings.

table2/class2 has own one column primary key as identity, and <one-to-one> mapping to table1/class1. if defining as @hibernate.many-to-one it works fine , but failed if changing to @hibernate.one-to-one

Hibernate version: 2.0

Mapping documents:
//many-to-one :works fine
/* @hibernate.many-to-one class="Class1"
* update="false" insert="false"
* @hibernate.column name="table1_id1" not-null="true"
* @hibernate.column name="table1_id2" not-null="true"
*/

<hibernate-mapping>
<class
name="Class2"
table="table2"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="table2_id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="assigned">
</generator>
</id>

<many-to-one
name="class1"
class="Class1"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
>
<column
name="table1_id1"
not-null="true"
/>
<column
name="table1_id2"
not-null="true"
/>
</many-to-one>
.....

----------
//one-to-one : missing subelements <column> and some attributes such as update="false",insert="false", access="property"

/* @hibernate.one-to-one class="Class1"
* update="false" insert="false"
* @hibernate.column name="table1_id1" not-null="true"
* @hibernate.column name="table1_id2" not-null="true"
*/
<hibernate-mapping>
<class
name="Class2"
table="table2"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="table2_id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="assigned">
</generator>
</id>

<one-to-one
name="class1"
class="Class2"
cascade="none"
outer-join="auto"
constrained="false"
/>
.....



Full stack trace of any exception that occurs:
net.sf.hibernate.MappingException: broken column mapping for: class1.id of: Class2


Name and version of the database you are using:
Oracle Rdb, version: V7.1-411

JDBC driver: Oracle Rdb Native Thin JDBC Driver, version: V7.1-300


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 8:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
This is detailed which is great but I did not see the version of XDoclet you are using? Have you tired the latest from CVS?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 8:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Thinking about it - this is correct since you have asked for a primary key level join. The Many-to-one is also a one-to-one equivalent mapping if your foreign keys are not also the primary keys. Why did you change it to one-to-one?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 11:33 am 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
david wrote:
This is detailed which is great but I did not see the version of XDoclet you are using? Have you tired the latest from CVS?

Xdoclet version is 1.2.1. is that a known issue? I haven't tried the latest yet.
Thanks for your reply.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 2:19 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
david wrote:
Thinking about it - this is correct since you have asked for a primary key level join. The Many-to-one is also a one-to-one equivalent mapping if your foreign keys are not also the primary keys. Why did you change it to one-to-one?

Thanks David for your info.

I’m trying to understand “The Many-to-one is also a one-to-one equivalent mapping if your foreign keys are not also the primary keys” . Do you mean “are also the primary keys” for the child table? That’s right if the foreign keys are the primary keys for child table also, but in our case, the child table has own one column primary key, the foreign keys are not the primary keys for child, they just a reference of parent.
Something like: Parent table primary key=P_ID1 + P_ID2.
Child table : primary key = ID
In child table :
ID, P_ID1, P_ID2 ……
1, 001, 100,…..
2, 001, 200…..
3, 002, 100…


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 9:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You should be using atleast 1.2.3 which was a start of many enhancements and fixed for hibernate mapping. The CVS version is even better (to be 1.3.x series).

one-to-one should only be used when the primary keys or the two tables in the relationship are used also as the fk- constraint (atleast as you have shown it). Otherwise use many-to-one. See the one-to-one discussion in the manual.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 3:08 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
david wrote:
You should be using atleast 1.2.3 which was a start of many enhancements and fixed for hibernate mapping. The CVS version is even better (to be 1.3.x series).

one-to-one should only be used when the primary keys or the two tables in the relationship are used also as the fk- constraint (atleast as you have shown it). Otherwise use many-to-one. See the one-to-one discussion in the manual.

I looked into Hibernate reference:
Alternatively, a foreign key with a unique constraint may be express as many-to-one with unique="true".
In our case, i can't put unique="true" per column since that's composite-id
So i added unique="true" in many-to-one. The same mapping file is generated , didn't see unique="true" there. It works the same as before.

Actually it doesn't matter the mapping is many-to-one or one-to-one for us now, the java class defination is alway the same, the traverse is alway from child to parent ,eg. group.person , not the other way. And the query result is the same. I'll leave it as many-to-one and add unique="true" on it to indicate it's one-to-one for the time being.
I'll give a try to upgrade xdoclet definitely. Thanks.


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.