File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Three Table/Class Combination Display? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Three Table/Class Combination Display?" Watch "Three Table/Class Combination Display?" New topic

Three Table/Class Combination Display?

Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223

I have 3 tables in MSSQL Database.

1. Auditfinding
2. AuditfindingsDisplayName
3. AuditFindingsFieldList

Fine. I have Created Mapping Files And Java Bean files(Using getter and setter methods)

My Hibernate Query is Working Perfectly.

My Query is:

select distinct Id as AuditId,substring(substring(CustomIssueField, patindex('%data_27="%',CustomIssueField)+9 ,len(CustomIssueField)),1,patindex('%"%',substring(CustomIssueField, patindex('%data_27="%',CustomIssueField)+9 ,len(CustomIssueField)))-1) as [CustomIssueField], DisplayName from Auditfindingsfieldlist X,Auditfindingsdisplayname Y, Auditfinding where x.fieldid>25 and y.fieldid=x.fieldid

Code is:
SQLQuery query = session.createSQLQuery("select distinct Id, substring(substring(CustomIssueField, patindex('%data_27=\"%',CustomIssueField)+9 ,len(CustomIssueField)),1,patindex('%\"%',substring(CustomIssueField, patindex('%data_27=\"%',CustomIssueField)+9 ,len(CustomIssueField)))-1) as [CustomIssueField], DisplayName from Auditfindingsfieldlist X,Auditfindingsdisplayname Y, Auditfinding where x.fieldid>25 and y.fieldid=x.fieldid");

query.addScalar( "DisplayName", Hibernate.STRING);
usrlist = query.list();
I am Using Three tables from above

The result is display like


I want to display id, customissuefield, displayname

How can I fetch from List (List contains combines three tables/classes)


Thank You<br />Edward
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

So if there are relationships defined in your mapping between the three tables, you can either do SQL, HQL or Criteria Object, and query on one of the tables and traverse to the other objects in the Object graph.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 661

when you do an aggregation of data from tables, we typically get an array of objects, like Object[][];
Object[0][1] will be Integer
Object[0][2] will be String
Object[0][3] will be String

you can typecast them to corresponding objects(Integers, Strings) and use them.

If you are not laughing at yourself, then you just didn't get the joke.
I agree. Here's the link:
subject: Three Table/Class Combination Display?
It's not a secret anymore!