Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.2
Mapping documents:
<?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="events.Nodo" table="Nodo">
<id name="id" column="Nodo_ID">
<generator class="native" />
</id>
<property name="txt" />
<!-- Inserire chiave esterna dalla stessa classe -->
<many-to-one name="dad" class="events.Nodo"
cascade="save-update" fetch="join" lazy="false" update="true"
insert="true" column="dad" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
session.beginTransaction();
Nodo padre=(Nodo) session.load(Nodo.class, new Long(1));
session.delete(padre);
session.getTransaction().commit();
Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:146)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at events.EventManager.delete(EventManager.java:181)
at events.EventManager.main(EventManager.java:43)
Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Impossibile cancellare la riga: un vincolo d'integrita' referenziale non e' soddisfatto"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 9 more
Name and version of the database you are using:MySQL 5.0
I have problems when I want to delete a parent-node of the Tables Node.
the table Node was created like this:
_____________________________________
| ID_NODE | DESCRIPTION | DAD_ID_NODE |
-----------------------------------------------------
| 1 | dad | null |
| 2 | first child | 1 |
| 3 | second child | 1 |
-----------------------------------------------------
When I delete the dad I want to delete the first and the second child.
The relation that I submit in the Node.hbm.xml is:
<many-to-one name="dad" class="events.Nodo"cascade="save-update" fetch="join" lazy="false" update="true" insert="true" column="dad" />
The java class of the table Node Is:
public class Nodo {
private Long id;
private String txt;
private Nodo dad=null;
with all the setter and getter.
I hanven't problem when insert or modify the item in the table, and if I try to delete a node that haven't child the operation is execute correcty.
Thanks of all.