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!