-->
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.  [ 4 posts ] 
Author Message
 Post subject: 1 PO class map to joined table, how?
PostPosted: Wed Mar 13, 2013 11:35 pm 
Newbie

Joined: Fri Dec 14, 2012 3:57 pm
Posts: 6
Mysql table

1 acct could many person(different login_id)

Create table accts (
Acct varchar(5) primary key,
Company _name varchar(50)
)

Create table accts_security
Login_id varchar(20),
Acct varchar(5)
Person_name varhcar(20)
Foreign key(acct) reference accts(acct)
);




Java class

Class person {
Login_id varchar(20),
Acct varchar(5),
Company varchar(50)
}

For the given login_id, I need to retrieve the combine info from both table accts and acct_security into PO class person, how can I do?


Top
 Profile  
 
 Post subject: Re: 1 PO class map to joined table, how?
PostPosted: Thu Mar 14, 2013 3:21 am 
Newbie

Joined: Wed Mar 13, 2013 11:32 am
Posts: 16
Hi

Do you want to create an object releation between accts and accts_security or do do you just want to join the tables and put the result into a list of Person objects?


Top
 Profile  
 
 Post subject: Re: 1 PO class map to joined table, how?
PostPosted: Thu Mar 14, 2013 10:31 am 
Newbie

Joined: Fri Dec 14, 2012 3:57 pm
Posts: 6
join the table first if possible

or

inside the person.hbm.xml , indicate join.

thanks in advance

john


Top
 Profile  
 
 Post subject: Re: 1 PO class map to joined table, how?
PostPosted: Thu Apr 04, 2013 3:22 am 
Newbie

Joined: Wed Mar 13, 2013 11:32 am
Posts: 16
Create an empty constructor and a contructor for all fields in Person(String loginId, String accts, String company)

Asuming that you have mapped accts and accts_security to Entity classes you can do something like this:


HQL:
Code:
select new Person(s.loginId, a.acct, a.companyName) from Accts a, AcctsSecurity s where s.acct = a.acct and s.loginId = :loginId


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