-->
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.  [ 3 posts ] 
Author Message
 Post subject: MySQL Delete Problems With Hibernate 3.3.0
PostPosted: Tue May 11, 2010 6:09 pm 
Newbie

Joined: Wed Apr 14, 2010 4:33 pm
Posts: 8
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


Top
 Profile  
 
 Post subject: Re: MySQL Delete Problems With Hibernate 3.3.0
PostPosted: Tue May 11, 2010 6:42 pm 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
You cannot have JoinColumn on both tables.
Leave the JoinColumn on the child table, which I think in this case is the Record and add a mappedBy property on the Owner table, which I think is the User table.
The reason you are having trouble is because the layout you have right now says that they both depend on each other -- not good


Top
 Profile  
 
 Post subject: Re: MySQL Delete Problems With Hibernate 3.3.0
PostPosted: Thu May 13, 2010 3:13 pm 
Newbie

Joined: Wed Apr 14, 2010 4:33 pm
Posts: 8
ivirani,
Thanks for the help. That solved my problem


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