-->
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.  [ 3 posts ] 
Author Message
 Post subject: BUG in Criteria and HQL using restriction isNotNull?
PostPosted: Tue Sep 14, 2010 12:21 am 
Beginner
Beginner

Joined: Sat Oct 03, 2009 1:51 pm
Posts: 26
Hello, I have to get this Criteria to get houses that have avatar, avatar is Photo type:
Code:
public class House {
@OneToOne
private Photo avatar;
}

Code:
public class Photo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id_photo")
private Long idPhoto;
private String name;
private String url;
// other codes here
}

This is the Criteria:
Code:
Criteria crit = session.createCriteria(House.class);
      crit.add(Restrictions.isNotNull("avatar"));
      Criteria tipoCrit = crit.createCriteria("modality");
      tipoCrit.add(Restrictions.eq("typeModality", "Sale"));
      crit.addOrder(Order.desc("dateInclusion"));
      List results = crit.list();
      return results;

To get avatar photo of the house i test with this in JSP:
Code:
<c:when test="${house.avatar.idPhoto eq null}">

And this is stacktrace:
Code:
root cause

java.lang.NumberFormatException: For input string: "avatar"
   java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
   java.lang.Integer.parseInt(Integer.java:449)
   java.lang.Integer.parseInt(Integer.java:499)
   javax.el.ListELResolver.coerce(ListELResolver.java:167)
   javax.el.ListELResolver.getValue(ListELResolver.java:51)
   javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
   org.apache.el.parser.AstValue.getValue(AstValue.java:123)
   org.apache.el.parser.AstEqual.getValue(AstEqual.java:37)


The same error using HQL:
Code:
public List<Imovel> listaVenda() {   
       Query query = this.session.
       createQuery("from House h, Modality m where h.avatar.id is not null and m.typeModality = 'Sale' order by h.dateInclusion desc");
      return query.list();
}

Does anyone know if this is bug?
Thanks!


Top
 Profile  
 
 Post subject: Re: BUG in Criteria and HQL using restriction isNotNull?
PostPosted: Tue Sep 14, 2010 2:44 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
<c:when test="${house.avatar.idPhoto eq null}">

I am not aware of JSP. I suspect the database type and idPhoto type did not match.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: BUG in Criteria and HQL using restriction isNotNull?
PostPosted: Tue Sep 14, 2010 11:52 am 
Beginner
Beginner

Joined: Sat Oct 03, 2009 1:51 pm
Posts: 26
The problem is the object returned by Criteria, if I have not registered houses the exception is thrown, if I have houses works normally, I think this is bug:
Code:
public List<House> listHouseSale() {         
      Criteria crit = session.createCriteria(House.class);
      //crit.add(Restrictions.isNotNull("avatar")); //removing this line for test      
      Criteria typeCrit = crit.createCriteria("modality");
      typeCrit.add(Restrictions.eq("typeModality", "Sale"));
      crit.addOrder(Order.desc("dateInclusion"));
      List results = crit.list();
      return results;
   }

I testing now with this in JSP:
Code:
<c:when test="${empty house.avatar.idPhoto}">

The stacktrace is:
Code:
root cause

java.lang.NumberFormatException: For input string: "avatar"
   java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
   java.lang.Integer.parseInt(Integer.java:449)
   java.lang.Integer.parseInt(Integer.java:499)
   javax.el.ListELResolver.coerce(ListELResolver.java:167)
   javax.el.ListELResolver.getValue(ListELResolver.java:51)
   javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
   org.apache.el.parser.AstValue.getValue(AstValue.java:123)
   org.apache.el.parser.AstEmpty.getValue(AstEmpty.java:45)
   org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
   org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)


Avatar is a Photo type, not a String or Integer.
Someone can explain this? Thanks!


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