mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-25 21:04:51 +00:00
HHH-12380 - Stackoverflow when order_inserts=true
This commit is contained in:
parent
08fa07442b
commit
07a0e1243a
@ -1102,9 +1102,20 @@ boolean hasAnyChildEntityNames(BatchIdentifier batchIdentifier) {
|
|||||||
*/
|
*/
|
||||||
boolean hasParent(BatchIdentifier batchIdentifier) {
|
boolean hasParent(BatchIdentifier batchIdentifier) {
|
||||||
return (
|
return (
|
||||||
parent == batchIdentifier ||
|
parent == batchIdentifier
|
||||||
( parent != null && parent.hasParent( batchIdentifier ) ) ||
|
|| ( parentEntityNames.contains( batchIdentifier.getEntityName() ) )
|
||||||
( parentEntityNames.contains( batchIdentifier.getEntityName() ) )
|
|| parent != null && parent.hasParent( batchIdentifier, new ArrayList<>() )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasParent(BatchIdentifier batchIdentifier, List<BatchIdentifier> stack) {
|
||||||
|
if ( !stack.contains( this ) && parent != null ) {
|
||||||
|
stack.add( this );
|
||||||
|
return parent.hasParent( batchIdentifier, stack );
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
parent == batchIdentifier
|
||||||
|
|| parentEntityNames.contains( batchIdentifier.getEntityName() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.test.insertordering;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.ManyToMany;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andrea Boriero
|
||||||
|
*/
|
||||||
|
@TestForIssue(jiraKey = "HHH-12380")
|
||||||
|
public class InsertOrderingHasParentTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
return new Class[] { Author.class, Book.class, Comment.class };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addSettings(Map settings) {
|
||||||
|
settings.put( Environment.ORDER_INSERTS, "true" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsert() {
|
||||||
|
|
||||||
|
doInHibernate( this::sessionFactory, session -> {
|
||||||
|
Book book = new Book();
|
||||||
|
book.setComment( new Comment( "first comment" ) );
|
||||||
|
book.setComments( Arrays.asList( new Comment( "second comment" ) ) );
|
||||||
|
|
||||||
|
Author author = new Author();
|
||||||
|
author.setBook( book );
|
||||||
|
|
||||||
|
session.persist( author );
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(name = "Author")
|
||||||
|
public static class Author {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
Long id;
|
||||||
|
|
||||||
|
@OneToOne(cascade = CascadeType.ALL)
|
||||||
|
Book book;
|
||||||
|
|
||||||
|
public Book getBook() {
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBook(Book book) {
|
||||||
|
this.book = book;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(name = "Book")
|
||||||
|
public static class Book {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
Long id;
|
||||||
|
|
||||||
|
@OneToOne(cascade = CascadeType.ALL)
|
||||||
|
Comment comment;
|
||||||
|
|
||||||
|
@ManyToMany(cascade = CascadeType.ALL)
|
||||||
|
List<Comment> comments = new ArrayList<>();
|
||||||
|
|
||||||
|
public Comment getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComment(Comment comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Comment> getComments() {
|
||||||
|
return comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComments(List<Comment> comments) {
|
||||||
|
this.comments = comments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(name = "Comment") @Table(name = "book_comment")
|
||||||
|
public static class Comment {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
Long id;
|
||||||
|
|
||||||
|
@Column(name = "book_comment")
|
||||||
|
String comment;
|
||||||
|
|
||||||
|
public Comment() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comment(String comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComment(String comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user