delete twice triggers detached entity error, but change to composite primary key and the
exception is gone.
-----------------------------------------------------------------------------------------------------------
Key: EJB-313
URL:
http://opensource.atlassian.com/projects/hibernate/browse/EJB-313
Project: Hibernate Entity Manager
Issue Type: Bug
Affects Versions: 3.2.0.cr3
Environment: Windows XP Professional + Postgres 8.1 + Spring 2 + JPA + Hibernate
3.2.3
Reporter: Simon Ng
Attachments: DeleteTwice.zip
The attached file DeleteTwice.zip has the entire project; and the primary key is a
composite primary key. Run the unit test and there is no exception, just an INFO level
message of "handling transient entity in delete processing".
Next, delete RestaurantPK.java, and change Restaurant.java to use a simple primary key:
package blog.jpa.domain;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
@Entity
public class Restaurant {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Change the onSetUpInTransaction to use different SQL statement to reflect a different
table
protected void onSetUpInTransaction() throws Exception {
jdbcTemplate.execute("insert into restaurant (id, name) values (1, 'Burger
Barn')");
jdbcTemplate.execute("insert into restaurant (id, name) values (2, 'Veggie
Village')");
jdbcTemplate.execute("insert into restaurant (id, name) values (3, 'Dover
Diner')");
}
drop the table restaurant and run the unit test again. Now there is an exception
[junit] Testcase: testDeleteRestaurant(blog.jpa.dao.JpaRestaurantDaoTests): Caused an
ERROR
[junit] Removing a detached instance blog.jpa.domain.Restaurant#3; nested exception is
java.lang.IllegalArgumentExce
ption: Removing a detached instance blog.jpa.domain.Restaurant#3
[junit] org.springframework.dao.InvalidDataAccessApiUsageException: Removing a
detached instance blog.jpa.domain.Res
taurant#3; nested exception is java.lang.IllegalArgumentException: Removing a detached
instance blog.jpa.domain.Restaura
nt#3
[junit] Caused by: java.lang.IllegalArgumentException: Removing a detached instance
blog.jpa.domain.Restaurant#3
[junit] at
org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventLis
tener.java:45)
The java.lang.IllegalArgumentException is specified in the JPA spec.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira