openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "roger.keays" <>
Subject Re: [VOTE] change primary key value?
Date Wed, 21 Feb 2007 07:51:21 GMT

Hi Craig,

Thanks for the reply.

Craig L Russell wrote:
>> Is there a way to change the primary key of an entity in OpenJPA? The
>> expection below doesn't fill me with hope...
> The JPA specification 2.1.4 says that the application must not change  
> the value of a primary key, but the specific behavior is not defined.  
> So OpenJPA is spec compliant.
That's what I was worried about. Actually, I was able to implement the
behaviour I needed by using a bulk UPDATE to change the key, and making sure
the foreign keys were set up correctly (i.e. CASCADE). I guess that being
able to do this is technically a bug in OpenJPA, but please don't fix it!

> That said, there are cases I've seen where changing a primary key is  
> useful. So I would not oppose a proposal to add the feature to OpenJPA.
> By the way, JDO doesn't prohibit it; there is a specific optional  
> feature to allow this. But an implementation has to choose to support  
> it.
Adding it to OpenJPA would be a nice start, although adding it to the JPA
spec would be better (along with the rest of the JDO 2.0 that is!)



>  <4|false|0.9.6-incubating>
> org.apache.openjpa.persistence.InvalidStateException: Attempt to  
> change a
> primary key field of an instance that already has a final object  
> id. Only
> new, unflushed instances whose id you have not retrieved can have  
> their
> primary keys changed. FailedObject:
> org.apache.openjpa.kernel.StateManagerImpl.assertNoPrimaryKeyChange 
> (
> org.apache.openjpa.kernel.StateManagerImpl.settingStringField 
> (
>     figbird.lists.entities.Email.pcSetemail(
>     figbird.lists.entities.Email.setEmail(
>    ...
> -- 
> View this message in context: 
> key-value--tf3244417.html#a9018988
> Sent from the open-jpa-dev mailing list archive at

Craig Russell
Architect, Sun Java Enterprise System
408 276-5638
P.S. A good JDO? O, Gasp!


View this message in context:
Sent from the open-jpa-dev mailing list archive at

View raw message