-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-18675. Ignore generic, synthetic property in JPA-model #9029
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
96 changes: 96 additions & 0 deletions
96
...e-core/src/test/java/org/hibernate/orm/test/manytomany/generic/ManyToManyGenericTest.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,96 @@ | ||
| /* | ||
| * SPDX-License-Identifier: LGPL-2.1-or-later | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.manytomany.generic; | ||
|
|
||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.JoinTable; | ||
| import jakarta.persistence.ManyToMany; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.OneToMany; | ||
| import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; | ||
| import org.hibernate.testing.orm.junit.Jpa; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.*; | ||
|
|
||
| @Jpa( | ||
| annotatedClasses = { | ||
| ManyToManyGenericTest.NodeTree.class, | ||
| ManyToManyGenericTest.GenericNode.class | ||
| } | ||
| ) | ||
| public class ManyToManyGenericTest { | ||
|
|
||
| @Test | ||
| void testSelfReferencingGeneric(final EntityManagerFactoryScope scope) { | ||
| final UUID treeId = scope.fromTransaction(em -> { | ||
| final NodeTree tree = new NodeTree(); | ||
| final GenericNode<?> root = new GenericNode<>(); | ||
| root.tree = tree; | ||
| final GenericNode<?> branch = new GenericNode<>(); | ||
| branch.tree = tree; | ||
| tree.nodes.add(root); | ||
| tree.nodes.add(branch); | ||
| root.children.add(branch); | ||
| em.persist(tree); | ||
| return tree.id; | ||
| }); | ||
|
|
||
| final NodeTree nodeTree = scope.fromEntityManager(em -> em.find(NodeTree.class, treeId)); | ||
|
|
||
| assertThat(nodeTree, is(notNullValue())); | ||
| assertThat(nodeTree.id, is(treeId)); | ||
| assertThat(nodeTree.nodes, iterableWithSize(2)); | ||
| assertThat(nodeTree.nodes, containsInAnyOrder(List.of( | ||
| hasProperty("children", iterableWithSize(1)), | ||
| hasProperty("children", emptyIterable()) | ||
| ))); | ||
| } | ||
|
|
||
| @Entity(name = "tree") | ||
| public static class NodeTree { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| public UUID id; | ||
|
|
||
| @OneToMany(mappedBy = "tree", fetch = FetchType.EAGER, cascade = CascadeType.ALL) | ||
| public Set<GenericNode<?>> nodes = new HashSet<>(); | ||
| } | ||
|
|
||
| @Entity(name = "node") | ||
| public static class GenericNode<T> { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| public UUID id; | ||
|
|
||
| @ManyToOne(optional = false) | ||
| @JoinColumn(name = "TREE_ID") | ||
| public NodeTree tree; | ||
|
|
||
| @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.DETACH}) | ||
| @JoinTable(name = "NODE_CHILDREN", | ||
| joinColumns = {@JoinColumn(name = "TREE_ID", referencedColumnName = "TREE_ID"), @JoinColumn(name = "NODE_ID", referencedColumnName = "ID")}, | ||
| inverseJoinColumns = {@JoinColumn(name = "CHILD_ID", referencedColumnName = "ID")} | ||
| ) | ||
| private final Set<GenericNode<?>> children = new HashSet<>(); | ||
|
|
||
| public Set<GenericNode<?>> getChildren() { | ||
| return children; | ||
| } | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
...ore/src/test/java/org/hibernate/orm/test/manytomany/generic/ManyToManyNonGenericTest.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,106 @@ | ||
| /* | ||
| * SPDX-License-Identifier: LGPL-2.1-or-later | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.manytomany.generic; | ||
|
|
||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.JoinTable; | ||
| import jakarta.persistence.ManyToMany; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.OneToMany; | ||
| import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; | ||
| import org.hibernate.testing.orm.junit.Jpa; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| import static org.hamcrest.Matchers.emptyIterable; | ||
| import static org.hamcrest.Matchers.hasProperty; | ||
| import static org.hamcrest.Matchers.is; | ||
| import static org.hamcrest.Matchers.iterableWithSize; | ||
| import static org.hamcrest.Matchers.notNullValue; | ||
|
|
||
| @Jpa( | ||
| annotatedClasses = { | ||
| ManyToManyNonGenericTest.NodeTree.class, | ||
| ManyToManyNonGenericTest.Node.class | ||
| } | ||
| ) | ||
| public class ManyToManyNonGenericTest { | ||
|
|
||
| @Test | ||
| void testSelfReferencingGeneric(final EntityManagerFactoryScope scope) { | ||
| final UUID treeId = scope.fromTransaction(em -> { | ||
| final NodeTree tree = new NodeTree(); | ||
| final Node root = new Node(); | ||
| root.tree = tree; | ||
| final Node branch = new Node(); | ||
| branch.tree = tree; | ||
| tree.nodes.add(root); | ||
| tree.nodes.add(branch); | ||
| root.children.add(branch); | ||
| em.persist(tree); | ||
| return tree.id; | ||
| }); | ||
|
|
||
| final NodeTree nodeTree = scope.fromEntityManager(em -> em.find(NodeTree.class, treeId)); | ||
|
|
||
| assertThat(nodeTree, is(notNullValue())); | ||
| assertThat(nodeTree.id, is(treeId)); | ||
| assertThat(nodeTree.nodes, iterableWithSize(2)); | ||
| assertThat(nodeTree.nodes, containsInAnyOrder(List.of( | ||
| hasProperty("children", iterableWithSize(1)), | ||
| hasProperty("children", emptyIterable()) | ||
| ))); | ||
| } | ||
|
|
||
| @Entity(name = "tree") | ||
| public static class NodeTree { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| public UUID id; | ||
|
|
||
| @OneToMany(mappedBy = "tree", fetch = FetchType.EAGER, cascade = CascadeType.ALL) | ||
| public Set<Node> nodes = new HashSet<>(); | ||
| } | ||
|
|
||
| @Entity(name = "node") | ||
| public static class Node { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| public UUID id; | ||
|
|
||
| @ManyToOne(optional = false) | ||
| @JoinColumn(name = "TREE_ID") | ||
| public NodeTree tree; | ||
|
|
||
| @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.DETACH}) | ||
| @JoinTable(name = "NODE_CHILDREN", | ||
| joinColumns = {@JoinColumn(name = "TREE_ID", referencedColumnName = "TREE_ID"), @JoinColumn(name = "NODE_ID", referencedColumnName = "ID")}, | ||
| inverseJoinColumns = {@JoinColumn(name = "CHILD_ID", referencedColumnName = "ID")} | ||
| ) | ||
| private final Set<Node> children = new HashSet<>(); | ||
|
|
||
| public Set<Node> getChildren() { | ||
| return children; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "node [%s] parent of %s".formatted(id, children.stream().map(n -> n.id).toList()); | ||
| } | ||
| } | ||
| } |
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.