Skip to content
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

Don't validate if the only change is to a @Version attribute (e.g. em.find() with PESSIMISTIC_FORCE_INCREMENT) #2265

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adjusted following feedback:
* Copyright headers
* Formatting/spacing
* Remove exception block from test case and attempt to make the test case clearer

Signed-off-by: Jonathan Gallimore <jgallimore@tomitribe.com>
  • Loading branch information
jgallimore committed Oct 4, 2024
commit 2a564a53b66f5a86bb7209bc19af6b6663a91afe
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024 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
Expand All @@ -24,20 +24,19 @@
public class Task {

@Id
private int id;
private int id;

@Version
private int version;
private int version;

@NotNull
private String name;
private String name;

@Column
private int priority;
private int priority;

public Task() {}


public int getId() {
return id;
}
Expand All @@ -50,12 +49,10 @@ public void setName(final String name) {
this.name = name;
}


public int getPriority() {
return priority;
}


public void setPriority(final int priority) {
this.priority = priority;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--

Copyright (c) 2018, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2018, 2024 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ public void testPessimisticLockWithInvalidData() throws Exception {

commitTransaction(em);

Vector resultSet = getDatabaseSession().executeSQL("select * from CMP3_BV_TASK where ID=900");
Vector<DatabaseRecord> resultSet = getDatabaseSession().executeSQL("select * from CMP3_BV_TASK where ID=900");
assertEquals(1, resultSet.size());

final DatabaseRecord dr = (DatabaseRecord) resultSet.firstElement();
final DatabaseRecord dr = resultSet.firstElement();
assertEquals(900L, dr.get("ID"));
assertEquals(2L, dr.get("VERSION")); // should be incremented by the pessimistic lock
assertNull(dr.get("NAME")); // should be unchanged
Expand Down Expand Up @@ -474,18 +474,13 @@ public void testPessimisticLockUpdateObjectWithInvalidData() throws Exception {
task.setPriority(2);

commitTransaction(em);
} catch (ConstraintViolationException e) {
assertTrue("Transaction not marked for roll back when ConstraintViolation is thrown", getRollbackOnly(em));
Set<ConstraintViolation<?>> constraintViolations = e.getConstraintViolations();
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
Object invalidValue = constraintViolation.getInvalidValue();
System.out.println(invalidValue);
gotConstraintViolations = true;
} catch (RollbackException e) {
e.printStackTrace();
} catch (RollbackException e) {
// we're expecting a rollback exception because we've changed the object
// and it isn't passing validation. Check that the cause is a ConstraintViolationException.

final ConstraintViolationException cve = (ConstraintViolationException) e.getCause();
Set<ConstraintViolation<?>> constraintViolations = cve.getConstraintViolations();
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
final Set<ConstraintViolation<?>> constraintViolations = cve.getConstraintViolations();
final ConstraintViolation constraintViolation = constraintViolations.iterator().next();
assertEquals("must not be null", constraintViolation.getMessage());
gotConstraintViolations = true;
} finally {
Expand Down
Loading