-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multiple @OneToOne newbie ?
PostPosted: Sat Mar 24, 2007 12:00 am 
Newbie

Joined: Fri Mar 23, 2007 11:42 pm
Posts: 2
Hi,

I'm having trouble getting something to work. Here is an example of what I'm trying to do. I have a Company class. It had an shipTo Address and a billTo Address, both of whch are Address objects. I've got both of these variables annoted like:

Code:
       
@OneToOne
@PrimaryKeyJoinColumn
private Address billingAddress;
@OneToOne
@PrimaryKeyJoinColumn
private Address shippingAddress;


When I attempt to create a Company with both addresses, the first Address object I created and saved is saved for both variables. However both Addresses appear in the Address table. Here is the code I'm using for this:

Code:
ContactInfo co = new Company();
ci.setEmailAddress("me@me.com");
ci.setFax(22);
ci.setPhone1(33);
ci.setPhone2(44);
ci.setUrl("www.crap.com");         
Address sa = new Address(
   "24 Madison Ave.", null, "Badland",
   "ME", 04105);         
Address ba = new Address(
   "25 Liberty Ave.", null, "Frank",
   "ME", 04444);
ci.setShippingAddress(sa);
ci.setBillingAddress(ba);
session.save(sa);
session.save(ba);
session.save(ci);



Any help is greatly appreciated. I just haven't been able to find the answer. I'm trying to learn Hibernate.

Thanks,
Mark


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 25, 2007 11:16 pm 
Newbie

Joined: Fri Mar 23, 2007 11:42 pm
Posts: 2
Ok, figured it out. Here is whata worked

Code:
@ManyToOne
@JoinColumn(name="BILL_ADDR")
private Address billingAddress;
@ManyToOne
@JoinColumn(name="SHIP_ADDR")
private Address shippingAddress;


Seems obvious now, but it took me a while to see it.

Thanks,
Mark


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