-->
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: Combination of Classes and Display from List How?
PostPosted: Wed Jul 05, 2006 2:10 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 7:56 am
Posts: 20
Name and version of the database you are using:
MSSQL2000

The generated SQL (show_sql=true):


Hi,

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("Id",Hibernate.INTEGER);
query.addScalar("CustomIssueField",Hibernate.STRING);
query.addScalar( "DisplayName", Hibernate.STRING);
usrlist = query.list();
=================================================
I am Using Three tables from above

The result is display like

[Ljava.lang.Object;@24bef5
[Ljava.lang.Object;@74d22e
[Ljava.lang.Object;@192ee25
[Ljava.lang.Object;@150cf54
[Ljava.lang.Object;@5bc8c9

I want to display id, customissuefield, displayname
=============================
id customissuefield displayname
=============================
1 -1 Category
2 -1 ISM COde
===============================

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

Thanks
edward


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 9:10 am 
Beginner
Beginner

Joined: Mon Jul 26, 2004 4:29 pm
Posts: 45
Location: TX, USA
From the api docs for Query:

Quote:
public List list()
throws HibernateException

Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].


This means that each row returned is an array of Object. So your Id would be object[0], your CustonIssueField would be object[1], and your DisplayName would be object[2].

Hope this helps,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 1:05 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 7:56 am
Posts: 20
Thank You So Much.

Using the below code, I got all the fields from Different Table
=============================================
Iterator itr = usrlist.iterator();
for( int index=0; itr.hasNext(); index++){
Object[] a1 = (Object[]) itr.next();
System.out.println("\t" +a1[0] + "\t" + a1[1] + "\t" + a1[2]);
}

=============================================


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.