-->
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: Exception when using Criteria:Null value was assigned ...
PostPosted: Sun Oct 24, 2004 10:45 pm 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
2.16



<hibernate-mapping>
<class name="com.fangtoo.bean.Sellhouse" table="sell_house" dynamic-update="true" dynamic-insert="true">
<id name="sell_id" column="sell_id" type="string">
<generator class="com.fangtoo.util.HibernateGenerator"/>
</id>

</property>
<property name="room">
<column name="room" sql-type="smallint"/>
</property>
<property name="guestroom" type="int">
<column name="guestroom" sql-type="smallint"/>
</property>
<property name="washroom">
<column name="washroom" sql-type="smallint"/>
</property>
<property name="area">
<column name="area" sql-type="float"/>
</property>
<property name="netarea">
<column name="netarea" sql-type="float"/>
</property>
<property name="building">
<column name="building" sql-type="varchar(100)"/>
</property>




public static List searchSell(SearchSellBean bean){
Session s=null;;
Transaction t=null;
List sellList=null;
log.info("enter query ... ...");
try {
s = HibernateUtil.currentSession();
t=s.beginTransaction();
Criteria c=s.createCriteria(Sellhouse.class);
log.info("before add expression ");
if(null!=bean.getAreaDown()&&!"all".equals(bean.getAreaDown())){
c.add(Expression.gt("area",bean.getAreaDown()));
}

if(null!=bean.getAreaUp()){
c.add(Expression.le("area",bean.getAreaUp()));
}

if(null!=bean.getChu()&&!"all".equals(bean.getChu())){
c.add(Expression.eq("kitchen",bean.getChu()));
}
if(null!=bean.getOriginarea()&&!"all".equals(bean.getOriginarea())){
c.add(Expression.eq("orientation",bean.getOriginarea()));
}

if(null!=bean.getProvince()&&!"all".equals(bean.getProvince())){
c.add(Expression.eq("province",bean.getProvince()));
}

if(null!=bean.getShi()){
c.add(Expression.eq("guestroom",bean.getShi())));
}

sellList=c.list();
t.commit();
}


net.sf.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.fangtoo.bean.Sellhouse.guestroom
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:222)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2210)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:315)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3613)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at com.fangtoo.util.HouseUtil.searchSell(HouseUtil.java:330)
at com.fangtoo.util.HouseUtil.main(HouseUtil.java:351)
Caused by: java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
... 12 more
08:47:34,328 INFO HouseUtil:352 - Get result: null


MySQL3.23

No

INFO

I write a main method to test the "searchSell" method.The main method is following:
Code:

public static void main(String[] args) {
      SearchSellBean b=new SearchSellBean();
      
      b.setProvince("test province");
      List list=searchSell(b);
      log.info("Get result: "+list);
   }

While I run the method,Exception happen. My Sellhouse is a javaBean,code is:
Code:

public class Sellhouse implements Serializable{
   private String sell_id;
   private String province="";
   private String location="";
   private int room;             // smallint
   private int guestroom;        //smallint
   private int washroom;          //smallint

               public void setGuestroom(int guestroom){
                     this.guestroom=guestroom;
               }
               public int getGuestroom(){
                      return this.guestroom;
               }
                ...............................................
                    /*  getter and setter **/
               ....................................
}


The SearchSellBean is :
Code:
public class SearchSellBean implements Serializable {
   private String province;
                private String guestroom;

               .................................................
             public void setProvince(String province){
                 this.province=province;
               }
                ....................................................
              /********* getter and setter **********/
             ..........................................................


Couldn't I use Criteria if the property is primitive type?
Why this Exception happen? Help!

_________________
You are not alone...


Top
 Profile  
 
 Post subject: : (
PostPosted: Mon Oct 25, 2004 8:10 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
I don't assigned value to guestroom column.Why this exception happen?
Help!

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 7:24 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
We had this once, or something similar to it anyway.
It was because there was null value in the DB column that mapped to the int property.

_________________
Cheers,
Shorn.


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.