-->
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: Error on save data
PostPosted: Sun Apr 17, 2005 1:20 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
Can someone tell me which is the cause of the exception? It occurs when saving a new user data. The query seems to be for updating, but not for creating a user data.

Thanks very much in advance for your kindly helps.



Hibernate version: 2.1.7

Mapping documents:

<class name="com.xxx.domain.User" table="users">
<id name="id" type="int" unsaved-value="null" >
<generator class="native"/>
</id>
<property name="cityId" type="int" not-null="true"/>
<property name="username" type="string" not-null="true"/>
<property name="password" type="string" not-null="true"/>
<property name="name" type="string" not-null="true"/>
<property name="email" type="string" not-null="true"/>
<property name="timeOfCreation" type="calendar" not-null="true"/>
<property name="status" type="int"/>
<property name="IPAddress" type="string" not-null="true"/>
<!-- Mapping for the component class Address. -->
<component name="address" class="com.xxx.domain.Address">
<property name="street1" type="string"/>
<property name="street2" type="string" />
<property name="postalCode" type="string" not-null="true"/>
<property name="city" type="string" not-null="true"/>
<property name="province" type="string" not-null="true"/>
<property name="country" type="string" not-null="true"/>
</component>
</class>

Code between sessionFactory.openSession() and session.close():

saveOrUpdate(user)

Full stack trace of any exception that occurs:

2005-04-17 09:26:00,031 DEBUG com.xxx.data.hibernate.HibernateUserDao - com.xxx.domain.User@8d2280[
id=<null>
username=myUsername
password=myPassword
timeOfCreation=java.util.GregorianCalendar[time=1113755159968,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT-08:00",offset=-28800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2005,MONTH=3,WEEK_OF_YEAR=17,WEEK_OF_MONTH=4,DAY_OF_MONTH=17,DAY_OF_YEAR=107,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=25,SECOND=59,MILLISECOND=968,ZONE_OFFSET=-28800000,DST_OFFSET=0]
name=myName
address=Street1: 'my street 1', Street2: 'my street 2', PostalCode: '90210', City: 'BEVERLY HILLS', Province: 'CA', Country: 'US'
email=baddy@mail.com
IPAddress=127.0.0.1
status=1
cityId=852
]
Hibernate: update users set cityId=?, username=?, password=?, name=?, email=?, timeOfCreation=?, status=?, IPAddress=?, street1=?, street2=?, postalCode=?, city=?, province=?, country=? where id=?
2005-04-17 09:26:00,484 ERROR net.sf.hibernate.impl.SessionImpl - Could not synchronize database state with session
2005-04-17 09:26:00,484 ERROR org.springframework.web.servlet.DispatcherServlet - Could not complete request
org.springframework.orm.hibernate.HibernateSystemException: Batch update row count wrong: 0; nested exception is net.sf.hibernate.HibernateException: Batch update row count wrong: 0
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:127)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2441)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
Name and version of the database you are using:

The generated SQL (show_sql=true):

PostgreSQL 8.0

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 9:17 am 
Beginner
Beginner

Joined: Sat Jan 01, 2005 12:18 pm
Posts: 23
I had the same problem using Hibernate 3, saveOrUpdate() but in combination with assigned ids.

I solved the problem with adding

Code:
unsaved-value="undefined"


to the id!

Yours is on null!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 12:11 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
Thanks ElLord for your input.

I use Hibernate 2, the "undfined" is not an option of unsaved value of ID.

I think the problem is for some reason the Hibernate takes the new instance as a transient one. It should carry out an insert query, but not a update query.

According to the documention section 5.1.4, "An identifier property value that indicates that an instance is newly instantiated (unsaved), distinguishing it from transient instances that were saved or loaded in a previous session." The mapping shall be right for an Integer ID.

Can someone point out what is missing here, please.


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.