-->
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.  [ 4 posts ] 
Author Message
 Post subject: mapping entities w/ formulas to native sql queries
PostPosted: Wed Dec 13, 2006 6:21 pm 
Newbie

Joined: Wed Dec 13, 2006 5:35 pm
Posts: 4
Hi, I'm trying to use session.createSqlQuery() in order to use oracle's "connect by" syntax. I seem to run into a problem when retrieving an entity which contains a formula field (formula + exception included below). Temporarily removing the formula field or setting it to transient makes the problem go away. Also, retrieving the entity using a non-native query seems to work fine - it's just the combination of the formula field and either .createNativeQuery or createSqlQuery that does it.

Has anyone gotten this combination to work?
Hibernate version:
3.2.0 GA, annotation 3.2.0-GA, entitymanager 3.2.0-GA
Mapping documents: (done through annotations)

@Entity
@Table(name = "FOLDER")
@AttributeOverride(name="name", column=@Column(name="FOLDER_NAME"))
public class SimpleFolder implements Folder {
.....

@Formula("(select count(f2.folder_id) from folder f2 where f2.parent_folder_id = folder_id)")
private Boolean hasChildren = Boolean.FALSE;
}


Code between sessionFactory.openSession() and session.close():
session.createSQLQuery("select {f.*}"
+
" from folder f connect by " +
"prior parent_folder_id = folder_id " +
"start with folder_id = " + childId).addEntity(SimpleFolder.class).list();

Full stack trace of any exception that occurs:
java.lang.NullPointerException
at org.hibernate.loader.DefaultEntityAliases.intern(DefaultEntityAliases.java:133)
at org.hibernate.loader.DefaultEntityAliases.getSuffixedPropertyAliases(DefaultEntityAliases.java:106)
at org.hibernate.loader.DefaultEntityAliases.<init>(DefaultEntityAliases.java:52)
at org.hibernate.loader.ColumnEntityAliases.<init>(ColumnEntityAliases.java:16)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.generateCustomReturns(SQLQueryReturnProcessor.java:174)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:129)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
at......


Name and version of the database you are using:
Oracle 10G
The generated SQL (show_sql=true):
doesn't get to that point
Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 7:16 am 
Newbie

Joined: Thu Oct 19, 2006 10:39 pm
Posts: 9
Location: London
I am also getting the exact same bug however I am using hbm mapping files instead of annontations.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 7:17 am 
Newbie

Joined: Thu Oct 19, 2006 10:39 pm
Posts: 9
Location: London
I am also getting the exact same bug however I am using hbm mapping files instead of annontations. Did you manage to resolve this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 12:30 pm 
Newbie

Joined: Wed Dec 13, 2006 5:35 pm
Posts: 4
Hi,
I managed to get this to work w/ some slight changes to the syntax:

BAD (wasn't working)
Quote:
session.createSQLQuery("select {f.*}"
+
" from folder f connect by " +
"prior parent_folder_id = folder_id " +
"start with folder_id = " + childId).addEntity(SimpleFolder.class).list();


GOOD (worked)
Quote:
session.createSQLQuery("select {folder.*} " +
" from FOLDER {folder} connect by " +
"prior parent_folder_id = folder_id " +
"start with folder_id = :folderId" )
.addEntity("folder",SimpleFolder.class)
.setLong("folderId", folder.getLongValue()).list();


Hope that helps.


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