-
Notifications
You must be signed in to change notification settings - Fork 183
[master] Bug 551815: When an entity with an aggregate with all fields set to null is changed to null for the aggregate field then Eclipselink executes a bogus no-op SQL update statement #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eperez
wants to merge
1
commit into
eclipse-ee4j:master
Choose a base branch
from
eperez:bugfix/simple-aggregate-null
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...elink.core.test/src/org/eclipse/persistence/testing/models/aggregate/SimpleAggregate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 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 v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.aggregate; | ||
|
||
public class SimpleAggregate { | ||
private String content; | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...ore.test/src/org/eclipse/persistence/testing/models/aggregate/SimpleAggregateProject.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 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 v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.aggregate; | ||
eperez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import org.eclipse.persistence.descriptors.ChangedFieldsLockingPolicy; | ||
import org.eclipse.persistence.descriptors.ClassDescriptor; | ||
import org.eclipse.persistence.descriptors.RelationalDescriptor; | ||
import org.eclipse.persistence.mappings.AggregateObjectMapping; | ||
import org.eclipse.persistence.mappings.DirectToFieldMapping; | ||
|
||
public class SimpleAggregateProject extends org.eclipse.persistence.sessions.Project { | ||
|
||
public SimpleAggregateProject() { | ||
applyPROJECT(); | ||
applyLOGIN(); | ||
|
||
addDescriptor(buildSimpleAggregateClassDescriptor()); | ||
addDescriptor(buildSimpleEntityDescriptor()); | ||
} | ||
|
||
protected void applyLOGIN() { | ||
} | ||
|
||
protected void applyPROJECT() { | ||
setName("SimpleAggregateSystem"); | ||
} | ||
|
||
public ClassDescriptor buildSimpleAggregateClassDescriptor() { | ||
RelationalDescriptor descriptor = new RelationalDescriptor(); | ||
descriptor.descriptorIsAggregate(); | ||
descriptor.setJavaClass(SimpleAggregate.class); | ||
|
||
// ClassDescriptor Properties. | ||
descriptor.setAlias("SimpleAggregate"); | ||
|
||
|
||
// Query Manager. | ||
|
||
|
||
// Event Manager. | ||
|
||
// Mappings. | ||
DirectToFieldMapping contentMapping = new DirectToFieldMapping(); | ||
contentMapping.setAttributeName("content"); | ||
contentMapping.setFieldName("content->DIRECT"); | ||
descriptor.addMapping(contentMapping); | ||
|
||
return descriptor; | ||
} | ||
|
||
protected ClassDescriptor buildSimpleEntityDescriptor() { | ||
RelationalDescriptor descriptor = new RelationalDescriptor(); | ||
//descriptor.setCacheable(false); | ||
|
||
// SECTION: DESCRIPTOR | ||
descriptor.setJavaClass(SimpleEntity.class); | ||
descriptor.addTableName("SIMPLEENTITY"); | ||
descriptor.addPrimaryKeyFieldName("SIMPLEENTITY.ID"); | ||
|
||
ChangedFieldsLockingPolicy lockingPolicy = new ChangedFieldsLockingPolicy(); | ||
descriptor.setOptimisticLockingPolicy(lockingPolicy); | ||
|
||
// SECTION: DIRECTTOFIELDMAPPING | ||
DirectToFieldMapping directtofieldmapping = new DirectToFieldMapping(); | ||
directtofieldmapping.setAttributeName("id"); | ||
directtofieldmapping.setIsReadOnly(false); | ||
directtofieldmapping.setFieldName("SIMPLEENTITY.ID"); | ||
descriptor.addMapping(directtofieldmapping); | ||
|
||
DirectToFieldMapping fieldmapping = new DirectToFieldMapping(); | ||
fieldmapping.setAttributeName("field"); | ||
fieldmapping.setIsReadOnly(false); | ||
fieldmapping.setFieldName("SIMPLEENTITY.FIELD"); | ||
descriptor.addMapping(fieldmapping); | ||
|
||
AggregateObjectMapping aggregateObjectMapping = new AggregateObjectMapping(); | ||
aggregateObjectMapping.setAttributeName("simpleAggregate"); | ||
aggregateObjectMapping.setReferenceClass(SimpleAggregate.class); | ||
aggregateObjectMapping.setIsNullAllowed(true); | ||
aggregateObjectMapping.addFieldNameTranslation("SIMPLEENTITY.CONTENT", "content->DIRECT"); | ||
descriptor.addMapping(aggregateObjectMapping); | ||
|
||
return descriptor; | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
...core.test/src/org/eclipse/persistence/testing/models/aggregate/SimpleAggregateSystem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 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 v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.aggregate; | ||
|
||
import org.eclipse.persistence.queries.ReadObjectQuery; | ||
import org.eclipse.persistence.sessions.DatabaseSession; | ||
import org.eclipse.persistence.sessions.UnitOfWork; | ||
import org.eclipse.persistence.testing.framework.TestSystem; | ||
import org.eclipse.persistence.testing.tests.dynamic.QuerySQLTracker; | ||
import org.eclipse.persistence.tools.schemaframework.SchemaManager; | ||
|
||
public class SimpleAggregateSystem extends TestSystem { | ||
|
||
public SimpleAggregateSystem() { | ||
project = new SimpleAggregateProject(); | ||
} | ||
|
||
@Override | ||
public void addDescriptors(DatabaseSession session) { | ||
if (project == null) { | ||
project = new SimpleAggregateProject(); | ||
} | ||
session.addDescriptors(project); | ||
} | ||
|
||
@Override | ||
public void createTables(DatabaseSession session) { | ||
SchemaManager schemaManager = new SchemaManager(session); | ||
|
||
schemaManager.replaceObject(SimpleEntity.tableDefinition()); | ||
} | ||
|
||
@Override | ||
public void populate(DatabaseSession session) { | ||
|
||
QuerySQLTracker qTracker = QuerySQLTracker.install(session); | ||
|
||
{ | ||
UnitOfWork uow = session.acquireUnitOfWork(); | ||
|
||
SimpleEntity instance = new SimpleEntity(); | ||
instance.setId("1"); | ||
instance.setField("constant"); | ||
instance.setSimpleAggregate(new SimpleAggregate()); | ||
session.writeObject(instance); | ||
uow.registerObject(instance); | ||
uow.commit(); | ||
} | ||
|
||
{ | ||
UnitOfWork uow = session.acquireUnitOfWork(); | ||
|
||
ReadObjectQuery query = new ReadObjectQuery(); | ||
final SimpleEntity queryInstance = new SimpleEntity(); | ||
queryInstance.setId("1"); | ||
query.setSelectionObject(queryInstance); | ||
final SimpleEntity instance = (SimpleEntity) uow.executeQuery(query); | ||
if (instance == null) { | ||
throw new RuntimeException("Object was not found"); | ||
} | ||
if (instance.getSimpleAggregate() == null) { | ||
//throw new RuntimeException("SimpleAggregate is null"); | ||
} | ||
instance.setSimpleAggregate(instance.getSimpleAggregate() == null ? new SimpleAggregate() : null); | ||
|
||
qTracker.reset(); | ||
|
||
instance.setSimpleAggregate(null); | ||
uow.registerObject(instance); | ||
uow.commit(); | ||
|
||
if (qTracker.getQueries().size() > 0) { | ||
throw new RuntimeException("Unexpected query was executed: " + qTracker.getQueries()); | ||
} | ||
} | ||
|
||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ipselink.core.test/src/org/eclipse/persistence/testing/models/aggregate/SimpleEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 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 v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.aggregate; | ||
|
||
import org.eclipse.persistence.tools.schemaframework.TableDefinition; | ||
|
||
public class SimpleEntity { | ||
private String id; | ||
private String field; | ||
private SimpleAggregate simpleAggregate; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public void setField(String field) { | ||
this.field = field; | ||
} | ||
|
||
public SimpleAggregate getSimpleAggregate() { | ||
return simpleAggregate; | ||
} | ||
|
||
public void setSimpleAggregate(SimpleAggregate simpleAggregate) { | ||
this.simpleAggregate = simpleAggregate; | ||
} | ||
|
||
public static TableDefinition tableDefinition() { | ||
TableDefinition definition = new TableDefinition(); | ||
|
||
definition.setName("SIMPLEENTITY"); | ||
|
||
definition.addIdentityField("ID", String.class, 15); | ||
definition.addField("FIELD", String.class, 15); | ||
definition.addField("CONTENT", String.class, 20); | ||
|
||
return definition; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...re.test/src/org/eclipse/persistence/testing/tests/aggregate/SimpleAggregateTestModel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 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 v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.tests.aggregate; | ||
|
||
import org.eclipse.persistence.testing.framework.TestModel; | ||
import org.eclipse.persistence.testing.framework.TestSuite; | ||
import org.eclipse.persistence.testing.models.aggregate.SimpleAggregateSystem; | ||
|
||
public class SimpleAggregateTestModel extends TestModel { | ||
public SimpleAggregateTestModel() { | ||
setDescription("This model tests reading/writing/deleting of the simple aggregate model."); | ||
} | ||
|
||
@Override | ||
public void addForcedRequiredSystems() { | ||
//We need to ensure that the correct database schema is created | ||
addForcedRequiredSystem(new SimpleAggregateSystem()); | ||
} | ||
|
||
@Override | ||
public void addRequiredSystems() { | ||
} | ||
|
||
@Override | ||
public void addTests() { | ||
addTest(getUpdateObjectTestSuite()); | ||
} | ||
|
||
public static TestSuite getUpdateObjectTestSuite() { | ||
TestSuite suite = new TestSuite(); | ||
suite.setName("AggregateUpdateObjectTestSuite"); | ||
suite.setDescription("This suite tests the updating of each object in the aggregate model."); | ||
|
||
return suite; | ||
} | ||
|
||
public static junit.framework.TestSuite suite() { | ||
return new SimpleAggregateTestModel(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.