-->
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.  [ 12 posts ] 
Author Message
 Post subject: Xdoclet can't generate 2 many-to-one in composite-id
PostPosted: Fri Jul 15, 2005 1:01 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
I just realized that xdoclet can't generate two <key-many-to-one> in <composite-id> , and can't recognize the non-attribute 'column' .

Here is what i've tried:

1. The goal is to generate :
----
<composite-id
name="id"
class="edu.mnscu.housing.vo.RCCampusPK"
>

<key-many-to-one
name="campus"
class="edu.mnscu.housing.vo.Campus"
column="tech_id"
/>
<key-many-to-one
name="campus"
class="edu.mnscu.housing.vo.Campus"
column="rc_id"
/>
....
</composite-id>

------
//xdoclet
/**
*@hibernate.many-to-one class="edu.mnscu.housing.vo.Campus" column="tech_id" not-null="true"
*@hibernate.many-to-one class="edu.mnscu.housing.vo.Campus" column="rc_id" not-null="true"
*/
//file .hbn.xml generated --- missing another <key-many-to-one> for 'rc_id'.
<composite-id
name="id"
class="edu.mnscu.housing.vo.RCCampusPK"
>

<key-many-to-one
name="campus"
class="edu.mnscu.housing.vo.Campus"
column="tech_id"
/>

...
</composite-id>
2. The goal is to generate the following mapping:
---
<composite-id name="id"
class="edu.mnscu.housing.vo.RCCampusPK">
<key-many-to-one name="campus"
class="edu.mnscu.housing.vo.Campus"
<column name="tech_id"/>
<column name="rc_id"/>
</key-many-to-one>
...
</composite-id>
---
//xdoclet
/**
*@hibernate.many-to-one class="edu.mnscu.housing.vo.Campus"
*@hibernate.column="tech_id" not-null="true"
*@hibernate.column="rc_id" not-null="true"
*/
//file generated -- didn't recognize the 'column' , set the default name 'campus' to column.
<composite-id
name="id"
class="edu.mnscu.housing.vo.RCCampusPK"
>

<key-many-to-one
name="campus"
class="edu.mnscu.housing.vo.Campus"
column="campus"
/>
...
</composite-id>

It works for me if just one column in <composite-id> .<many-to-one>. not the case if a nested composite-id (ie. more than one columns ) in <composite-id>.<many-to-one>. Am i missing something?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 16, 2005 7:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I would not be using key-many-to-one . Use a normal composite key and then two Many-to-one with update's and insert's set to false on each Many-to-one property.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 10:12 am 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
You know, I've seen the Hibernate team suggest this a few times in the forums, but I've never seen an explanation why. Is there an easy explanation for this? Should key-many-to-one be considered deprecated? (Basically I'm just curious). Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 12:24 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
david wrote:
I would not be using key-many-to-one . Use a normal composite key and then two Many-to-one with update's and insert's set to false on each Many-to-one property.


<key-many-to-one> is generated by xdoclet. The problem occurred if the 'many-to-one' is in 'composite.id' and the 'one' is composite.id also. ie. <composite-id>.<many-to-one>.<composite-id>

Here is :
//one column in composite.id -- works fine.
public class Campus implements Serializable {

private CampusPK _id;
/**
* @hibernate.id generator-class="assigned"
*/
public CampusPK getId() {
return _id;
}
...
}

public class CampusPK implements Serializable {

private String _techId;
private Institution inst;

/**
* @hibernate.property column="tech_id" not-null="true"
*/
public String getTechId () {
return _techId;
}
public void setTechId (String techId ){
_techId= techId;
}
/**
* @hibernate.many-to-one column="rc_id" not-null="true"
*/
public Institution getInst(){
return inst;
}

//mapping generated:
<composite-id
name="id"
class="edu.mnscu.housing.vo.CampusPK"
>
<key-property
name="techId"
type="java.lang.String"
column="tech_id"
/>

<key-many-to-one
name="inst"
class="edu.mnscu.housing.vo.Institution"
column="rc_id"
/>

</composite-id>
...

//now Campus (composite.id) is part of RCCampus (composite.id) primary key - nested composite.id doesn't work , missing second column's mapping.

public class RCCampus implements Serializable {
...
private RCCampusPK _id;
...
/**
* @hibernate.id generator-class="assigned" not-null="true"
*/

public RCCampusPK getId(){
return _id;
}
public void setId( RCCampusPK id ){
_id = id ;
}
...
public class RCCampusPK implements Serializable {
...
private Campus campus;
...

/**
* @hibernate.many-to-one class="edu.mnscu.housing.vo.Campus" column="tech_id" not-null="true"
* hibernate.column="tech_id" not-null="true"
* @hibernate.many-to-one class="edu.mnscu.housing.vo.Campus" column="rc_id" not-null="true"
*/
public Campus getCampus(){
return campus;
}

//mapping generated:
<composite-id
name="id"
class="edu.mnscu.housing.vo.RCCampusPK"
>

<key-many-to-one
name="campus"
class="edu.mnscu.housing.vo.Campus"
column="tech_id"
/>

<key-property
name="FY"
type="java.lang.String"
column="fy"
/>

</composite-id>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 8:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
nathanmoon wrote:
You know, I've seen the Hibernate team suggest this a few times in the forums, but I've never seen an explanation why. Is there an easy explanation for this? Should key-many-to-one be considered deprecated? (Basically I'm just curious). Thanks.


Deprecated - well no. But you can map more variations when not using the key-many-to-one option. Use the approach that feels and works best for you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 8:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Chihbn - Dont plavce the many-ton-ones in the key class. Use them in the main class with update=false, insert=false since they are maintained through the key itself.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 8:47 am 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
david wrote:
Chihbn - Dont plavce the many-ton-ones in the key class. Use them in the main class with update=false, insert=false since they are maintained through the key itself.


David - Do you mean no need to have key class? what is the return type for composite-id suppose to be? It'll be nice if you can provide an example. thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 8:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Its a composite key so you must have the separate key. The fields of the key will no longer be key-many-to-one and now be simple properties.

The main class will have the many-to-one entries mapped with the update=false, insert=flase.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 9:30 am 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
david wrote:
Its a composite key so you must have the separate key. The fields of the key will no longer be key-many-to-one and now be simple properties.

The main class will have the many-to-one entries mapped with the update=false, insert=flase.


Where should i put columns mapping? In key class or main class ? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 11:43 am 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
chihbn wrote:
david wrote:
Its a composite key so you must have the separate key. The fields of the key will no longer be key-many-to-one and now be simple properties.

The main class will have the many-to-one entries mapped with the update=false, insert=flase.


Where should i put columns mapping? In key class or main class ? Thanks.

I've tried put the key columns mapping in key or main class only and in both key and main class. They don't works for me, similar to key-many-to-one, only one key column got mapped , missing the second column mapping. see the following for map files and errors.

----
//Case1. map 2 key columns( composite-id )in key class only

//main class :
/**
* @hibernate.many-to-one class="edu.mnscu.housing.common.vo.YearTerm" update="false" insert="false"
*/
public YearTerm getYearTerm(){
return yearTerm;
}
//key class:
/**
* @hibernate.property column="yrtr" not-null="true"
*/
public String getYrtr(){
return _yrtr;
}
public void setYrtr( String yrtr ){
_yrtr = yrtr;
}
/**
* @hibernate.property column="rc_id"
*/
public String getRcid(){
return _rcid;
}
//mapping file for main class:
...

<class
name="edu.mnscu.housing.common.vo.AssignmentPeriod"
table="yrtr_cal_dates"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id
name="id"
class="edu.mnscu.housing.common.vo.AssignmentPeriodPK"
>
<key-property
name="yrtr"
type="java.lang.String"
column="yrtr"
/>

<key-property
name="rcid"
type="java.lang.String"
column="rc_id"
/>

....

</composite-id>


<many-to-one
name="yearTerm"
class="edu.mnscu.housing.common.vo.YearTerm"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="yearTerm"
/>


//errors:
Foreign key (yrtr_cal_dates [yearTerm])) must have same number of columns as the referenced primary key (yrtr_cal [yrtr,rc_id])

------------------

//Case2: map 2 columns in both main class and key class, missing second column mapping.
//error: Foreign key (yrtr_cal_dates [yrtr])) must have same number of columns as the referenced p
rimary key (yrtr_cal [yrtr,rc_id])
/**
* @hibernate.many-to-one class="edu.mnscu.housing.common.vo.YearTerm" column="yrtr" update="false" insert="false"
* @hibernate.many-to-one class="edu.mnscu.housing.common.vo.YearTerm" column="rc_id" update="false" insert="false"
**/
public YearTerm getYearTerm(){
return yearTerm;


<hibernate-mapping>
<class
name="edu.mnscu.housing.common.vo.AssignmentPeriod"
table="yrtr_cal_dates"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id
name="id"
class="edu.mnscu.housing.common.vo.AssignmentPeriodPK"
>
<key-property
name="yrtr"
type="java.lang.String"
column="yrtr"
/>

<key-property
name="rcid"
type="java.lang.String"
column="rc_id"
/>

...

</composite-id>


<many-to-one
name="yearTerm"
class="edu.mnscu.housing.common.vo.YearTerm"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="yrtr"
/>
---------------
//Case3: map in main class only, no <key-property> got generated
//see same errors as case2. Foreign key (yrtr_cal_dates [yrtr])) must have
same number of columns as the referenced primary key (yrtr_cal [yrtr,rc_id])

<hibernate-mapping>
<class
name="edu.mnscu.housing.common.vo.AssignmentPeriod"
table="yrtr_cal_dates"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id
name="id"
class="edu.mnscu.housing.common.vo.AssignmentPeriodPK"
>

...
</composite-id>



<many-to-one
name="yearTerm"
class="edu.mnscu.housing.common.vo.YearTerm"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="yrtr"
/>

Since those tables are read only for our apps now, our workaround was to not map associations , map key columns in key class. And do separate query. That works for us.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 10:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Try something along the lines of:

Code:
/**
* @hibernate.many-to-one class="edu.mnscu.housing.common.vo.YearTerm" update="false" insert="false"
* @hibernate.column name="yrtr"
* @hibernate.column name="rc_id"
*/
public YearTerm getYearTerm(){
     return yearTerm;
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 12:36 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 9:10 am
Posts: 29
david wrote:
Try something along the lines of:

Code:
/**
* @hibernate.many-to-one class="edu.mnscu.housing.common.vo.YearTerm" update="false" insert="false"
* @hibernate.column name="yrtr"
* @hibernate.column name="rc_id"
*/
public YearTerm getYearTerm(){
     return yearTerm;
}

Thank you for the info I'll give a try later.


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