Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Entity insert statement incorrect with multiple mapped subclasses.

I am porting over an existing application from OpenJPA (2.3.0).  I’ve had this working for quite some time (over 2 years now, previous versions of OpenJPA, ‘natch).

I have the same class structure, and same annotations that I was using in OpenJPA.  However, I’m failing when trying my first tests.  The error I’m getting is on the first insert:


[EL Warning]: 2014-04-13 09:23:30.325--UnitOfWork(102806359)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: null value in column "updated_by" violates not-null constraint
  Detail: Failing row contains (2, CoRE, null, null, null, 2014-04-13 12:23:30.437749-04, 0).
Error Code: 0
Call: INSERT INTO ruleform.agency (id, description, name, notes, pinned, update_date, updated_by) VALUES (?, ?, ?, ?, ?, ?, ?)
bind => [7 parameters bound]
Query: WriteObjectQuery(Agency [name=CoRE, id=2])

What’s happening, apparently, is that the insert of the row is not presenting the instance variables in the same order as the generated insert statement.

The generated insert has the columns in the order:

id, description, name, notes, pinned, update_date, updated_by

However, the bind values are presented in the order:

id, updated_by, description, name, notes, update_date, pinned

Which is clearly the cause of the error I’m seeing - i.e. the column of “updated_by" is being bound to 0, which is the value of “pinned”.  As I have no entities with id 0, this violates the non null constraint (updated_by is a foreign key back to the ruleform.agency table).

The class, Agency (ruleform.agency table) is a subclass of two mapped super classes:

Ruleform
ExistentialRuleform
Agency

Both Ruleform and ExistentialRuleform are both annotated with @MappedSuperclass and have @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS).

The Ruleform superclass defines the columns:

notes, update_date and updated_by

The ExistentialRuleform class defines:

name, description, pinned

The Agency defines
id

Is there something I need to tell EclipsLink to figure out the correct insert order to correspond to the INSERT statement?

I’m using EclipseLink 2.5.1

I’ve looked for something in the archives that spoke to this problem, but as you can imagine the queries I can come up with do not yield much useful information.  Apologies if this has already been answered ;)

As this has been working perfectly fine in OpenJPA, I’m pretty sure I have the DDL and things correct.  I’m wondering if this problem rings a bell with anyone before I dedicate some time to produce a test case that isolates this - my code base is rather large with a lot of foreign keys, so I can’t just cut this particular example out and produce a test case.

Hopefully, I’m just doing something odd that is allowed by OpenJPA but needs more finessing with EclipseLink.

In any event, any help you can send my way would be greatly appreciated.

Thanks,

-Hal




Back to the top