-->
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.  [ 10 posts ] 
Author Message
 Post subject: net.sf.hibernate.PropertyAccessException: Null value was ass
PostPosted: Thu Sep 15, 2005 5:20 pm 
Newbie

Joined: Tue Sep 06, 2005 5:04 pm
Posts: 15
I have an integer mapping of an attribute in Device.java (where this property is int snmpPort). I get the following error - for some reason the IntegerType is getting a null. Could some one please help
Hibernate version:2.1.4

Mapping documents:
<property name="snmpPort" type="integer">
<column name="snmp_port" sql-type="integer" not-null="false"/>
</property>


Code between sessionFactory.openSession() and session.close():
N/A


Full stack trace of any exception that occurs:
net.sf.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.powerup.configmgr.server.persist.device.Device.snmpPort
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:221)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2206)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:240)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at net.sf.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:541)


Name and version of the database you are using:
Postgres, 8.0


The generated SQL (show_sql=true):
N/A


Debug level Hibernate log excerpt:N/A


Top
 Profile  
 
 Post subject: Re: net.sf.hibernate.PropertyAccessException: Null value
PostPosted: Thu Sep 15, 2005 5:28 pm 
Newbie

Joined: Tue Sep 06, 2005 5:04 pm
Posts: 15
veejnas wrote:
I have an integer mapping of an attribute in Device.java (where this property is int snmpPort). I get the following error - for some reason the IntegerType is getting a null. Could some one please help
Hibernate version:2.1.4

Mapping documents:
<property name="snmpPort" type="integer">
<column name="snmp_port" sql-type="integer" not-null="false"/>
</property>


Code between sessionFactory.openSession() and session.close():
N/A


Full stack trace of any exception that occurs:
net.sf.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.powerup.configmgr.server.persist.device.Device.snmpPort
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:221)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2206)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:240)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at net.sf.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:541)


Name and version of the database you are using:
Postgres, 8.0


The generated SQL (show_sql=true):
N/A


Debug level Hibernate log excerpt:N/A


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:07 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
It is a "classic" error that a null value cannot be assigned to a primitive type. In your case, snmp_port column is null but the snmpPort might be int or long.
Changing the snmpPort type to Long should solve your problem.
Check the database to see if the column is null. Post back if this does not solve your problem.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject: Why should it be a Wrapper Object
PostPosted: Thu Sep 15, 2005 6:12 pm 
Newbie

Joined: Tue Sep 06, 2005 5:04 pm
Posts: 15
Jason Zhicheng Li wrote:
It is a "classic" error that a null value cannot be assigned to a primitive type. In your case, snmp_port column is null but the snmpPort might be int or long.
Changing the snmpPort type to Long should solve your problem.
Check the database to see if the column is null. Post back if this does not solve your problem.


I have various other columns with int and short datatype in the POJO and integer and short corresponding to those in the mapping. They are working absoutely fine. I just added a new attribute/field and it does not want to work. If the other one is working as primitive (int or short) why do I need to make the new attribute to a Wrapper object.?

Thanks
- Sanjeev


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:23 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
your new attribute/field has a null value in databast table.
Can you check the value in the database to ensure the value is not null?

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:27 pm 
Newbie

Joined: Tue Sep 06, 2005 5:04 pm
Posts: 15
Jason Zhicheng Li wrote:
your new attribute/field has a null value in databast table.
Can you check the value in the database to ensure the value is not null?


Jason:
It does have a null value in the db table. The others that I talked about are atleast initilized to 0. This is an existing table and we are adding a column which happens to be an integer.
Does this mandate that we give a init value for all such newly added columns even though in my db I say that Null is allowed and mapping I say not-null="false"?
Cant hibernate init the primitive?
Thanks again...
- Sanjeev


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:42 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
Are you expecting Hibernate convert your null value from db to 0 for you? No , I don't think so.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:48 pm 
Newbie

Joined: Tue Sep 06, 2005 5:04 pm
Posts: 15
Jason Zhicheng Li wrote:
Are you expecting Hibernate convert your null value from db to 0 for you? No , I don't think so.


All I want to see is, I introduce a new field/column in an existing db/pojo and it is a primitive. When I fetch that row of record I would like to see this attribute property set. But apparently the int translates to an IntegerType object in hibernate and is null and hence the problem.

So I have to have some migration scheme to initialize, "even though these fields are null value acceptable" fields to some thing non null.


In Java all primitives are initialized but in hibernate ORM - primitives are not initilized to default.

Do you agree?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 7:05 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
Yes.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 7:06 pm 
Newbie

Joined: Tue Sep 06, 2005 5:04 pm
Posts: 15
Jason Zhicheng Li wrote:
Yes.


Thanks for you input - I knew so but wanted someone else to confirm the same.


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