-
Notifications
You must be signed in to change notification settings - Fork 3.6k
HHH-18891 fix of an AssertionError when using a NotFound annotation #10247
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
mbellade
wants to merge
1
commit into
hibernate:6.6
Choose a base branch
from
mbellade:HHH-18891_6.6
base: 6.6
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
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
144 changes: 144 additions & 0 deletions
144
...e-core/src/test/java/org/hibernate/orm/test/notfound/CompositeForeignKeyNotFoundTest.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,144 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.notfound; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import org.hibernate.FetchNotFoundException; | ||
import org.hibernate.annotations.JoinColumnOrFormula; | ||
import org.hibernate.annotations.JoinFormula; | ||
import org.hibernate.annotations.NotFound; | ||
import org.hibernate.annotations.NotFoundAction; | ||
import org.hibernate.query.Query; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.JiraKey; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
@JiraKey(value = "HHH-18891") | ||
@DomainModel( | ||
annotatedClasses = {CompositeForeignKeyNotFoundTest.Document.class, CompositeForeignKeyNotFoundTest.DocumentIgnore.class, | ||
CompositeForeignKeyNotFoundTest.DocumentException.class, CompositeForeignKeyNotFoundTest.Person.class}) | ||
@SessionFactory | ||
public class CompositeForeignKeyNotFoundTest { | ||
|
||
@Test | ||
void hhh18891TestWithNotFoundIgnore(SessionFactoryScope scope) { | ||
|
||
// prepare document | ||
scope.inTransaction( session -> { | ||
Query nativeQuery = session.createNativeQuery( | ||
"insert into DocumentIgnore (id,owner) values (123,42)" ); | ||
nativeQuery.executeUpdate(); | ||
} ); | ||
|
||
// assert document | ||
scope.inTransaction( session -> { | ||
final DocumentIgnore document = session.find( DocumentIgnore.class, 123 ); | ||
assertNotNull( document ); | ||
assertEquals( 123, document.id ); | ||
assertNull( document.owner ); | ||
} ); | ||
} | ||
|
||
@Test | ||
void hhh18891TestWithNotFoundException(SessionFactoryScope scope) { | ||
|
||
// prepare document | ||
scope.inTransaction( session -> { | ||
Query nativeQuery = session.createNativeQuery( | ||
"insert into DocumentException (id,owner) values (123,42)" ); | ||
Comment on lines
+60
to
+61
Check noticeCode scanning / CodeQL Deprecated method or constructor invocation Note test
Invoking
QueryProducerImplementor.createNativeQuery Error loading related location Loading |
||
nativeQuery.executeUpdate(); | ||
} ); | ||
|
||
// assert document | ||
scope.inTransaction( session -> { | ||
assertThrows( FetchNotFoundException.class, () -> | ||
session.find( DocumentException.class, 123 ) ); | ||
} ); | ||
} | ||
|
||
@Test | ||
void hhh18891TestWithoutNotFoundAnnotation(SessionFactoryScope scope) { | ||
|
||
// prepare document | ||
scope.inTransaction( session -> { | ||
Query nativeQuery = session.createNativeQuery( | ||
"insert into Document (id,owner) values (123,42)" ); | ||
Comment on lines
+77
to
+78
Check noticeCode scanning / CodeQL Deprecated method or constructor invocation Note test
Invoking
QueryProducerImplementor.createNativeQuery Error loading related location Loading |
||
nativeQuery.executeUpdate(); | ||
} ); | ||
|
||
// assert document | ||
scope.inTransaction( session -> { | ||
final Document document = session.find( Document.class, 123 ); | ||
assertNotNull( document ); | ||
assertEquals( 123, document.id ); | ||
assertNull( document.owner ); | ||
} ); | ||
} | ||
|
||
@Entity(name = "DocumentIgnore") | ||
public static class DocumentIgnore { | ||
|
||
@Id | ||
@GeneratedValue | ||
Long id; | ||
|
||
@ManyToOne | ||
@NotFound(action = NotFoundAction.IGNORE) | ||
@JoinColumnOrFormula(column = @JoinColumn(name = "owner", referencedColumnName = "id", insertable = false, | ||
updatable = false)) | ||
@JoinColumnOrFormula(formula = @JoinFormula(value = "'fubar'", referencedColumnName = "name")) | ||
Person owner; | ||
} | ||
|
||
@Entity(name = "DocumentException") | ||
public static class DocumentException { | ||
|
||
@Id | ||
@GeneratedValue | ||
Long id; | ||
|
||
@ManyToOne | ||
@NotFound(action = NotFoundAction.EXCEPTION) | ||
@JoinColumnOrFormula(column = @JoinColumn(name = "owner", referencedColumnName = "id", insertable = false, | ||
updatable = false)) | ||
@JoinColumnOrFormula(formula = @JoinFormula(value = "'fubar'", referencedColumnName = "name")) | ||
Person owner; | ||
} | ||
|
||
@Entity(name = "Document") | ||
public static class Document { | ||
|
||
@Id | ||
@GeneratedValue | ||
Long id; | ||
|
||
@ManyToOne | ||
@JoinColumnOrFormula(column = @JoinColumn(name = "owner", referencedColumnName = "id", insertable = false, | ||
updatable = false)) | ||
@JoinColumnOrFormula(formula = @JoinFormula(value = "'fubar'", referencedColumnName = "name")) | ||
Person owner; | ||
} | ||
|
||
@Entity(name = "Person") | ||
public static class Person { | ||
|
||
@Id | ||
Long id; | ||
|
||
String name; | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note test