Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Insert statements generated with the same attribute repeated multiple times
Insert statements generated with the same attribute repeated multiple times [message #1523033] Mon, 22 December 2014 17:49 Go to next message
Mauro Molinari is currently offline Mauro MolinariFriend
Messages: 285
Registered: July 2009
Senior Member
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 #1524140 is a reply to message #1523033] Tue, 23 December 2014 08:50 Go to previous messageGo to next message
Mauro Molinari is currently offline Mauro MolinariFriend
Messages: 285
Registered: July 2009
Senior Member
I tried to make this change to my actual use case:

@Entity
public class SecondaryEntity extends MySuperClass  {
  @Id
  private Long id;

  @MapsId
  @OneToOne(optional=false)
  private MainEntity main;
  // getter/setter omitted
}


But then I get the following error from the static weaver:

Quote:

Internal Exception: java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor cannot be cast to org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ObjectAccessor
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:230)
... 8 more
Caused by: java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor cannot be cast to org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ObjectAccessor
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ObjectAccessor.processId(ObjectAccessor.java:491)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ObjectAccessor.processOwningMappingKeys(ObjectAccessor.java:725)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToOneAccessor.process(OneToOneAccessor.java:161)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.processDerivedId(ClassAccessor.java:1619)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processDerivedId(EntityAccessor.java:987)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processAccessorsWithDerivedIDs(MetadataProject.java:1524)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage3(MetadataProject.java:1821)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:580)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:585)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1869)
... 6 more


By debugging I see that the failure is when the static weaver is processing the "secondary" field of the MainEntity: it expects it to have an ObjectAccessor, but it finds it has an IdAccessor, which is weird, since I have the @MapsId annotation.
I couldn't reproduce this second problem with a small test case...

I'm using EclipseLink 2.5.2.
Re: Insert statements generated with the same attribute repeated multiple times [message #1524384 is a reply to message #1524140] Tue, 23 December 2014 11:55 Go to previous message
Mauro Molinari is currently offline Mauro MolinariFriend
Messages: 285
Registered: July 2009
Senior Member
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.
Previous Topic:Default value for @TransactionAttribute.
Next Topic:How to configure CacheIndex wirth native ORM project ?
Goto Forum:
  


Current Time: Sun Oct 06 10:56:17 GMT 2024

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

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

Back to the top