-->
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: Error if map property is not included in the select query
PostPosted: Fri Nov 18, 2005 6:10 pm 
Newbie

Joined: Fri Nov 18, 2005 5:48 pm
Posts: 1
Hello,

My mapping file has this property "subClass" that is mapped to column ITEM.SUBCLASS. When I ran a select query from ITEM table and I did not select the mapped column SUBCLASS I got following error. In debugger I found Hibernate tried to get values for all properties defined in map file even though my query didn't include all properties. I have many use cases and sometimes I don't need to get all class properties. Is there a way to resolve this? Any help is appreciated!

Hibernate version: 3.0

Mapping documents:
<class name="Item" table="ITEM">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="objClass" column="CLASS"/>
<property name="subClass" column="SUBCLASS"/>
<property name="itemNumber" column="ITEM_NUMBER"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
s.setFlushMode(FlushMode.NEVER);
tx = s.beginTransaction();

String sql = "SELECT T0.ID {T0.id}, T0.CLASS {T0.objClass}, T0.ITEM_NUMBER {T0.itemNumber} FROM ITEM T0";
List items = s.createSQLQuery(sql).addEntity("T0", Item.class).setMaxResults(20).list();

tx.commit();

Full stack trace of any exception that occurs:
[java] Caused by: java.sql.SQLException: Invalid column name
[java] at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:1
34)
[java] at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:1
79)
[java] at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:2
69)
[java] at oracle.jdbc.driver.OracleStatement.get_column_index(OracleSta
tement.java:6221)
[java] at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResul
tSetImpl.java:1557)
[java] at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.
java:1482)
[java] at org.hibernate.type.StringType.get(StringType.java:16)
[java] at org.hibernate.type.NullableType.nullSafeGet(NullableType.java
:77)
[java] at org.hibernate.type.NullableType.nullSafeGet(NullableType.java
:68)
[java] at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)

[java] at org.hibernate.persister.entity.BasicEntityPersister.hydrate(B
asicEntityPersister.java:1690)
[java] at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991
)
[java] at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:
942)
[java] at org.hibernate.loader.Loader.getRow(Loader.java:855)
[java] at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:3
05)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:412)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollec
tions(Loader.java:218)
[java] at org.hibernate.loader.Loader.doList(Loader.java:1593)

Name and version of the database you are using:

The generated SQL (show_sql=true):
select * from ( SELECT T0.ID ID0_, T0.CLASS CLASS0_0_, T0
.ITEM_NUMBER ITEM4_0_0_ FROM ITEM T0 ) where rownum <= ?

Debug level Hibernate log excerpt:

-Tom
Code:
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 6:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
as stated in the documentation you need to return all properties for the class and the superclass since an entity can by definition not be incomplete.

You could experiment with having lazy properties, but I don't think that will help you completely.

Use scalar selects or HQL select new syntax to get partial value objects.

_________________
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.