-->
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.  [ 12 posts ] 
Author Message
 Post subject: Nullable field hitting PropertyAccessException
PostPosted: Mon Nov 07, 2005 2:55 am 
Newbie

Joined: Mon Nov 07, 2005 2:43 am
Posts: 5
Hi,
I'm facing a simple issue which I havent been able to resolve for long. I have defined a simple mapping from class to a existing table.


<hibernate-mapping package="com.nokia.ccpe.sam.model">

<class name="SoldtoVO"
table="SOLDTO"
>

<id name="soldtoId"
column="SOLDTOID">
<generator class="native" />
</id>
<property name="name"
column="NAME"
update="false"
insert="false"/>

<property name="cid"
column="CID"
update="false"
insert="false"/>

<property name="nodeId"
column="NODE_ID"
not-null="true"
update="false"
insert="false"/>

<property name="subAccountId"
column="SUBACCOUNTID"
not-null="true"
update="false"
insert="false"/>

<property name="dfPhoneActive"
column="DFPHONEACTIVE"
update="true"
insert="false"/>

<property name="cvActive"
column="CV_ACTIVE"
not-null="true"
update="true"
insert="false"/>


<property name="cvRowState"
column="CV_ROWSTATE"
update="true"
insert="false"/>

<property name="rowState"
column="ROWSTATE"
update="true"
insert="false"
type="integer"/>

<property name="cvRowStateTime"
column="CV_ROWSTATETIME"
update="true"
insert="false"/>

<property name="rowStateTime"
column="ROWSTATETIME"
update="true"
insert="false"
type="timestamp"/>


<property name="regionId"
column="PROJECT_ID"
update="false"
insert="false"/>



</class>


<query name="findsoldtobynodeid">
<![CDATA[
from SoldtoVO as soldto
where soldto.nodeId = ? ]]></query>

<query name="findsoldtobyprimarykey">
<![CDATA[
from SoldtoVO as soldto
where soldto.soldtoId = ? ]]></query>
<query name="findsoldundersubaccount">
<![CDATA[
from SoldtoVO as soldto
where soldto.subAccountId = ? ]]></query>



</hibernate-mapping>


When I try to run the findsoldtobyprimarykey query, I'm getting the following exception.
org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.nokia.ccpe.sam.model.SoldtoVO.setRowState; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.nokia.ccpe.sam.model.SoldtoVO.setRowState
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.nokia.ccpe.sam.model.SoldtoVO.setRowState
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:203)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.springframework.orm.hibernate3.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:876)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:867)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:863)
at com.nokia.ccpe.sam.dao.NodeTypeDaoImpl.getSoldtoVO(NodeTypeDaoImpl.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy2.getSoldtoVO(Unknown Source)
at com.nokia.ccpe.sam.dao.test.NodeTypeDaoTester.testGetSoldto(NodeTypeDaoTester.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: net.sf.cglib.beans.BulkBeanException
at com.nokia.ccpe.sam.model.SoldtoVO$$BulkBeanByCGLIB$$d862d87c.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
... 44 more
Caused by: java.lang.NullPointerException
... 46 more



I find that this exception only occurs when any field is nullable.
The rowstate variable is nullable in this case. Please see log below.

d2005-11-07 00:33:50,040 DEBUG [org.hibernate.SQL] - select soldtovo0_.SOLDTOID as SOLDTOID, soldtovo0_.NAME as NAME2_, soldtovo0_.CID as CID2_, soldtovo0_.NODE_ID as NODE4_2_, soldtovo0_.SUBACCOUNTID as SUBACCOU5_2_, soldtovo0_.DFPHONEACTIVE as DFPHONEA6_2_, soldtovo0_.CV_ACTIVE as CV7_2_, soldtovo0_.CV_ROWSTATE as CV8_2_, soldtovo0_.ROWSTATE as ROWSTATE2_, soldtovo0_.CV_ROWSTATETIME as CV10_2_, soldtovo0_.ROWSTATETIME as ROWSTAT11_2_, soldtovo0_.PROJECT_ID as PROJECT12_2_ from ccpeu1.SOLDTO soldtovo0_ where soldtovo0_.NODE_ID=?
dHibernate: select soldtovo0_.SOLDTOID as SOLDTOID, soldtovo0_.NAME as NAME2_, soldtovo0_.CID as CID2_, soldtovo0_.NODE_ID as NODE4_2_, soldtovo0_.SUBACCOUNTID as SUBACCOU5_2_, soldtovo0_.DFPHONEACTIVE as DFPHONEA6_2_, soldtovo0_.CV_ACTIVE as CV7_2_, soldtovo0_.CV_ROWSTATE as CV8_2_, soldtovo0_.ROWSTATE as ROWSTATE2_, soldtovo0_.CV_ROWSTATETIME as CV10_2_, soldtovo0_.ROWSTATETIME as ROWSTAT11_2_, soldtovo0_.PROJECT_ID as PROJECT12_2_ from ccpeu1.SOLDTO soldtovo0_ where soldtovo0_.NODE_ID=?
2005-11-07 00:33:50,040 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
d2005-11-07 00:34:32,824 DEBUG [org.hibernate.type.StringType] - binding '2759' to parameter: 1
d2005-11-07 00:35:15,859 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open ResultSet (open ResultSets: 0, globally: 0)
d2005-11-07 00:35:15,859 DEBUG [org.hibernate.loader.Loader] - processing result set
d2005-11-07 00:35:15,869 DEBUG [org.hibernate.loader.Loader] - result set row: 0
d2005-11-07 00:35:15,869 DEBUG [org.hibernate.type.StringType] - returning 'OCEAM' as column: SOLDTOID
d2005-11-07 00:35:15,869 DEBUG [org.hibernate.loader.Loader] - result row: EntityKey[com.nokia.ccpe.sam.model.SoldtoVO#OCEAM]
d2005-11-07 00:35:15,869 DEBUG [org.hibernate.loader.Loader] - Initializing object from ResultSet: [com.nokia.ccpe.sam.model.SoldtoVO#OCEAM]
d2005-11-07 00:35:15,899 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Hydrating entity: [com.nokia.ccpe.sam.model.SoldtoVO#OCEAM]
d2005-11-07 00:35:15,909 DEBUG [org.hibernate.type.StringType] - returning 'NOKIA FRANCE S.A.' as column: NAME2_
d2005-11-07 00:35:15,909 DEBUG [org.hibernate.type.StringType] - returning null as column: CID2_
d2005-11-07 00:35:15,909 DEBUG [org.hibernate.type.StringType] - returning '2759' as column: NODE4_2_
d2005-11-07 00:35:15,909 DEBUG [org.hibernate.type.StringType] - returning '1318' as column: SUBACCOU5_2_
d2005-11-07 00:35:15,909 DEBUG [org.hibernate.type.BooleanType] - returning 'false' as column: DFPHONEA6_2_
d2005-11-07 00:35:15,909 DEBUG [org.hibernate.type.BooleanType] - returning 'true' as column: CV7_2_
d2005-11-07 00:35:15,909 DEBUG [org.hibernate.type.IntegerType] - returning '0' as column: CV8_2_
d2005-11-07 00:35:15,909 DEBUG [org.hibernate.type.IntegerType] - returning null as column: ROWSTATE2_
d2005-11-07 00:35:15,929 DEBUG [org.hibernate.type.TimestampType] - returning '2005-11-04 14:56:49' as column: CV10_2_
d2005-11-07 00:35:15,939 DEBUG [org.hibernate.type.TimestampType] - returning null as column: ROWSTAT11_2_
d2005-11-07 00:35:15,939 DEBUG [org.hibernate.type.IntegerType] - returning '2' as column: PROJECT12_2_
d2005-11-07 00:35:15,939 DEBUG [org.hibernate.loader.Loader] - done processing result set (1 rows)
d2005-11-07 00:35:15,939 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close ResultSet (open ResultSets: 1, globally: 1)
d2005-11-07 00:35:15,939 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
d2005-11-07 00:35:15,939 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement
d2005-11-07 00:35:15,939 DEBUG [org.hibernate.loader.Loader] - total objects hydrated: 1
d2005-11-07 00:35:15,939 DEBUG [org.hibernate.engine.TwoPhaseLoad] - resolving associations for [com.nokia.ccpe.sam.model.SoldtoVO#OCEAM]
d2005-11-07 00:35:15,949 DEBUG [org.springframework.orm.hibernate3.HibernateTemplate] - Not closing pre-bound Hibernate Session after HibernateTemplate
d2005-11-07 00:35:15,949 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] - Applying rules to determine whether transaction should rollback on org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.nokia.ccpe.sam.model.SoldtoVO.setRowState; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.nokia.ccpe.sam.model.SoldtoVO.setRowState
d2005-11-07 00:35:15,949 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] - Winning rollback rule is: null
d2005-11-07 00:35:15,949 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] - No relevant rollback rule found: applying superclass default
d2005-11-07 00:35:15,949 DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] - Invoking rollback for transaction on com.nokia.ccpe.sam.dao.inf.NodeTypeDaoInf.getSoldtoVO due to throwable [org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.nokia.ccpe.sam.model.SoldtoVO.setRowState; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.nokia.ccpe.sam.model.SoldtoVO.setRowState]
d2005-11-07 00:35:15,949 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] - Triggering beforeCompletion synchronization
d2005-11-07 00:35:15,949 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] - Initiating transaction rollback
d2005-11-07 00:35:15,949 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] - Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@f62eba]
d2005-11-07 00:35:15,949 DEBUG [org.hibernate.transaction.JDBCTransaction] - rollback


Can someone please HELP!!!!?
Thanks
Dheepak


Top
 Profile  
 
 Post subject: More information needed
PostPosted: Mon Nov 07, 2005 2:58 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Please show your code and if possible more of the stack trace of the NullPointerException.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 3:54 am 
Newbie

Joined: Mon Nov 07, 2005 2:43 am
Posts: 5
log.debug("getSoldtoVO(nodeId) - Entry nodeId" + nodeId);

List nodeList = getHibernateTemplate().findByNamedQuery("findsoldtobynodeid",nodeId );
log.debug("Size of the list returned :" + nodeList.size());


This is all the code for invoking the query. What is puzzling is that the object hydration by itself is successful, but it is trying to fail when it tries to resolve associations and entities.
My Java class is as follows
/**
*
*/
package com.nokia.ccpe.sam.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* @author ramnatha
*
*/
public class SoldtoVO extends NodeType {

/**
*
*/
private static final long serialVersionUID = -776899199225452063L;
/**
*
*/

private String cid_;
private String soldtoId_;
private String nodeId_;
private boolean dfPhoneActive_;
private boolean cvActive_;
private String name_;
private String subAccountId_;
private int rowState_;
private Date rowStateTime_;
private int cvRowState_;
private Date cvRowStateTime_;
private int regionId_;
private List shiptoList_;

/* (non-Javadoc)
* @see com.nokia.ccpe.sam.model.NodeType#getSellerId()
*/
public String getSellerId() {

return getSoldtoId();
}

/* (non-Javadoc)
* @see com.nokia.ccpe.sam.model.ValueObject#getKey()
*/
public String getKey() {
return getSoldtoId();
}

public String getCid() {
return cid_;
}

public void setCid(String cid_) {
this.cid_ = cid_;
}

public boolean isCvActive() {
return cvActive_;
}

public void setCvActive(boolean cvActive_) {
this.cvActive_ = cvActive_;
}

public int getCvRowState() {
return cvRowState_;
}

public void setCvRowState(int cvRowState_) {
this.cvRowState_ = cvRowState_;
}

public Date getCvRowStateTime() {
return cvRowStateTime_;
}

public void setCvRowStateTime(Date cvRowStateTime_) {
this.cvRowStateTime_ = cvRowStateTime_;
}

public boolean isDfPhoneActive() {
return dfPhoneActive_;
}

public void setDfPhoneActive(boolean dfPhoneActive_) {
this.dfPhoneActive_ = dfPhoneActive_;
}

public String getName() {
return name_;
}

public void setName(String name_) {
this.name_ = name_;
}

public String getNodeId() {
return nodeId_;
}

public void setNodeId(String nodeId_) {
this.nodeId_ = nodeId_;
}

public int getRegionId() {
return regionId_;
}

public void setRegionId(int regionId_) {
this.regionId_ = regionId_;
}

public int getRowState() {
return rowState_;
}

public void setRowState(int rowState_) {
this.rowState_ = rowState_;
}

public Date getRowStateTime() {
return rowStateTime_;
}

public void setRowStateTime(Date rowStateTime_) {
this.rowStateTime_ = rowStateTime_;
}

public String getSoldtoId() {
return soldtoId_;
}

public void setSoldtoId(String soldToId_) {
this.soldtoId_ = soldToId_;
}

public String getSubAccountId() {
return subAccountId_;
}

public void setSubAccountId(String subAccountId_) {
this.subAccountId_ = subAccountId_;
}

public List getShiptoList() {
return shiptoList_;
}

public void setShiptoList(List shipToList) {
this.shiptoList_ = shipToList;
}


public void addShipto(ShiptoVO shipto) {
if(shiptoList_==null) {
shiptoList_ = new ArrayList();

}
shiptoList_.add(shipto);
}

public String toString() {
return new StringBuffer().append("Soldto \t NodeId: ").append(nodeId_).append("\n \t")
.append("SellerID : ").append(soldtoId_).append("type : SOLDTO\n").toString();
}

public boolean equals(Object obj) {
if (obj instanceof SoldtoVO) {
SoldtoVO newObj = (SoldtoVO) obj;
if(getNodeId().equals(newObj.getNodeId())) {
return true;
}

}
return false;
}
}


Top
 Profile  
 
 Post subject: Stack trace?
PostPosted: Mon Nov 07, 2005 4:05 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
I guess it would be really interesting, if you could come up with a more detailed stack trace of the NullPointerException.

By the way:
The output mentions a way of getting more information:
set hibernate.cglib.use_reflection_optimizer=false for more info


But I think the problem is something else:
I guess, you can't make a primitive nullable.
If you want to make rowState nullable, you probably have to use Integer!


hth,
Heinz
Don't forget to rate, if this helped.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 5:10 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
That is definitely the case. Fields marked nullable can not contain primitives.


Top
 Profile  
 
 Post subject: Yes. It worked.!!
PostPosted: Mon Nov 07, 2005 11:42 am 
Newbie

Joined: Mon Nov 07, 2005 2:43 am
Posts: 5
Hi,
Thanks guys!! I changed all my primitive attributes to wrapper classes and it worked! But I feel this doesnt look very obvious from the reference documentation. Is there a way I can set a default value to replace null? say new Integer(0) for null etc..?

Thanks a TON!
Dheepak


Top
 Profile  
 
 Post subject: Support the idea
PostPosted: Mon Nov 07, 2005 3:26 pm 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Quote:
Is there a way I can set a default value to replace null? say new Integer(0) for null etc..?


I definitely support this idea.
We have a home grown OR mapping (way off from what Hibernate is though) where I implemented this myself.

Regards,
Heinz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 4:25 pm 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
But null is null, it's not a representation for another value.

null <> 0


Maybe handy for legacy apps but a very bad thing to encourage for new builds.


Top
 Profile  
 
 Post subject: Null == null => primitive types
PostPosted: Mon Nov 07, 2005 5:28 pm 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
jamie_dainton wrote:
But null is null, it's not a representation for another value.

null <> 0

Maybe handy for legacy apps but a very bad thing to encourage for new builds.


Doesn't have to be a legacy app!
If you want to work with primitive data types, you may have a special value for a property that "means" null. E.g. 0 for an int-property.
We have this all over our apps.

Then you have to change your whole object model to wrapper types just to make Hibernate happy ?!?

Regards,
Heinz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 4:40 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Yeah, because when your language provides you with the power to have a null it's always worth replacing it with a magic number to represent null.

Not something really worth having a huge argument over but I disagree with your logic.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 4:50 am 
Newbie

Joined: Mon Oct 03, 2005 8:27 am
Posts: 13
Hi...
I'm not so convinced by the use of 0 as rapresentation of null values?
What if you have an optional foreign key of type integer and you put 0 to mean that the foreign key doesn't exists?
You get a db error of "Foreigh Key Constraint bla bla bla" because 0 is interpreted as the primary key (or parto of it) of the referenced table!

Just to say something!


Nico


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 5:34 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
http://forum.hibernate.org/viewtopic.php?t=949814


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