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.  [ 1 post ] 
Author Message
 Post subject: SQL insert, update or delete failed
PostPosted: Mon Sep 27, 2004 3:00 am 
Newbie

Joined: Sun Sep 26, 2004 11:36 am
Posts: 7
Hibernate version:
2.1.6
Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<class name="com.playingwithmatches.xeg.webservices.User" table="users">


<id name="userid" column="userid" type="java.lang.Long" unsaved-value="null">
<generator class="hilo"/>
</id>

<property name="firstname" column="firstname" type="string" length="12" not-null="true"/>
<property name="lastname" column="lastname" type="string" length="15" not-null="true"/>

<property name="address" type="string" column="address" length="255" not-null="true"/>


<property name="username" type="string" column="username" length="16" not-null="true"

unique="true" update="false">
</property>


<property name="password" type="string" column="password" length="12" not-null="true"/>

<property name="email" type="string" column="email" length="255" not-null="true"/>


<array name="preferences" table="organisations" cascade="all" >
<key column="userid"/>
<index column="i"/>

<one-to-many

class="com.playingwithmatches.xeg.webservices.Preference"/>
</array>


<many-to-one name="organisation"

class="com.playingwithmatches.xeg.webservices.Organisation" column="organisationid"

cascade="all"/>


</class>
</hibernate-mapping>

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


public void removeUser(String username) throws NoSuchUserException, DAOException
{
Session session = null;

try
{
session = sessionFactory.openSession();

Transaction tx = session.beginTransaction();

List results = (List) session.find("from com.playingwithmatches.xeg.webservices.User as user where user.username= ?",
username, Hibernate.STRING);

System.out.println("there is " + results.size() + " to delete");

if(results.size() < 1)
{
System.out.println("throwing !!!!!");
throw new NoSuchUserException(username, "specified user does not exist");
}
else
{

session.delete(results.get(0));

tx.commit();
}
}
catch(HibernateException he)
{
logger.error("hibernate failed to remove user " + he.getMessage());

//rollback();
throw new DAOException(he);
}

finally
{
try
{
session.close();
}
catch(Exception ex)
{
}
}
}

Full stack trace of any exception that occurs:

Hibernate: select user0_.userid as userid, user0_.firstname as firstname, user0_
.lastname as lastname, user0_.address as address, user0_.username as username, u
ser0_.password as password, user0_.email as email, user0_.organisationid as orga
nisa8_ from users user0_ where (user0_.username=? )
there is 1 to delete
Hibernate: delete from users where userid=?
Hibernate: select preference0_.userid as userid__, preference0_.preferenceid as
preferen1___, preference0_.i as i__, preference0_.preferenceid as preferen1_0_,
preference0_.storagekey as storagekey0_, preference0_.preference as preference0_
, preference0_.userid as userid0_ from user_preferences preference0_ where prefe
rence0_.userid=?
there is 1 to delete
Hibernate: delete from users where userid=?
2004-09-27 08:49:49,705 ERROR net.sf.hibernate.impl.SessionImpl - Could not syn
chronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row no
t found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatche
r.java:25)
at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.jav
a:599)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.jav
a:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2376)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.j
ava:61)
at com.playingwithmatches.xeg.persistence.UserDAO.removeUser(UserDAO.jav
a:93)
at com.playingwithmatches.xeg.webservices.UserserviceSoapBindingImpl.rem
oveUser(UserserviceSoapBindingImpl.java:338)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)

Name and version of the database you are using:

MySQL 4.0



Hi Guys,

Ive read the FAQ on this and various documentation and added the "unsaved value" but I cant figure out what the problem is - this code works fine with many sequential requests so I assume the user gets deleted from a prior call then this error but shouldn the nosuchuser throw in that case ?. Ive disabled batch update to get a clearer stack trace. Im am using a test JSP to send multiple save / remove user requests to try and break it.

Any ideas apreciated


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.