Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA: Attr ... mapped to a primary key column in the DB. Update not allowed.

173391Dec 22 2007 — edited Mar 10 2010
Let me just say that I posted a bug report for this here:
https://glassfish.dev.java.net/issues/show_bug.cgi?id=3937

But I'm also posting the info here, so that people who search on this forum may get some help:

TopLink (both Essentials and 11g) has a problem with flushing entities
containing a self-reference relationship. When flushing, the following exception
occurs:

Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.1 (Build b14-fcs
(12/17/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The attribute [id] of class [test.jpa.entities.Person] is
mapped to a primary key column in the database. Updates are not allowed.

No manual updates have been made to ANY primary key.

What I'm doing is:

1. I instantiate a new entity.
2. I start a transaction
3. I persist the new entity.
4. I read an existing entity from the DB.
5. I let the existing entity point to the new entity via the self-reference
relationship.
6. I flush the persistence context.
7. I issue commit(), and the exception occurs. (I have provided the stack traces for various versions of TopLink below.)

This is a clear bug.

Here are some additional observations:

1. Reproduced on the following versions of TopLink:
1.1. Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))
1.2. Oracle TopLink Essentials - 2.1 (Build b14-fcs (12/17/2007))
1.3. Oracle TopLink - 11g Technology Preview 3 (11.1.1.0.0) (Build 071214)
2. Reproducible both on Java SE and Java EE. (I tested on Oracle Application Server)
3. Reproducible with and without class weaving
4. Reproducible regardless of whether the JPA annotations are on fields or on
methods
5. Reproducible regardless of whether "cascade={CascadeType.PERSIST}" is used or
not.
6. Reproducible regardless of the fetch type of the self-reference relationship
(EAGER or LAZY).

Also:

1. Without flushing, the bug doesn't occur. That is, if I commit without
flushing, it works.
2. Without setting the self-reference relationship, the bug doesn't occur.

This is an issue that appears when using BOTH self-reference relationship AND
flushing.

Best regards,
Bisser

The message was edited by bisser:
Added info that the exception occurs "when I issue commit()" on step 7.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2010
Added on Dec 22 2007
10 comments
14,658 views