Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink-7251: is mapped to a primary key column in the database. Updates are not allowed.
EclipseLink-7251: is mapped to a primary key column in the database. Updates are not allowed. [message #990874] Fri, 14 December 2012 15:39 Go to next message
Igor B is currently offline Igor BFriend
Messages: 9
Registered: July 2012
Junior Member
Hi,

I have the following Entity:

public class A extends Base {

private EmbClass abcEmbClass;


@Embedded
@AttributeOverrides({ @AttributeOverride(name = "EmbClass", column = @Column(name = "ABCEMBCLASS")) })
public EmbClass getAbcEmbClass() {
return abcEmbClass;
}
}

@MappedSuperclass
public abstract class Base {

private EmbClass embClass;

@EmbeddedId
public EmbClass getEmbClass () {
if (embClass== null) {
embClass= new EmbClass();
}
return embClass;
}
}

So far so good.

Now the implementation does the following:

public A update(AVo aVo) {
A _a = aEm.find(A.class, aVo.getEmbClass());
_a.setAbcEmbClass(aVo.getAbcEmbClass)
aEm.merge(_a);
return _a;
}

The primary key EmbClass is not changed at all, only a foreign key, so why happens the following error:

Exception Description: The attribute [embClass] of class [EmbClass ] is mapped to a primary key column in the database. Updates are not allowed.
[java] at org.eclipse.persistence.exceptions.ValidationException.primaryKeyUpdateDisallowed(ValidationException.java:2458)
[java] at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectMapping.java:1214)


How can I fix this problem?

best regards,

Igor
Re: EclipseLink-7251: is mapped to a primary key column in the database. Updates are not allowed. [message #991502 is a reply to message #990874] Wed, 19 December 2012 14:51 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Try copying the EmbClass instance instead of reusing instances as embeddable objects are not meant to be shared. Each reference should have its own independent instance to be used to track changes.
Previous Topic:Weird problem of persist in another transaction
Next Topic:entity extensions in a secondary table
Goto Forum:
  


Current Time: Sat Dec 20 15:17:56 GMT 2014

Powered by FUDForum. Page generated in 0.01568 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software