Matt Watson created CAY-2122:
--------------------------------
Summary: Vertical Inheritance: Cannot Insert Record For
Implementing Class with Attribute And Relationship
Key: CAY-2122
URL: https://issues.apache.org/jira/browse/CAY-2122
Project: Cayenne
Issue Type: Bug
Components: Core Library
Affects Versions: 4.0.M3
Reporter: Matt Watson
When using the following DbEntities:
IV_OTHER (id, name)
IV_BASE (id, type, name)
IV_IMPL (id, attr1, other_id) (vertically inherits IV_BASE)
all fields are non-null
We end up with ObjEntities:
IvOther
IvBase (abstract)
IvImpl extends IvBase
When running the following code:
{code:java}
IvOther other = context.newObject(IvOther.class);
other.setName("other");
IvImpl impl = context.newObject(IvImpl.class);
impl.setName("Impl 1");
impl.setAttr1("attr1");
impl.setOther(other);
context.commitChanges();
{code}
Committing this errors in the database, because its trying to insert into the
IV_IMPL table with a NULL value for OTHER_ID
{code}
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO
IV_OTHER (ID, NAME) VALUES (?, ?)
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind: 1->ID:200,
2->NAME:'other']
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - === updated 1 row.
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO IV_BASE
(ID, NAME, TYPE) VALUES (?, ?, ?)
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind: 1->ID:200,
2->NAME:'Impl 1', 3->TYPE:'I']
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - === updated 1 row.
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO IV_IMPL
(ATTR1, ID, OTHER_ID) VALUES (?, ?, ?)
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind:
1->ATTR1:'attr1', 2->ID:200, 3->OTHER_ID:NULL]
[main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - *** error.
java.sql.SQLException: Attempt to insert null into a non-nullable column:
column: OTHER_ID table: IV_IMPL in statement [INSERT INTO IV_IMPL (ATTR1, ID,
OTHER_ID) VALUES (?, ?, ?)]
{code}
If there was only an attribute in IV_IMPL, or only a relationship on IV_IMPL it
would work fine. But the DataDomainFlushAction is using separate
InsertBatchQuery to handle the attributes and another one to handle the
relationships.
I have not yet figured out how to solve, but will continue to look into it.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)