Hi,
I have encountered similar error using JDO long time back. I firmly believe
that if you use @ManyToOne or something it means a relationship amongst
them.

Though I don't remember exactly what I did ,Coupleof observations
1. In the rating class. Add annotation of rederenced by attribute in
annotation. Or a similar annotation needs to be done in Book class.

2. Person has a list of rating and rating again has a person. Are you
planning to query by rating entity independently? I think this design tells
JPA that a person indirectly owns a book.

Thanks
Hari

On Oct 5, 2010 2:54 AM, "Dave Hicks" <dh...@i-hicks.org> wrote:

 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<google-appengine-java%2bunsubscr...@googlegroups.com>
.
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.

-- 
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.

Reply via email to