wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate mapping. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate mapping." Watch "Hibernate mapping." New topic
Author

Hibernate mapping.

Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
Hi All,

I am new in hibernate, I need to complete a task in which I have to pick the data from 3 tables.
table one - fields
1-CUSIP
2-LIPPER_CAT(id)

table 2 - fields

1-LIPPER_CAT
2-UBS_CAT_CD(id)

table 3 - fields
1-UBS_CAT_CD
2-UBS_CAT_DS
3-UBS_SEQ
so I will use first table ID to make join with 2nd table and 2nd table id for making join to 3rd table.
Just for example - I am using following code if I have to pick data from only one table that is -LipperAstCat
code is as follows-

LipperAstCatDAO lipperAstCatDAO = ((LipperAstCatDAO)getDAO("LipperAstCatDAO"));
String hql = "from LipperAstCat ";

Session session = lipperAstCatDAO.getSessionFactory().openSession();
Query query = session.createQuery(hql);
ArrayList<LipperAstCat> ssFundAstCat = (ArrayList<LipperAstCat>)query.list();
session.close();

return ssFundAstCat;

LipperAstCat table has two files in this so I am using a bean class(with getter setters) and LipperAstCatDAO class from where I am getting session.
I have a persistence.xml file which is having
<property name="mappingResources">
<list>
<value>
com/hewitt/websolutions/emp/persistence/hibernate/LipperAstCat.hbm.xml
</value>
</list>
</property>

In the same xml file I have mapping like this

<bean id="LipperAstCatDAO"
class="com.hewitt.websolutions.emp.persistence.hibernate.dao.LipperAstCatDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

LipperAstCat.hbm.xml has LipperAstCat table mapping.
and I am getting data comfortably.

So In join sceniro how would I do all this to get data.
Can you please help me in this ? Thanks.
 
 
subject: Hibernate mapping.