Hi All,
In our application I am working on a module wherein we allow user to delete the records from the database. They can select records to delete or just delete everything. The number of records could be more than 500000.
Here is part of the attachment.hbm.xml
Code:
<class name="Attachment" table="attachment">
<id name="Id" type="integer" column="att_id" >
<set name="assignmentassigns" inverse="true" lazy="true" cascade="all,delete-orphan">
<key column="att_id" foreign-key="FK_assignment_attachment"/>
<one-to-many class="assignment"/>
</set>
Here is the code in the dao.
Code:
Query query = getSession().createQuery("delete from attachment");
query.executeUpdate();
My question:
1. Is it the right way to delete huge number of records?
2. I get the following exception when I execute the above code.
ERROR org.hibernate.util.JDBCExceptionReporter - The DELETE statement conflicted with the REFERENCE constraint "FK_assignment_attachment". The conflict occurred in database "mydb", table "dbo.assignment", column 'att_id'.
Could anyone guide me in the right path?
Thanks!!