-->
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.  [ 2 posts ] 
Author Message
 Post subject: Native SQL, feed only few attributes of a Bean.
PostPosted: Tue Sep 27, 2005 12:22 pm 
Newbie

Joined: Tue Sep 27, 2005 12:06 pm
Posts: 1
Location: test
Hibernate version:

3

Mapping documents:

<sql-query name="GestQuery">
<return alias="ge" class="Gest">
<return-property name="nomUsr" column="col1"/>
<return-property name="codPrf" column="col2"/>
<return-property name="nomGut" column="null"/>
<return-property name="melUsr" column="null"/>
</return>
SELECT mup.nom_usr AS col1,
um.mel_usr AS col2,
'' AS null
FROM m_usr_prf mup, OUTER usr_mel um
WHERE mup.nom_usr = um.nom_usr and mup.cod_prf='ges'
</sql-query>


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

try {
session = getHibernateTemplate().getSessionFactory().openSession();
Query q = session.getNamedQuery("GestQuery");
List lst = q.list();
session.close();
} catch (HibernateException e) {
log.error(e.getMessage(), e);
throw new TechnicalException(CLASS_NAME,"error.technical: initCache", e);
}


With all the attributes of my class Gest in a return-property, no problem... all works OK! but an Exception is raised if i forget to feed even 1 attributes of my class called "Gest"

In the thread http://forum.hibernate.org/viewtopic.ph ... e87130e813

Max said that all attributes ( -> select MyClass.*) must be feeded (in v2.1)
but since version 3 is it possible to feed only few attributes of a Bean ???

I've found a trick : create a virtual column named null with '', then
you add that :
<return-property name="melUsr" column="null"/>
for all your property that don't need to be fed, and ('' AS null) in your query.

What do you think about that trick ?????

Thank you!!!!!

Level
ERROR
Logger
org.hibernate.util.JDBCExceptionReporter
Time
2005-09-27 17:18:35,625
Thread
http-8080-Processor22
Message
No such column name
Full stack trace of any exception that occurs:

org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1560)
at org.hibernate.loader.Loader.list(Loader.java:1540)

Name and version of the database you are using:
Informix
The generated SQL (show_sql=true):
Hibernate: SELECT mup.nom_usr AS col1, um.mel_usr AS col2, '' AS null FROM m_usr_prf mup, OUTER usr_mel um WHERE mup.nom_usr = um.nom_usr and mup.cod_prf='ges'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 1:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
in H3 you still need to return all the columns to return *entities*.

If you only want *parts* of these objects returned you can use <return-scalar>

_________________
Max
Don't forget to rate


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