Home » Eclipse Projects » EclipseLink » RollbackException on commit but transaction was successful.(NPE received upon getTransaction().commit however the Database has been successfully updated.)
RollbackException on commit but transaction was successful. [message #1853049] |
Wed, 15 June 2022 20:22  |
Julie Schenk Messages: 3 Registered: June 2022 |
Junior Member |
|
|
Please forgive me if I don't include all of the appropriate information. Happy to add any as necessary.
JPA Version 2.0
<persistence version="2.0"
<persistence-unit name="fpa" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/oracle-orm.xml</mapping-file>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
The application works fine when there is only one instance running. When there are two instances of the application running and connected to the Oracle DB, there is a RollbackException when an object is merged.
However, the merge of the object, by all accounts in the database, is completely successful (all tables are updated correctly); it is only the commit that seems to be a problem, in that a RollbackException is thrown.
The Exception is either a Null Pointer or sometimes an integrity constraint but in both situations the database is accurately updated. This is very unnerving.
The DB appears to be updated successfully just like it is when the entityManager.getTransaction().commit() is successful (no Exception).
It's like I'm getting a false negative response.
At the time of this situation, each application has a list being viewed, therefore a query has been done using the EntityManager.
Perhaps this keeps the commit from being successful?
I'm including the code that populates the list(s) here:
private <T> List<T> getListOfType(final Class<T> klass) {
EntityManager entityManager
= getDAO().getEntityManager(needToRefreshEM);
if (needToRefreshEM) {
entityManager.getEntityManagerFactory().getCache().evictAll();
entityManager.clear();
}
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<T> criteria = cb.createQuery(klass);
TypedQuery<T> query = entityManager.createQuery(criteria);
query.setHint("javax.persistence.cache.storeMode", "REFRESH");
List<T> result = query.getResultList();
return result;
}
The 'store' method is straightforward:
public void store(final Object o, final boolean update) {
logger.debug("Storing " + o);
EntityManager entityManager = getEntityManager();
entityManager.getTransaction().begin();
if (entityManager.contains(o) || update) {
entityManager.merge(o);
} else {
entityManager.persist(o);
}
try {
entityManager.getTransaction().commit();
} catch (RollbackException re) {
logger.debug("This is the message: " + re.getMessage());
logger.debug("Couldn't commit all or part of transaction.");
logger.debug(re.getCause());
}
}
The object being persisted has an equal method and a hashCode method.
This is the Exception:
javax.persistence.RollbackException: java.lang.NullPointerException
149484 [AWT-EventQueue-0] DEBUG com.wec.cnfd.fpa.storage.Storage - This is the message: java.lang.NullPointerException
149484 [AWT-EventQueue-0] DEBUG com.wec.cnfd.fpa.storage.Storage - Couldn't commit all or part of transaction.
149484 [AWT-EventQueue-0] DEBUG com.wec.cnfd.fpa.storage.Storage - java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
at com.wec.cnfd.fpa.storage.Storage.store(Storage.java:181)
at com.wec.cnfd.fpa.storage.Storage.store(Storage.java:151)
at com.wec.cnfd.fpa.StoredListSynchronizer.itemAdded(StoredListSynchronizer.java:122)
at com.wec.cnfd.fpa.StoredListSynchronizer.access$200(StoredListSynchronizer.java:25)
at com.wec.cnfd.fpa.StoredListSynchronizer$StoredListListenerForDBSyncing.listElementsAdded(StoredListSynchronizer.java:85)
149492 [AWT-EventQueue-0] DEBUG MY CODE - Focus set on: null
at org.jdesktop.observablecollections.ObservableCollections$ObservableListImpl.add(ObservableCollections.java:294)
149512 [AWT-EventQueue-0] DEBUG MY CODE - Focus set on: javax.swing.JButton[importNewButton,571,0,107x25,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@12a00e3e,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=Import New,defaultCapable=true]
at java.util.AbstractList.add(AbstractList.java:108)
at com.wec.cnfd.fpa.dataset.DataSetList.add(DataSetList.java:94)
at com.wec.cnfd.fpa.io.ImportDataSetController.doAdd(ImportDataSetController.java:111)
at com.wec.cnfd.fpa.io.ImportDataSetController.doAdd(ImportDataSetController.java:115)
at com.wec.cnfd.fpa.io.ImportDataSetView.nextClicked(ImportDataSetView.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2238)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2296)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4897)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4475)
at java.awt.Container.dispatchEventImpl(Container.java:2282)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:109)
at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
at java.awt.Dialog.show(Dialog.java:1084)
at java.awt.Component.show(Component.java:1671)
at java.awt.Component.setVisible(Component.java:1623)
at java.awt.Window.setVisible(Window.java:1014)
at java.awt.Dialog.setVisible(Dialog.java:1005)
at com.wec.cnfd.fpa.dataset.gui.DataSetListView.showImportDataSetView(DataSetListView.java:126)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2238)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2296)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4897)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4475)
at java.awt.Container.dispatchEventImpl(Container.java:2282)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.postMergeChanges(UnitOfWorkImpl.java:3672)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeChangesIntoParent(UnitOfWorkImpl.java:3292)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeChangesIntoParent(RepeatableWriteUnitOfWork.java:369)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:283)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1147)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:84)
... 105 more
Does anyone know why I'm getting the NullPointerException when it appears the transactions have been successful? Any information will be greatly appreciated.
|
|
|
Re: RollbackException on commit but transaction was successful. [message #1853689 is a reply to message #1853049] |
Wed, 13 July 2022 16:16   |
Julie Schenk Messages: 3 Registered: June 2022 |
Junior Member |
|
|
I want to provide additional information that may hopefully help in providing some clues to point me in the right direction or even uncover an answer...
1. The integrity constraint is no longer an issue b/c of the following code added to a class and VERSION column added to DB:
@Version
@Column(name="VERSION")
private long version;
2. In regard to the NullPointerException, the fields that are/were being stored are declared as @Transient.
In my investigations I found:
Use the @Transient annotation or <transient> XML to specify a field or property of an entity that is not persistent
(for example, a field or property that is used at run time, but that is not part of the entity's state).
In this case, the code was written this way prior to my working on the project and I was surprised to read that, since
the fields are meant to be persisted.
Of note, the fields are part of an Embedded class, where are themselves a class (E.g. Measure<Double,
MeasureType>) which is why I suspect the author originally designed it this way.
Also, the NullPointerException DOES NOT occur when the DB is SQLite, which again, I suspect is why the
original author did not notice anything wrong. This issue shows itself when we recently started working with an
Oracle 19c DB.
I have changed the @Transients to @Basic and am in the process of refactoring the Embedded/Embeddable classes
and writing Converters b/c the Embedded is a class. Most of that is coming along but I am concerned I'm going
down a rabbit hole (current issue is I'm trying to insert duplicate column names (two extra for each of the "old"
Transient types)) and wonder if there's any ideas someone can provide please.
Thank you.
|
|
| | |
Goto Forum:
Current Time: Thu Dec 07 00:30:27 GMT 2023
Powered by FUDForum. Page generated in 0.02055 seconds
|