Hello all,
I am having problems with getting my delete function to work. I have an entity User which can have many records but each record can only be assigned to one user. I am trying to test the delete of the user. In my database the user is not assigned any records, however, I am getting a foreign key constraint error. I have followed the instructions at
http://www.oracle.com/technology/pub/articles/gupta-jpa.html but I still get an error while trying to delete my records. I have included snippets of code below. I appreciate the help.
User.java
Code:
@Entity
@Table(name="TBLUSER") //tblUsers
public class User implements Persistent
{
@OneToMany(cascade =CascadeType.ALL)
@JoinColumn(name="UserID")
public Set<Record> getUserRecords()
{
return Collections.unmodifiableSet(records);
}
}
Record.java
Code:
@Entity
@Table(name="TBLRECORDS")
public class Record implements Persistent
{
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="UserID")
public User getRecordCreator()
{
return recordCreator;
}
}
When I try to delete the user I get
Code:
Hibernate: delete from TBLPROGRAM
WARN - JDBCExceptionReporter - SQL Error: 1451, SQLState: 23000
WARN - JDBCExceptionReporter - SQL Error: 1451, SQLState: 23000