-->
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: One to One Hibernate Annotation
PostPosted: Tue Jan 25, 2011 9:36 am 
Newbie

Joined: Tue Jan 25, 2011 9:17 am
Posts: 2
Hi

I am having two tables.
1) Person (personid varchar2(10), name varchar2(10), contact number(2))
2) Address (addressid number(2), description varchar2(10))


Java Pojo Objects

Person
{
String personId;
String name;
Address contactInfo (this is for contact column)

public getContactInfo() {}
}


Address
{
int addressId;
String description;
}

Note: Person(contact) and Address(addressid) are foreignkey relation
Note: Please notice those column names are different.

How to make ONE to ONE annotation for these tables and How to fetch Address object row when we get Person object like

person.getContactInfo().getAddressId();

Please suggest proper annotation and a java example.

Thanks
Rao


Top
 Profile  
 
 Post subject: Re: One to One Hibernate Annotation
PostPosted: Tue Jan 25, 2011 11:54 am 
Newbie

Joined: Tue Jan 25, 2011 9:17 am
Posts: 2
Solved.


Java Pojo Objects

Person
{
String personId;
String name;
Address contactInfo;

@Embedded
@AttributeOverrides( {
@AttributeOverride(name="addressId;", column = @Column(name="CONTACT") )
} )
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "CONTACT", columnDefinition="ADDRESSID")
public getContactInfo() {}

}


@Embededable
Address
{
int addressId;
String description;
}


Note: Column names and table names in CAPITOL letters


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.