I'm using JPA, and I'm having a really tough time getting around this
problem. It seems that when I try to refer to an object by way of a
@ManyToOne, somehow DataNucleus wants to assume some kind of ownership
and throws an exception.
I have three kinds of objects: Person, Book, Rating. Person and Book
objects are independent of one another and created independently. When
a person rates a Book, a new Rating object is created and added to a set
of Ratings owned by the Person. The Rating object has a reference to
the Book. Here are the classes (each extends a superclass that contains
the @Id element):
class Person extends BasicEntity {
private String email;
@OneToMany(mappedBy="person", cascade=CascadeType.All,
fetch=FetchType.LAZY)
private Set<Rating> ratings;
}
class Book extends BasicEntity {
private String name;
}
class Rating extends BasicEntity {
@ManyToOne(fetch=FetchType.LAZY)
private Person person;
@ManyToOne(fetch=FetchType.LAZY)
private Book book;
private Integer value;
}
I get the following exception when I attempt to add such a Rating to a
Person:
org.springframework.orm.jpa.JpaSystemException: Detected attempt to
establish Person(1)/Rating(3) as the parent of Book(2) but the entity
identified by Book(2) has already been persisted without a parent. A
parent cannot be established or changed once an object has been persisted.
What gives? Is it not permitted to refer to objects in this way? I've
been using this technique in JPA for years.
Thanks,
Dave
--
You received this message because you are subscribed to the Google Groups "Google
App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.