Home Update without select in EclipseLink 2.7
Reply: 0

Update without select in EclipseLink 2.7

user5762
1#
user5762 Published in April 25, 2018, 6:13 pm

I need a solution to update entity without select using EclipeLink 2.7. Here I found the following solution:

EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
UnitOfWork unitOfWork = ((EntityManagerImpl) entityManager.getDelegate()).getUnitOfWork();
AbstractSession session = unitOfWork.getParent();
session.updateObject(entity);
entityManager.getTransaction().commit();

And this is what I get:

Caused by: java.lang.ClassCastException: org.eclipse.persistence.internal.sessions.IsolatedClientSession cannot be cast to org.eclipse.persistence.internal.sessions.UnitOfWorkImpl
    at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.preUpdate(BeanValidationListener.java:90) ~[org.eclipse.persistence.jpa.jar:na]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:726) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.java:696) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:233) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.updateObjectForWrite(DatabaseQueryMechanism.java:901) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.queries.UpdateObjectQuery.executeCommit(UpdateObjectQuery.java:69) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWrite(DatabaseQueryMechanism.java:259) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:60) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:911) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:3346) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1892) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1874) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1824) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.updateObject(AbstractSession.java:4324) ~[org.eclipse.persistence.core.jar:na]

I tried to add to entity

@ExistenceChecking(ExistenceType.CHECK_CACHE)
public class MyEntity {...}

and

@ExistenceChecking(ExistenceType.ASSUME_EXISTENCE)
public class MyEntity {...}

however it didn't help. How to do update without select in EclipseLink 2.7?

Edit
I also tried

EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
UpdateObjectQuery updateQuery= new UpdateObjectQuery();
updateQuery.setObject(entity);
Session session = ((JpaEntityManager)entityManager.getDelegate()).getUnitOfWork().getParent();
session.executeQuery(updateQuery);
entityManager.getTransaction().commit();
entityManager.close();

But got :

Caused by: java.lang.ClassCastException: org.eclipse.persistence.internal.sessions.IsolatedClientSession cannot be cast to org.eclipse.persistence.internal.sessions.UnitOfWorkImpl
    at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.preUpdate(BeanValidationListener.java:90) ~[org.eclipse.persistence.jpa.jar:na]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:726) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.java:696) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:233) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.updateObjectForWrite(DatabaseQueryMechanism.java:901) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.queries.UpdateObjectQuery.executeCommit(UpdateObjectQuery.java:69) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWrite(DatabaseQueryMechanism.java:259) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:60) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:911) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:3346) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1892) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1874) ~[org.eclipse.persistence.core.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1824) ~[org.eclipse.persistence.core.jar:na]
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.320126 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO