Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Shallow update and non-nullable fields
Shallow update and non-nullable fields [message #954096] Mon, 22 October 2012 19:44 Go to next message
Vitaly Gorbunov is currently offline Vitaly GorbunovFriend
Messages: 7
Registered: July 2012
Junior Member
We have the following tables:
TRANSACTION 1:n TRANSACTION_EVENT
and TRANSACTION has reference to last transaction event.

TRANSACTION_EVENT mapped to TRANSACTION as private-owned.

When deleting transaction the following sequence applied:
In toplink 9.0.3
DELETE FROM TRANSACTION_EVENT WHERE TRANSACTION_EVENT_ID = 1;
DELETE FROM TRANSACTION_EVENT WHERE TRANSACTION_EVENT_ID = 2;
--The event below is referenced from TRANSACTION like last transaction event, but there is no error
DELETE FROM TRANSACTION_EVENT WHERE TRANSACTION_EVENT_ID = 3;
DELETE FROM TRANSACTION WHERE TRANSACTION_ID = 1;


Now eclipselink makes shallow update for TRANSACTION before deleting last event. And it's fail because TRANSACTION has some non-nullable foreign keys.
DELETE FROM TRANSACTION_EVENT WHERE TRANSACTION_EVENT_ID = 1;
DELETE FROM TRANSACTION_EVENT WHERE TRANSACTION_EVENT_ID = 2;
--Shallow update: All foreign keys set to NULL. SQL error appears here since there is some non-nullable foreign keys
UPDATE TRANSACTION SET LAST_TRANSACTION_EVENT_ID = NULL, CURRENCY_ID = NULL WHERE TRANSACTION_ID = 1;
DELETE FROM TRANSACTION_EVENT WHERE TRANSACTION_EVENT_ID = 3;
DELETE FROM TRANSACTION WHERE TRANSACTION_ID = 1;


It seems that class OneToOneMapping has some code that should solve this problem, but it not works because flag nullable is not setted in DatabaseField (it's always true)
protected void writeFromObjectIntoRowInternal(Object object, AbstractRecord databaseRow, AbstractSession session, ShallowMode mode) {
        List<DatabaseField> foreignKeyFields = getForeignKeyFields();
        if (mode != null) {
            List<DatabaseField> nonNullableFields = null;
            for (DatabaseField field : foreignKeyFields) {
                if (field.isNullable()) {
                    if (mode == ShallowMode.Insert) {
                        // add a nullable field with a null value
                        databaseRow.add(field, null);
                    }
                } else {
                    if (nonNullableFields == null) {
                        nonNullableFields = new ArrayList<DatabaseField>();
                    }
                    nonNullableFields.add(field);
                }
            }


I have applied workaround to skip shallow update before delete and it works for this case.

So my questions are:
1) Is there some common practice how to set flag nullable in DatabaseField? Maybe it can be setted from deployment descriptor generated by workbench?
2) How did it even work without shallow update? To see maybe I can rely on my workaround.
Re: Shallow update and non-nullable fields [message #964671 is a reply to message #954096] Tue, 30 October 2012 18:00 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You should be able to set the nullability of the DatabaseField in the @JoinColumn annotation for the relationship.

You should consider removing the not null constraint, as your model has a cycle, so deletion and insertion will be very difficult otherwise.


James : Wiki : Book : Blog : Twitter
Re: Shallow update and non-nullable fields [message #964783 is a reply to message #964671] Tue, 30 October 2012 19:50 Go to previous messageGo to next message
Vitaly Gorbunov is currently offline Vitaly GorbunovFriend
Messages: 7
Registered: July 2012
Junior Member
Thanks for your answer.
We actually using xml descriptor, not annotations. The problem with removing not null constraints is that we have to make all FKs in one table nullable even if only one of it is taking part in cycle. And considering the scale of the database it would be pain to determine and remove all needed not null constraints.

As I understood "shallow update before delete" was developed for maintaining delete order by instance (not only by class), so we decided to switch it off by custom mapping (we use custom extension to maintain delete order by instance anyway).
Re: Shallow update and non-nullable fields [message #973629 is a reply to message #964783] Tue, 06 November 2012 13:46 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The JPA orm.xml contains XML elements for all annotations, @JoinColumn is <join-column>.

James : Wiki : Book : Blog : Twitter
Previous Topic:OSGI Load Time Weaver
Next Topic:Remove child entity from collection: Best practice?
Goto Forum:
  


Current Time: Thu Mar 28 22:47:31 GMT 2024

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

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

Back to the top