-->
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.  [ 4 posts ] 
Author Message
 Post subject: Error when updating column of type int with null
PostPosted: Mon Aug 13, 2007 1:34 pm 
Newbie

Joined: Mon Aug 13, 2007 1:05 pm
Posts: 2
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="importer.Contact" table="CMS_CONTACT">
<id name="con_id" column="con_id">
<generator class="native"/>
</id>
<property name="firstname" />
<property name="lastname"/>
<property name="street" />
<property name="city" />
<property name="owner_metauser_id" />
<property name="homepage" />
<property name="username" />
<property name="hsn" column="hsn" type="java.lang.Integer" />
</class>

</hibernate-mapping>


This works fine when hsn is set with a value but when I try to set hsn to null I get the following error:

[java] Exception in thread "main" java.lang.ClassCastException: java.lang.String
[java] at org.hibernate.type.IntegerType.set(IntegerType.java:41)
[java] at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
[java] at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:107)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1997)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1974)
[java] at org.hibernate.persister.entity.AbstractEntityPersister$3.bindValues(AbstractEntityPersister.java:2152)
[java] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:32)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
[java] at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
[java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
[java] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
[java] at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
[java] at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
[java] at $Proxy0.save(Unknown Source)
[java] at importer.DbInsert.StoreContact(Unknown Source)
[java] at importer.DbInsert.storeContactList(Unknown Source)
[java] at importer.DbInsert.main(Unknown Source)
[java] Java Result: 1


Any idea what I'm doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 3:30 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Are your getter and setter methods for hsn of Integer type?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 4:12 pm 
Newbie

Joined: Mon Aug 13, 2007 1:05 pm
Posts: 2
Yes, they are of Integers type:

public class Contact {

...
private Integer hsn;
...



public Integer getHsn() {
return hsn;
}
public void setHsn(Integer hsn){
this.hsn=hsn;
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 4:29 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
I don't think hsn is the problem. You're getting an exception because a string value is being cast to an integer type. So whatever property is causing the problem _isn't_ set to null when you save the object.

Can you post the rest of your Contact class.


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