-->
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.  [ 5 posts ] 
Author Message
 Post subject: HibernateException: Not supported for DML operations
PostPosted: Wed Apr 12, 2006 4:49 am 
Newbie

Joined: Wed Mar 15, 2006 10:36 am
Posts: 14
Hibernate version: 3.1

Hibernate Mapping file
<?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 entity-name="Bug" table="Bug" node="bug">
<id name="bugId" column="bugId" node="bugId"
type="java.lang.String">
<generator class="uuid" />
</id>
<version name="version" column="VERSION" node="version" />
<property name="bugInfo" column="bugInfo" node="bugInfo"
type="java.lang.String" length="80" not-null="true" />

<bag name="bugUsers" node="." cascade="all" inverse="true">
<key column="bugId" on-delete="cascade"/>
<one-to-many entity-name="User" embed-xml="false" node="userId" />
</bag>

<many-to-one name="productId" column="productId" cascade="all"
node="productId" embed-xml="false" entity-name="Product" />

</class>

<class entity-name="Product" table="Product" node="product">
<id name="productId" column="productId" node="productId"
type="java.lang.String">
<generator class="uuid" />
</id>
<version name="version" column="VERSION" node="version" />
<property name="productInfo" column="PRODUCT_INFO"
node="productInfo" type="java.lang.String" length="80"
not-null="true" />

<bag name="bugsProducts" cascade="all" inverse="true"
node="." >
<key column="productId" on-delete="cascade"/>
<one-to-many entity-name="Bug" embed-xml="false" node="bugId" />
</bag>

<bag name="productsUsers" table="ProductsUsers" node="." cascade="all" inverse="true">
<key column="productId" />
<many-to-many entity-name="User" embed-xml="false"
column="userId" node="userId" />
</bag>
</class>

<class entity-name="User" table="USERS" node="user">

<id name="userId" column="userId" node="userId"
type="java.lang.String">
<generator class="uuid" />
</id>

<version name="version" column="VERSION" node="version" />

<property name="email" column="EMAIL" node="email"
type="java.lang.String" length="40" />

<many-to-one name="manager" node="manager" column="managerId"
entity-name="User" embed-xml="false" update="true" cascade="all"/>

<many-to-one name="bugId" column="bugId" node="bugId" update="true"
embed-xml="false" entity-name="Bug" cascade="all"/>

<bag name="productsUsers" node="." table="ProductsUsers"
cascade="all">
<key column="userId"/>
<many-to-many entity-name="Product" embed-xml="false"
column="productId" node="productId"/>
</bag>

<one-to-one name="userDetails" node="userDetails"
entity-name="UserDetail" embed-xml="false" cascade="all"/>
</class>

<class entity-name="UserDetail" table="USER_DETAILS"
node="userDetail">
<id name="userId" column="userId" node="userId"
type="java.lang.String">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<version name="version" column="VERSION" node="version" />

<one-to-one name="user" node="." entity-name="User" cascade="all"
constrained="true" />

<property name="name" column="NAME" node="name"
type="java.lang.String" />
<property name="address" column="ADDRESS" node="address"
type="java.lang.String" />
<property name="phone" column="PHONE" node="phone"
type="java.lang.String" />
</class>

</hibernate-mapping>


Full stack trace of any exception that occurs:
org.hibernate.HibernateException: Not supported for DML operations
at org.hibernate.hql.ast.QueryTranslatorImpl.errorIfDML(QueryTranslatorImpl.java:256)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:297)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:137)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1014)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.pramati.TestSearchQuery.deleteRecord(TestSearchQuery.java:330)
at com.pramati.TestSearchQuery.main(TestSearchQuery.java:347)
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:585)
at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)




Name and version of the database you are using: Mysql 5.0


Hello all,

I am executing Query: "delete from User where userId='402881de0a8c44e9010a8c450a230001'". and because of foreign key constraints getting this error. In my hibernate mapping file I have defined cascade="all", so its working when I am updating the entry, but it fails when I tried deleting the same. Any help will be highly appreciated.


Regards

_________________
Gagan Jain


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 5:10 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
"delete User where userId='402881de0a8c44e9010a8c450a230001'"

you don't have to put "from" keyword


Top
 Profile  
 
 Post subject: it din't work out..
PostPosted: Wed Apr 12, 2006 5:17 am 
Newbie

Joined: Wed Mar 15, 2006 10:36 am
Posts: 14
Error Message :

org.hibernate.exception.ConstraintViolationException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:80)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:324)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:190)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1031)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at com.pramati.TestSearchQuery.deleteRecord(TestSearchQuery.java:328)
at com.pramati.TestSearchQuery.main(TestSearchQuery.java:348)
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:585)
at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: java.sql.SQLException: Cannot delete or update a parent row: a foreign key constraint fails (`bugtracker/productsusers`, CONSTRAINT `FKA2B63AE4CE539211` FOREIGN KEY (`userId`) REFERENCES `users` (`userId`))
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1120)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:675)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1162)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1079)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1064)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:71)
... 27 more

_________________
Gagan Jain


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 10:18 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
This looks like a constraint violation:

Quote:
Caused by: java.sql.SQLException: Cannot delete or update a parent row: a foreign key constraint fails (`bugtracker/productsusers`, CONSTRAINT `FKA2B63AE4CE539211` FOREIGN KEY (`userId`) REFERENCES `users` (`userId`))

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 2:45 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
If you do the delete with

Code:
String userId = "402881de0a8c44e9010a8c450a230001";
User user = session.get(User.class, userId);
session.delete(user);


Do you get the same error?


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