-->
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: hwo to get named query metadata
PostPosted: Tue Mar 27, 2007 12:55 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
Hibernate version
hibernate v3.2

]Mapping documents:
<hibernate-mapping>
<sql-query name="my.Query1">
select * FROM TEST where ID = :ID
</sql-query>
<sql-query name="allFields" >
<return-scalar column="tid" type="string" ></return-scalar>
<return-scalar column="tname" type="string"></return- scalar>
select id as tid, name as tname FROM TEST
</sql-query>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
org.hibernate.Session ses = sessionFactory.openSession();
Transaction tx = ses.beginTransaction();
Query q= ses.getNamedQuery("allFields");
List lst = q.list();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle9i

The generated SQL (show_sql=true):
/*Hibernate : named query allFields */ select id as tid, name as tname FROM TEST


Now my problem is the it only gives me returned records bt it doesnt give me coulumn name.

for ex in the above case, tid and tname is the coulum name bt in the output , it doesnt give me couldm name as in the result set.

so is there ne solution for the same?

waiting for the positive reply.... or mail me on shethap@yahoo.com

Regards


Top
 Profile  
 
 Post subject: requires more info
PostPosted: Tue Mar 27, 2007 2:52 am 
Beginner
Beginner

Joined: Thu Feb 01, 2007 3:08 am
Posts: 20
Can u make it clear? How do u expect the return values? Here the return liust contains object arrays
One object array for each row.What kind of data structure are u expecting ?


U can change the query to get objects of Test.


Regards
Gokul

PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: this is what i exactly want
PostPosted: Wed Mar 28, 2007 2:25 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
[b]my database table is like:[/b]
Id Name
1 a
2 b

q.list() : - will return me the list of object which will not have column name(table metadata).

so list wil only return me :-
1 a
2 b

but not :-(column name of the table)
Id Name

So what if i want to have column name(or table metadata) for the respective query?

I use :
Query q = session.getNamedQuery("queryName");

so waiting for ur reply soon...

Thanks & Regards,
Shethap.


Top
 Profile  
 
 Post subject: try this
PostPosted: Thu Mar 29, 2007 2:19 am 
Beginner
Beginner

Joined: Thu Feb 01, 2007 3:08 am
Posts: 20
Try the following HQL named query

<hibernate-mapping>
<query name="allFields">
<![CDATA[select new map(test.tid as id,test.Name as Name) from Test test]]>
</query>
</hibernate-mapping>



This will return a list of maps with keys id and Name.

Thanks and Regards
Gokul nair(gokul112@gmail.com)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 3:57 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
Again it givs me the exception as below:-


Hibernate: select new map(test.tid as id,test.Name as Name) from Test test
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2159)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2040)
at org.hibernate.loader.Loader.list(Loader.java:2035)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:167)
at com.iflex.fcr.dataSelect.DynamicQueryController.setResultset(DynamicQueryController.java:57)
at com.iflex.fcr.dataSelect.DynamicQueryController.fetchRecords(DynamicQueryController.java:24)
at com.iflex.fcr.dataSelect.TestDataselect.main(TestDataselect.java:35)
Caused by: java.sql.SQLException: ORA-00923: FROM keyword not found where expected

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1680)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2156)
... 9 more
java.lang.NullPointerException
at com.iflex.fcr.dataSelect.TestDataselect.main(TestDataselect.java:38)
Exception in thread "main"


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.