Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink-48(Multiple writable mappings exist for the field)
EclipseLink-48 [message #911685] Wed, 12 September 2012 05:59 Go to next message
Igor B is currently offline Igor B
Messages: 9
Registered: July 2012
Junior Member
Hi,
I have the following:

@Embeddable
public final class Oid {
private byte[] oid;
}

public abstract class Base {

@EmbeddedId
private Oid oid;

}


@Entity
public class A extends Base {

private String txt1;
private String txt2;

@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
private B aB;

}

@Entity
public class B extends Base {

private String msg1;
private String msg2;

}

What do I need to fix for not getting the following error:

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [TSI01_A.OID]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[aB]
Descriptor: RelationalDescriptor(A --> [DatabaseTable(TSI01_A)])
Runtime Exceptions:

I use the OID as primary key for the Entity Class A as well as for B.

Any help is welcome.

best regards,

Igor



Re: EclipseLink-48 [message #911812 is a reply to message #911685] Wed, 12 September 2012 11:24 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

So, you want the B to share the same oid as the A? Or do you want to use a foreign key?
Either way, your use of @PrimaryKeyJoinColumn is wrong.

Either remove this (and a foreign key will be used).

Or use a mappedBy in the A relationship, and add OneToOne back in B that uses the @PrimaryKeyJoinColumn(name="OID"), or @JoinColumn(name="OID",insertable=false,updateable=false)

See,
http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Primary_Keys_through_OneToOne_and_ManyToOne_Relationships

http://en.wikibooks.org/wiki/Java_Persistence/OneToOne


James : Wiki : Book : Blog : Twitter
Re: EclipseLink-48 [message #911906 is a reply to message #911812] Wed, 12 September 2012 15:02 Go to previous messageGo to next message
Igor B is currently offline Igor B
Messages: 9
Registered: July 2012
Junior Member
Hi James,

thank you for your answer.

I did the first solution you told me with mappedBy in the A relationship, and add OneToOne back in B that uses the PrimaryKeyJoinColumn(name="oid_adresse").

So far it worked and I got the table generated.


CREATE TABLE A (
OID RAW(13) NOT NULL,
oid_adresse RAW(13) NULL,
PRIMARY KEY (OID));

CREATE TABLE B(
oid_adresse RAW(13) NOT NULL,
PRIMARY KEY (oid_adresse));

as well as


ALTER TABLE A ADD CONSTRAINT FK_A_oid_adresse FOREIGN KEY (oid_adresse) REFERENCES B (oid_adresse);

ALTER TABLE B ADD CONSTRAINT FK_B_oid_adresse FOREIGN KEY (oid_adresse) REFERENCES A (oid_adresse)

When I try to use persist(A), I get the following exception:

java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: B@1050aad.
[java] at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOfWork.java:303)
[java] at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:706)
[java] at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:431)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:798)

I did do on B the following annotation:

public class B extends Base {

...

@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name="oid_adresse",
referencedColumnName="oid_adresse")
})
public A getA() {
return a;
}
}

What's still missing?

best regards,

Igor
Re: EclipseLink-48 [message #916049 is a reply to message #911906] Tue, 18 September 2012 13:05 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Ensure you relationship to B in A is cascade persist.

James : Wiki : Book : Blog : Twitter
Previous Topic:"updatable = false" column getting updated
Next Topic:Problem filtering with NOT IN clause
Goto Forum:
  


Current Time: Tue Oct 21 00:32:20 GMT 2014

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

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