-->
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.  [ 6 posts ] 
Author Message
 Post subject: problem with derived property in criteria query
PostPosted: Wed Mar 16, 2005 11:05 am 
Newbie

Joined: Wed Mar 16, 2005 10:13 am
Posts: 3
Hibernate version: 3.0RC1

I have a persistent class 'A' what has a component 'comp'. One of the component's properties is derived (let's call it 'derived') by specifying SQL in 'formula' attribute in mapping document.

This construction works fine if I load object of type A and access its component's derived property. E.g.

Code:
A a = (A) session.load(A.class, key);
System.out.prinln(a.getComp().getDerived());


But the problems appear when I want to set restriction on this derived property in criteria query. E.g.

Code:
Criteria c = session.createCriteria(A.class);
c.add(
  Restrictions.eq("comp.derived", value)
);
c.list();


When executing criteria query, I get NullPointerException:

Code:
java.lang.NullPointerException
   at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:68)
   at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:33)
   at org.hibernate.persister.entity.BasicEntityPersister.toColumns(BasicEntityPersister.java:1104)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:402)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:368)
   at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:42)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:313)
   at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1228)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)
        ...


Is anybody run to the same problem? Or what I am missing here?

Thanks,
Rando


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 1:17 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
If your property is a purely derived property (i.e. not mapped by hibernate) then you can't query the database againt it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 3:59 pm 
Newbie

Joined: Wed Mar 16, 2005 10:13 am
Posts: 3
This is probably not a case. The property A.comp.derived has Hibernate mapping, but not directly to the database column, but via formula (SQL expression calling stored function):

Code:
<property name="derived"
    formula="( IS_VALID(fromDate, untilDate) )"/>


regards,
Rando


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 12:01 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Ok - so it is mapped as a formula. It should work. What happens when you query on the column using HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 1:00 pm 
Newbie

Joined: Wed Mar 16, 2005 10:13 am
Posts: 3
The same problem is also when quering via HQL like:

Code:
Query q = session.createQuery("from A a where a.comp.derived=?");
q.setParameter(0, value);
q.list();


It seems, that the problem is present when the derived column is inside a component.

In method org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns() for 'formula'-mapped columns a template value is searched from formulaTemplatesByPropertyPath map. But for component properties this map does not contain entries (e.g. for key 'comp.derived' in my case) and that's why NPE is thrown.

regards,
Rando


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 5:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
put it in jira

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