From 2bf85ffd2a3c3f21dacce095a1c6cb3e40eb0227 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Sat, 7 Apr 2018 12:40:23 +0100 Subject: [PATCH] HHH-12464 - Add test for issue --- .../org/hibernate/id/CreateDeleteTest.java | 65 +++++++++++++++++++ .../src/test/resources/log4j.properties | 1 + 2 files changed, 66 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/id/CreateDeleteTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/id/CreateDeleteTest.java b/hibernate-core/src/test/java/org/hibernate/id/CreateDeleteTest.java new file mode 100644 index 0000000000..c42ea26e09 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/id/CreateDeleteTest.java @@ -0,0 +1,65 @@ +/* + * 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 . + */ +package org.hibernate.id; + +import org.hibernate.FlushMode; +import org.hibernate.action.internal.EntityAction; +import org.hibernate.internal.CoreMessageLogger; + +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.logger.LoggerInspectionRule; +import org.hibernate.testing.logger.Triggerable; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import org.jboss.logging.Logger; + +import static junit.framework.TestCase.assertTrue; +import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; + +@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) +@TestForIssue(jiraKey = "HHH-12464") +public class CreateDeleteTest extends BaseCoreFunctionalTestCase { + + @Rule + public LoggerInspectionRule logInspection = new LoggerInspectionRule( + Logger.getMessageLogger( CoreMessageLogger.class, EntityAction.class.getName() ) + ); + + private Triggerable triggerable; + + @Before + public void setUp() { + triggerable = logInspection.watchForLogMessages( + "Skipping action - the persistence context does not contain any entry for the entity" ); + triggerable.reset(); + } + + @Test + public void createAndDeleteAnEntityInTheSameTransactionTest() { + doInHibernate( this::sessionFactory, session -> { + session.setHibernateFlushMode( FlushMode.COMMIT ); + RootEntity entity = new RootEntity(); + session.persist( entity ); + session.delete( entity ); + } ); + + assertTrue( triggerable.wasTriggered() ); + } + + @Override + public Class[] getAnnotatedClasses() { + return new Class[] { + RootEntity.class, + RelatedEntity.class, + }; + } +} diff --git a/hibernate-core/src/test/resources/log4j.properties b/hibernate-core/src/test/resources/log4j.properties index 0ad1dc3ae8..d288a3b43d 100644 --- a/hibernate-core/src/test/resources/log4j.properties +++ b/hibernate-core/src/test/resources/log4j.properties @@ -49,6 +49,7 @@ log4j.logger.org.hibernate.engine.internal.StatisticalLoggingSessionEventListene log4j.logger.org.hibernate.boot.model.source.internal.hbm.ModelBinder=debug log4j.logger.org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry=debug +log4j.logger.org.hibernate.action.internal.EntityAction=debug log4j.logger.org.hibernate.engine.internal.Cascade=trace