Skip to content

Commit

Permalink
[2.6] Rollback the fix for bug 411013 (#459)
Browse files Browse the repository at this point in the history
* Revert "Bug 411013: Entities in persistene context get validated on commit ev… (#270) (#271)"

This reverts commit 95176b9.

* Revert "[2.6] Bug 411013: Entities in persistence context get validated on commit even when unchanged (#248) (#252)"

This reverts commit 4318a80.

* update copyrights

Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj authored Jun 3, 2019
1 parent f013f52 commit 418f1a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
Expand Down Expand Up @@ -78,6 +78,7 @@ public ObjectChangeSet calculateChangesForExistingObject(Object clone, UnitOfWor
public ObjectChangeSet calculateChanges(Object clone, Object backUp, boolean isNew, UnitOfWorkChangeSet changeSet, UnitOfWorkImpl unitOfWork, ClassDescriptor descriptor, boolean shouldRaiseEvent) {
// PERF: Avoid events if no listeners.
if (descriptor.getEventManager().hasAnyEventListeners() && shouldRaiseEvent) {
// The query is built for compatibility to old event mechanism.
WriteObjectQuery writeQuery = new WriteObjectQuery(clone.getClass());
writeQuery.setObject(clone);
writeQuery.setBackupClone(backUp);
Expand All @@ -94,18 +95,16 @@ public ObjectChangeSet calculateChanges(Object clone, Object backUp, boolean isN
}

ObjectChangeSet changes = createObjectChangeSet(clone, backUp, changeSet, isNew, unitOfWork, descriptor);
if (changes.hasChanges()) {
if (descriptor.hasMappingsPostCalculateChanges() && ! changes.isNew() && ! unitOfWork.getCommitManager().isActive() && !unitOfWork.isNestedUnitOfWork()) {
// if we are in the commit because of an event skip this postCalculateChanges step as we have already executed it.
int size = descriptor.getMappingsPostCalculateChanges().size();
for (int i=0; i < size; i++) {
DatabaseMapping mapping = descriptor.getMappingsPostCalculateChanges().get(i);
org.eclipse.persistence.sessions.changesets.ChangeRecord record = changes.getChangesForAttributeNamed(mapping.getAttributeName());
if (record != null) {
// Deferred attributes will already have been acted on, therefore we need
// to post calculate changes to ensure orphaned objects are removed.
mapping.postCalculateChanges(record, unitOfWork);
}
if(changes.hasChanges() && descriptor.hasMappingsPostCalculateChanges() && ! changes.isNew() && ! unitOfWork.getCommitManager().isActive() && !unitOfWork.isNestedUnitOfWork()) {
// if we are in the commit because of an event skip this postCalculateChanges step as we have already executed it.
int size = descriptor.getMappingsPostCalculateChanges().size();
for(int i=0; i < size; i++) {
DatabaseMapping mapping = descriptor.getMappingsPostCalculateChanges().get(i);
org.eclipse.persistence.sessions.changesets.ChangeRecord record = changes.getChangesForAttributeNamed(mapping.getAttributeName());
if(record != null) {
// Deferred attributes will already have been acted on, therefore we need
// to post calculate changes to ensure orphaned objects are removed.
mapping.postCalculateChanges(record, unitOfWork);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2019 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
Expand All @@ -15,17 +15,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.TypedQuery;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;

import org.eclipse.persistence.logging.SessionLog;
import org.eclipse.persistence.mappings.ForeignReferenceMapping;
import org.eclipse.persistence.testing.framework.junit.JUnitTestCase;
import org.eclipse.persistence.testing.models.jpa.beanvalidation.Address;
Expand Down Expand Up @@ -60,7 +55,7 @@ public static Test suite() {
suite.addTest(new BeanValidationJunitTest("testUpdateWithInvalidData"));
suite.addTest(new BeanValidationJunitTest("testRemoveWithInvalidData"));
suite.addTest(new BeanValidationJunitTest("testTraversableResolverPreventsLoadingOfLazyRelationships"));
suite.addTest(new BeanValidationJunitTest("testValidateChangedData"));
suite.addTest(new BeanValidationJunitTest("testTraversableResolverPreventsTraversingRelationshipdMultipleTimes"));
}
return suite;
}
Expand Down Expand Up @@ -325,34 +320,7 @@ public void testTraversableResolverPreventsTraversingRelationshipdMultipleTimes(
// If it ever finds an entity with such flag set, the entity has visited the validator twice. It should be flagged as error.
}

//Bug #411013
public void testValidateChangedData() {
try {
getDatabaseSession().executeNonSelectingSQL("insert into CMP3_BV_PROJECT values (895, \"some long name\")");
} catch (Throwable t) {
getDatabaseSession().getSessionLog().logThrowable(SessionLog.WARNING, t);
}
clearCache();
Map<String, Object> props = new HashMap<>();
props.put("eclipselink.weaving", "false");
EntityManagerFactory factory = getEntityManagerFactory(props);
EntityManager em = factory.createEntityManager();
try {
beginTransaction(em);
TypedQuery<Project> query = em.createQuery("select p from CMP3_BV_PROJECT p", Project.class);
for (Project p: query.getResultList()) {
System.out.println(p.getName());
}
commitTransaction(em);
} catch (RuntimeException ex) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw ex;
} finally {
closeEntityManager(em);
}
}


//--------------------Helper Methods ---------------//
private boolean isInstantiated(Object entityObject, String attributeName, org.eclipse.persistence.sessions.Project project) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2018 Sun Microsystems, Inc, IBM Corporation. All rights reserved.
* Copyright (c) 2009, 2019 Sun Microsystems, Inc, IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
Expand All @@ -15,6 +15,11 @@

package org.eclipse.persistence.internal.jpa.metadata.listeners;

import java.lang.annotation.ElementType;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Path;
Expand All @@ -24,20 +29,15 @@
import javax.validation.groups.Default;

import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.descriptors.DescriptorEventAdapter;
import org.eclipse.persistence.descriptors.DescriptorEvent;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.DescriptorEvent;
import org.eclipse.persistence.descriptors.DescriptorEventAdapter;
import org.eclipse.persistence.descriptors.FetchGroupManager;
import org.eclipse.persistence.internal.jpa.metadata.beanvalidation.BeanValidationHelper;
import org.eclipse.persistence.internal.sessions.UnitOfWorkImpl;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.mappings.ForeignReferenceMapping;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.lang.annotation.ElementType;

/**
* Responsible for performing automatic bean validation on call back events.
* @author Mitesh Meswani
Expand Down Expand Up @@ -79,7 +79,7 @@ public void prePersist (DescriptorEvent event) {
}

@Override
public void aboutToUpdate (DescriptorEvent event) {
public void preUpdate (DescriptorEvent event) {
Object source = event.getSource();
UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl )event.getSession();
// preUpdate is also generated for deleted objects that were modified in this UOW.
Expand Down Expand Up @@ -150,6 +150,7 @@ private static class AutomaticLifeCycleValidationTraversableResolver implements
/**
* @return false for any lazily loaded property of root object being validated
*/
@Override
public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
boolean reachable = true;
String attributeName = null;
Expand Down Expand Up @@ -180,6 +181,7 @@ public boolean isReachable(Object traversableObject, Path.Node traversableProper
* Called only if isReachable returns true
* @return false for any associatons of root object being validated true otherwise
*/
@Override
public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
boolean cascadable = true;
if (isRootObjectPath(pathToTraversableObject)) {
Expand Down

0 comments on commit 418f1a1

Please sign in to comment.