Insert statements generated with the same attribute repeated multiple times [message #1523033] |
Mon, 22 December 2014 12:49  |
Eclipse User |
|
|
|
I have the following problem.
I have a mapped superclass:
@MappedSuperclass
public class MySuperClass {
@Version
private long version;
private String foo;
private String bar;
// getter/setter omitted
}
and two entities, the second of which uses a shared primary key:
@Entity
public class MainEntity extends MySuperClass {
@Id @GeneratedValue
private Long id;
@OneToOne(mappedBy="main")
private SecondaryEntity secondary;
// getter/setter omitted
}
@Entity
public class SecondaryEntity extends MySuperClass {
@Id
@OneToOne(optional=false)
private MainEntity main;
// getter/setter omitted
}
What I'm seing is that when I try to persist an instance of SecondaryEntity, EclipseLink generated a SQL statement that repeats the fields of the mapped superclass:
INSERT INTO SecondaryEntity ('field1', 'field2', 'version', 'foo', 'bar', 'field3', 'version', 'foo', 'bar') VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Of course, MySql complains: Column 'version' specified twice
(I think it doesn't mention 'foo' and 'bar' because it stops at 'version', but they are repeated, too).
Am I doing something wrong? Is there a problem in EclipseLink with the combination "shared primary key" and "mapped superclass"?
I would really appreciate any help, I'm quite in an urgent situation and I don't know how to fix this without heavily changing my entities (by removing the shared primary keys... I have quite a few).
Thanks in advance,
Mauro
|
|
|
|
Re: Insert statements generated with the same attribute repeated multiple times [message #1524384 is a reply to message #1524140] |
Tue, 23 December 2014 06:55  |
Eclipse User |
|
|
|
For the records, the first problem (column specified twice) was caused by the fact that in my case SecondaryEntity had an embeddable field which erroneously extended the same mapped superclass, hence EclipseLink was trying to put the mapped superclass attributes more than once in the SQL insert statement.
Unfortunately, no error or warning was produced by EclipseLink at any stage in the modelling phase, at startup time or when I generated tables from entities. I opened bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=456054 for this.
The second problem (static weaver ClassCastException when using @MapsId) remains even after fixing the embeddable definition and occurs with both EclipseLink 2.5.2 and 2.6.0-M3.
|
|
|
Powered by
FUDForum. Page generated in 0.07469 seconds