Gateway pattern using Java EE

I am using a gateway template in a Java EE project in which I have:

Bean session with extended matching context.

The bean has a transaction attribute that is not supported in order to abort any transaction that will be entered into the database.

The bean has a save method with the established requirement for the transaction attribute new, which will lead to a new transaction, which changes the object and reflects them in the database.

see Gateway: adam bein page-67

Until two days ago, I used GlassFish 3, and everything worked fine. I retrieve the object, make changes, and then call the save method without merging the object. Entity changes will be flushed to the database. But when I changed GlassFish to GlassFish 4, this operation stopped, and now I need to merge the object to clear the changed object to the database.

+4
source share
1 answer

Save specifically inserts. So calling save will again lead to another line in db.

Refresh updates the object in the session. Therefore, if an object is in a session, it will be updated. If the object is not in the session, you must invoke merging.

, , , update/merge .

JPA

, X, : X , X X ' X' X.

X , X ', X X.

X , IllegalArgumentException ( ).

X , , , X, cascade = MERGE cascade = ALL . Y, X, cascade = MERGE cascade = ALL, Y Y '. Y, X, X ' Y'. (, X , X , X '.)

X , X ', Y, cascade = MERGE cascade = ALL , X' Y ' , Y.

+1

Source: https://habr.com/ru/post/1531627/


All Articles