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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate mapping problem
PostPosted: Wed Feb 07, 2007 7:44 am 
Newbie

Joined: Mon Dec 04, 2006 1:50 am
Posts: 2
Hi All,

I have a basic question related to O/R mapping.

I have 3 tables, A, B and C.

Table A
A_ID int primary key
A_NAME varchar

Table B
B_ID int primary key
A_ID int foreign key to A.A_ID
B_NAME varchar

Table C
C_ID int primary key & foreign key to A.A_ID
C_NAME varchar

I want the beans A, B and C to be as follows:

Code:
class A
{
    private int id;
    private String name;

    private B b;
    private C c;
}

Code:
class B
{
    private int id;
    private String name;
}

Code:
class C
{
    private int id;
    private String name;
}

When I perform a select on A, I want to get the members b and c of A to be automatically populated based on the foreign key relations specified in the tables B and C.

I will always have 0 or 1 rows in B and C for every row in A. In other words, the relationship between A-B and A-C are one-to-one.

Can someone help me on achieving this?
Basically I want to know how to write the mapping file.

Thanks,
Jayarama Nettar.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 7:54 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi jayaramanettar,

use Hibernate in Action .

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 12:39 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Hi,

You can look at this tutorial.
http://www.hibernate.org/hib_docs/v3/re ... orial.html

Look at section 1.3. The example is for many-many but the concept is the same. Just change the many-monay to one-one.

Budyanto


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