Reputation: 43
And I created entities from tableA
, tableB
, tableC
from my database.
tableA
has foreign key to tableB
and has unidirectional Many-to-One relationship. tableC
has two primary keys and one of these is foreign key to primary key in tableA
. tableC
also has unidirection Many-to-One relationship to tableA
.
Then I created session bean and data control from it, in design window, created read-only table from tableA
.
And I selected columns in tableA
and also in tableB
.
I ran the application and saw the following exception in log window.
Local Exception Stack: Exception [EclipseLink-46] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException Exception Description: There should be one non-read-only mapping defined for the primary key field [tableC.tableA_ID]. Descriptor: RelationalDescriptor(mypack.tableC --> [DatabaseTable(tableC)])
tableA_ID
is a primary key in tableA
.
How can I solve this error?
Upvotes: 1
Views: 9303
Reputation: 18780
Please post the code for your @Entity
classes.
My best guess, though, is that you have the tableA_ID column on tableC in two separate mappings, once as part of a @ManyToOne
and again as a field (perhaps as part of an @EmbeddedId
). JPA only lets you manage the underlying column through a single writeable mapping.
If you want both mappings, you have to pick which one you'll use to write, and designate the other as read-only with insertable=false, updatable=false
.
For example:
@Entity
pubilc class TableC {
// read-write mapping to manage via relationship
@ManyToOne(column="tableA_ID")
private TableA tableA;
// read-only convenience method to get ID directly w/o navigating relationship
@Column(name="tableA_ID", insertable=false, updatable=false)
private Long tableA_ID;
}
Upvotes: 4
Reputation: 2003
[pedant]I suppose that by "tableC has two primary keys" you mean "tableC has a primary key made of two columns".[/pedant]
"Then I created session bean and data control from it, in design window, created read-only table from tableA."
Does that mean that you marked the bean mapped for tableA as globally read-only? If so, depending on the mapping, you may encounter the same as here where EclipeLink concludes that it's not possible to create a new entity since it depends on a read-only entity.
Upvotes: 0