-->
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.  [ 5 posts ] 
Author Message
 Post subject: Help in joining tables
PostPosted: Tue Dec 20, 2005 6:27 pm 
Beginner
Beginner

Joined: Wed Dec 14, 2005 10:32 am
Posts: 20
Hi,

I have an sql similar to the one given below. I am trying to figure out how to acheive this in hibernate 3.

I am a beginner to hibernate and I could succesfully do the CRUD operations when the query is something like this: 'select * from table'.

SELECT
i.id,
i.sa,
i.curr,
i.num,
i._line_id,
acc.cd,

FROM

ITEM i,
ACCOUNT acc
WHERE
i.cd = 'ACT' AND
i.type_cd = 'LINE' AND
acc.type_cd = 'S'

How do I acheive the CRUD operations in hibernate 3 with something similar to the above query.

Any help will be greatly appreciated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 6:44 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
Assuming you have an Item class and an Account class, your hql query would look pretty similar to what you have already written, except that it would use case sensitive class names and property names instead of table/column names. And, you could get objects of type Item, Account as return values instead of individual column values.

SELECT i, acc
FROM
Item i,
Account acc
WHERE
i.cd = 'ACT' AND
i.type_cd = 'LINE' AND
acc.type_cd = 'S'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 6:47 pm 
Beginner
Beginner

Joined: Wed Dec 14, 2005 10:32 am
Posts: 20
Hi,

Can you help me in putting the class and .hbm file for the account with the basic columns and attributes in the class.

Appreciate it.

-Ram


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 7:11 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
It would be something along hte lines of....

public class Account {
int id;
String cd;
String typeCd;

//generate the getters and setters for hte above properties...
}


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="Account" table="ACCOUNT" >
<id name="id" type="integer"/>
<property name="cd" type="string" column="cd"/>
<property name="typeCd type="string" column="type_cd"/>
</class>
</hibernate-mapping>

PS. Dont' forget to Rate the posting.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 8:51 pm 
Beginner
Beginner

Joined: Wed Dec 14, 2005 10:32 am
Posts: 20
Hi Again,

should it not mention any relationship between the account and the item table in the .hbm file.

When I load the class with the primaykey of the item table I want to pick one of the columns in the account table based the foriegnkey relationship.

Thanks for you help.

-Ram


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