-->
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: Component question
PostPosted: Sun Mar 07, 2004 8:25 am 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
I have a class Person which has a relation to PhoneNumber. The latter has to be a component. Person has two methods for the relation:


Quote:
public PhoneNumber getBusinessPhoneNumber()
and
public PhoneNumber getPrivatePhoneNumber()


PhoneNumber contains String attribute phoneNumberNational and country attribute, which is a Business Object.

I cannot beat the mapping problem with this:
Quote:
/**
* @hibernate.component
* @return
*/
public PhoneNumber getBusinessPhoneNumber() {
return businessPhoneNumber;
}

/**
* @hibernate.component
* @return
*/
public PhoneNumber getPrivatePhoneNumber() {
return privatePhoneNumber;
}
Code:

It results in only adding only two columns to the PERSON table: country and phoneNumberNational. But it should add two more columns, since I have a businessPhoneNumber and a privatePhoneNumber.

Can someone please tell me whats wrong? Or can someone tell me a full code example which solves the thing which I want to do?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2004 10:38 am 
Regular
Regular

Joined: Wed Mar 03, 2004 9:38 am
Posts: 70
I posted a bug report to the xdoclet jira last spring about this. The answer I got from Gavin was IIRC, given the architecture of xdoclet, the problem is not fixable.

I ended up mapping the component separately and using a one-to-one association between them. It works, although there is almost certainly a performance loss, but at least in my case it's too small to notice.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2004 10:46 am 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
joib wrote:
I posted a bug report to the xdoclet jira last spring about this. The answer I got from Gavin was IIRC, given the architecture of xdoclet, the problem is not fixable.

I ended up mapping the component separately and using a one-to-one association between them. It works, although there is almost certainly a performance loss, but at least in my case it's too small to notice.


Can you please show me a code example of your solution?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2004 11:10 am 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
Forget about it. Now I know what you mean.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2004 11:37 am 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
I think I need your source code example. It does not work.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2004 11:56 am 
Regular
Regular

Joined: Wed Mar 03, 2004 9:38 am
Posts: 70
Sorry, I meant to say many-to-one association. one-to-one is somewhat useless, while many-to-one is what you want when you want something whose semantics are similar to normal java references. Anyway, in your example it would be:

/**
* @hibernate.many-to-one
* class="com.foo.PhoneNumber"
* column="businessphonenumber_id"
* cascade="all"
*/
public PhoneNumber getBusinessPhoneNumber() {
return businessPhoneNumber;
}

And a similar thing for the private number (remember to use another column name for that!).

You also have to map the PhoneNumber class to the database.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2004 12:29 pm 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
Now it works, thank you. Normally its a one-to-one relation and not a many-to-one relation. But as you said, one-to-one causes problems.

Maybe XDoclet 2 will have no problems with making component relations.


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.