Fix some issues with tests migration

This commit is contained in:
Andrea Boriero 2021-01-25 15:07:53 +01:00 committed by Jan Schatteman
parent 491cbabc6c
commit e0e44433a9
12 changed files with 174 additions and 431 deletions

View File

@ -0,0 +1,58 @@
/*
* 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.jpa.test.cacheable.api;
import javax.persistence.EntityManagerFactory;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Steve Ebersole
*/
// TODO Convert to annotation based testing? Setting the CachingRegionFactory as below leads to a CNFE
@Jpa(
annotatedClasses = Order.class,
integrationSettings = {
@Setting(name = AvailableSettings.CACHE_REGION_FACTORY, value = "org.hibernate.testing.cache.CachingRegionFactory"),
@Setting(name = AvailableSettings.JPA_SHARED_CACHE_MODE, value = "ALL"),
@Setting(name = AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, value = "read-write"),
@Setting(name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true"),
}
)
public class JpaCacheApiUsageTest {
@Test
public void testEviction(EntityManagerFactoryScope scope) {
// first create an Order
scope.inTransaction(
entityManager ->
entityManager.persist( new Order( 1, 500 ) )
);
final EntityManagerFactory entityManagerFactory = scope.getEntityManagerFactory();
assertTrue( entityManagerFactory.getCache().contains( Order.class, 1 ) );
scope.inTransaction(
entityManager -> {
assertTrue( entityManagerFactory.getCache().contains( Order.class, 1 ) );
entityManager.createQuery( "delete Order" ).executeUpdate();
}
);
assertFalse( entityManagerFactory.getCache().contains( Order.class, 1 ) );
}
}

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.orm.test.jpa.cacheable.api; package org.hibernate.jpa.test.cacheable.api;
import javax.persistence.Cacheable; import javax.persistence.Cacheable;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -1,110 +0,0 @@
/*
* 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.orm.test.jpa.cacheable.api;
import javax.persistence.EntityManager;
import javax.persistence.SharedCacheMode;
import java.util.Map;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.cache.CachingRegionFactory;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Steve Ebersole
*/
// TODO Convert to annotation based testing? Setting the CachingRegionFactory as below leads to a CNFE
//@DomainModel(
// annotatedClasses = Order.class
//)
//@ServiceRegistry(
// settings = {
// @Setting(name = AvailableSettings.CACHE_REGION_FACTORY, value = "CachingRegionFactory.class"),
// @Setting(name = AvailableSettings.JPA_SHARED_CACHE_MODE, value = "ALL")
// }
//)
//@SessionFactory
public class JpaCacheApiUsageTest /*extends BaseEntityManagerFunctionalTestCase*/ {
// @Override
// protected Class<?>[] getAnnotatedClasses() {
// return new Class[] { Order.class };
// }
//
// @Override
// @SuppressWarnings("unchecked")
// protected void addConfigOptions(Map options) {
//// options.put( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" );
// options.put( AvailableSettings.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
//// options.put( AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-write" );
// options.put( org.hibernate.jpa.AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.ALL );
// }
@Test
@NotImplementedYet(reason = "BulkOperationCleanupAction is never created", expectedVersion = "6.0")
public void testEviction() {
throw new NotYetImplementedFor6Exception();
// first create an Order
// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// em.persist( new Order( 1, 500 ) );
// em.getTransaction().commit();
// em.close();
//
// assertTrue( entityManagerFactory().getCache().contains( Order.class, 1 ) );
//
// em = getOrCreateEntityManager();
// em.getTransaction().begin();
// assertTrue( entityManagerFactory().getCache().contains( Order.class, 1 ) );
// em.createQuery( "delete Order" ).executeUpdate();
// em.getTransaction().commit();
// em.close();
//
// assertFalse( entityManagerFactory().getCache().contains( Order.class, 1 ) );
}
// @Test
// public void testEviction(SessionFactoryScope scope) {
// scope.inTransaction(
// session -> {
// session.getTransaction().begin();
// session.persist( new Order( 1, 500 ) );
// session.getTransaction().commit();
// session.close();
// }
// );
//
// scope.inSession(
// session -> {
// assertTrue( session.getEntityManagerFactory().getCache().contains( Order.class, 1 ) );
// }
// );
//
// scope.inTransaction(
// session -> {
// session.getTransaction().begin();
// assertTrue( session.getEntityManagerFactory().getCache().contains( Order.class, 1 ) );
// session.createQuery( "delete Order" ).executeUpdate();
// session.getTransaction().commit();
// session.close();
// }
// );
//
// scope.inSession(
// session -> {
// assertFalse( session.getEntityManagerFactory().getCache().contains( Order.class, 1 ) );
// }
// );
// }
}

View File

@ -15,7 +15,6 @@ import org.hibernate.jpa.test.Kitten;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa; import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting; import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -39,28 +38,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class CallbacksDisabledTest { public class CallbacksDisabledTest {
@Test @Test
public void testCallbacksAreDisabled(EntityManagerFactoryScope scope) throws Exception { public void testCallbacksAreDisabled(EntityManagerFactoryScope scope) {
int id = scope.fromTransaction( scope.inTransaction(
entityManager -> { entityManager -> {
Cat c = new Cat(); Cat c = new Cat();
c.setName( "Kitty" ); c.setName( "Kitty" );
c.setDateOfBirth( new Date( 90, 11, 15 ) ); c.setDateOfBirth( new Date( 90, 11, 15 ) );
entityManager.persist( c ); entityManager.persist( c );
return c.getId(); entityManager.getTransaction().commit();
} entityManager.clear();
); entityManager.getTransaction().begin();
Cat _c = entityManager.find( Cat.class, c.getId() );
scope.inTransaction(
entityManager -> {
Cat _c = entityManager.find( Cat.class, id );
assertTrue( _c.getAge() == 0 ); // With listeners enabled this would be false. Proven by org.hibernate.orm.test.jpa.callbacks.CallbacksTest.testCallbackMethod assertTrue( _c.getAge() == 0 ); // With listeners enabled this would be false. Proven by org.hibernate.orm.test.jpa.callbacks.CallbacksTest.testCallbackMethod
} }
); );
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Cat" ).executeUpdate();
}
);
} }
} }

View File

@ -16,7 +16,7 @@ import org.hibernate.jpa.test.Kitten;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.Jpa; import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -38,34 +38,40 @@ import static org.junit.jupiter.api.Assertions.fail;
Rythm.class Rythm.class
}) })
public class CallbacksTest { public class CallbacksTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Cat" ).executeUpdate();
entityManager.createQuery( "delete from Television" ).executeUpdate();
entityManager.createQuery( "delete from Plant" ).executeUpdate();
entityManager.createQuery( "delete from Kitten" ).executeUpdate();
}
);
}
@Test @Test
public void testCallbackMethod(EntityManagerFactoryScope scope) { public void testCallbackMethod(EntityManagerFactoryScope scope) {
int id = scope.fromTransaction( scope.inTransaction(
entityManager -> { entityManager -> {
Cat c = new Cat(); Cat c = new Cat();
c.setName( "Kitty" ); c.setName( "Kitty" );
c.setDateOfBirth( new Date( 90, 11, 15 ) ); c.setDateOfBirth( new Date( 90, 11, 15 ) );
entityManager.persist( c ); entityManager.persist( c );
return c.getId(); entityManager.getTransaction().commit();
}
);
scope.inTransaction(
entityManager -> {
Cat _c = entityManager.find( Cat.class, id );
assertFalse( _c.getAge() == 0 );
_c.setName( "Tomcat" ); //update this entity
}
);
scope.inTransaction(
entityManager -> {
Cat _c = entityManager.find( Cat.class, id );
assertEquals( "Tomcat", _c.getName() );
}
);
scope.inTransaction( entityManager.clear();
entityManager -> {
entityManager.createQuery( "delete from Cat" ).executeUpdate(); entityManager.getTransaction().begin();
c = entityManager.find( Cat.class, c.getId() );
assertFalse( c.getAge() == 0 );
c.setName( "Tomcat" ); //update this entity
entityManager.getTransaction().commit();
entityManager.clear();
entityManager.getTransaction().begin();
c = entityManager.find( Cat.class, c.getId() );
assertEquals( "Tomcat", c.getName() );
} }
); );
} }
@ -76,44 +82,38 @@ public class CallbacksTest {
PV(int version) { PV(int version) {
this.version = version; this.version = version;
} }
private int version; private int version;
private void set(int version) { private void set(int version) {
this.version = version; this.version = version;
} }
private int get() { private int get() {
return version; return version;
} }
} }
scope.inTransaction(
entityManager -> {
Cat c = new Cat(); Cat c = new Cat();
c.setName( "Kitty" ); c.setName( "Kitty" );
c.setLength( 12 ); c.setLength( 12 );
c.setDateOfBirth( new Date( 90, 11, 15 ) ); c.setDateOfBirth( new Date( 90, 11, 15 ) );
PV previousVersion = new PV( c.getManualVersion() ); PV previousVersion = new PV( c.getManualVersion() );
entityManager.persist( c );
entityManager.getTransaction().commit();
scope.inTransaction( entityManager.getTransaction().begin();
entityManager -> entityManager.persist( c ) c = entityManager.find( Cat.class, c.getId() );
); assertNotNull( c.getLastUpdate() );
scope.inTransaction( assertTrue( previousVersion.get() < c.getManualVersion() );
entityManager -> { assertEquals( 12, c.getLength() );
Cat _c = entityManager.find( Cat.class, c.getId() ); previousVersion.set( c.getManualVersion() );
assertNotNull( _c.getLastUpdate() ); c.setName( "new name" );
assertTrue( previousVersion.get() < _c.getManualVersion() ); entityManager.getTransaction().commit();
assertEquals( 12, _c.getLength() ); entityManager.getTransaction().begin();
previousVersion.set( _c.getManualVersion() ); c = entityManager.find( Cat.class, c.getId() );
_c.setName( "new name" ); assertTrue( previousVersion.get() < c.getManualVersion() );
}
);
scope.inTransaction(
entityManager -> {
Cat _c = entityManager.find( Cat.class, c.getId() );
assertTrue( previousVersion.get() < _c.getManualVersion() );
}
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Cat" ).executeUpdate();
} }
); );
} }
@ -135,12 +135,6 @@ public class CallbacksTest {
List ids = Cat.getIdList(); List ids = Cat.getIdList();
Object id = Cat.getIdList().get( ids.size() - 1 ); Object id = Cat.getIdList().get( ids.size() - 1 );
assertNotNull( id ); assertNotNull( id );
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Cat" ).executeUpdate();
}
);
} }
//Not a test since the spec did not make the proper change on listeners //Not a test since the spec did not make the proper change on listeners
@ -183,12 +177,6 @@ public class CallbacksTest {
assertNotNull( rc.getCreationDate() ); assertNotNull( rc.getCreationDate() );
} }
); );
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Television" ).executeUpdate();
}
);
} }
@Test @Test
@ -205,12 +193,6 @@ public class CallbacksTest {
assertTrue( tv.isLast ); assertTrue( tv.isLast );
} }
); );
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Television" ).executeUpdate();
}
);
} }
@Test @Test
@ -229,7 +211,8 @@ public class CallbacksTest {
} }
catch (Exception e) { catch (Exception e) {
fail( "should have raised an ArythmeticException:" + e.getClass() ); fail( "should have raised an ArythmeticException:" + e.getClass() );
} finally { }
finally {
entityManager.getTransaction().rollback(); entityManager.getTransaction().rollback();
entityManager.close(); entityManager.close();
} }
@ -247,81 +230,62 @@ public class CallbacksTest {
entityManager.flush(); entityManager.flush();
} }
); );
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Plant" ).executeUpdate();
}
);
} }
@Test @Test
@FailureExpected(reason = "collection change does not trigger an event", jiraKey = "EJB-288") @FailureExpected(reason = "collection change does not trigger an event", jiraKey = "EJB-288")
public void testPostUpdateCollection(EntityManagerFactoryScope scope) { public void testPostUpdateCollection(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
try {
// create a cat // create a cat
Cat cat = new Cat(); Cat cat = new Cat();
cat.setLength( 23 ); cat.setLength( 23 );
cat.setAge( 2 ); cat.setAge( 2 );
cat.setName( "Beetle" ); cat.setName( "Beetle" );
cat.setDateOfBirth( new Date() ); cat.setDateOfBirth( new Date() );
entityManager.getTransaction().begin();
scope.inTransaction(
entityManager -> {
entityManager.persist( cat ); entityManager.persist( cat );
} entityManager.getTransaction().commit();
);
// assert it is persisted // assert it is persisted
List ids = Cat.getIdList(); List ids = Cat.getIdList();
Object id = Cat.getIdList().get( ids.size() - 1 ); Object id = Cat.getIdList().get( ids.size() - 1 );
assertNotNull( id ); assertNotNull( id );
// add a kitten to the cat - triggers PostCollectionRecreateEvent // add a kitten to the cat - triggers PostCollectionRecreateEvent
scope.inTransaction(
entityManager -> {
int postVersion = Cat.postVersion; int postVersion = Cat.postVersion;
entityManager.getTransaction().begin();
Kitten kitty = new Kitten(); Kitten kitty = new Kitten();
kitty.setName( "kitty" ); kitty.setName( "kitty" );
List kittens = new ArrayList<Kitten>(); List kittens = new ArrayList<Kitten>();
kittens.add( kitty ); kittens.add( kitty );
cat.setKittens( kittens ); cat.setKittens( kittens );
entityManager.getTransaction().commit();
assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." ); assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." );
}
);
Kitten tom = new Kitten(); Kitten tom = new Kitten();
tom.setName( "Tom" ); tom.setName( "Tom" );
scope.inTransaction(
entityManager -> {
// add another kitten - triggers PostCollectionUpdateEvent. // add another kitten - triggers PostCollectionUpdateEvent.
int postVersion = Cat.postVersion; postVersion = Cat.postVersion;
entityManager.getTransaction().begin();
cat.getKittens().add( tom ); cat.getKittens().add( tom );
entityManager.getTransaction().commit();
assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." ); assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." );
}
);
scope.inTransaction(
entityManager -> {
// delete a kitty - triggers PostCollectionUpdateEvent // delete a kitty - triggers PostCollectionUpdateEvent
int postVersion = Cat.postVersion; postVersion = Cat.postVersion;
entityManager.getTransaction().begin();
cat.getKittens().remove( tom ); cat.getKittens().remove( tom );
entityManager.getTransaction().commit();
assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." ); assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." );
} }
); catch (Exception e) {
if ( entityManager.getTransaction().isActive() ) {
scope.inTransaction( entityManager.getTransaction().rollback();
entityManager -> { }
// delete and recreate kittens - triggers PostCollectionRemoveEvent and PostCollectionRecreateEvent) throw e;
int postVersion = Cat.postVersion;
cat.setKittens( new ArrayList<Kitten>() );
assertEquals( postVersion + 2, Cat.postVersion, "Post version should have been incremented." );
} }
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Cat" ).executeUpdate();
entityManager.createQuery( "delete from Kitten" ).executeUpdate();
} }
); );
} }

View File

@ -35,11 +35,9 @@ public class CascadeTest {
student.setPrimaryTeacher( teacher ); student.setPrimaryTeacher( teacher );
entityManager.persist( teacher ); entityManager.persist( teacher );
} entityManager.getTransaction().commit();
);
scope.inTransaction( entityManager.getTransaction().begin();
entityManager -> {
Teacher foundTeacher = (Teacher) entityManager.createQuery( "select t from Teacher as t" ) Teacher foundTeacher = (Teacher) entityManager.createQuery( "select t from Teacher as t" )
.getSingleResult(); .getSingleResult();

View File

@ -11,8 +11,9 @@ import java.lang.reflect.Method;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import org.hibernate.testing.junit4.ClassLoadingIsolater; import org.hibernate.testing.junit4.ClassLoadingIsolater;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.junit.Rule; import org.junit.Rule;
import org.junit.jupiter.api.Test; import org.junit.Test;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
@ -21,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.fail;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@BaseUnitTest
public class NoCdiAvailableTest { public class NoCdiAvailableTest {
public static final String[] EXCLUDED_PACKAGES = new String[] { public static final String[] EXCLUDED_PACKAGES = new String[] {
"javax.enterprise.inject.", "javax.enterprise.inject.",

View File

@ -1,38 +0,0 @@
/*
* 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.orm.test.jpa.cdi.extended;
import javax.ejb.LocalBean;
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
/**
* @author Vlad Mihalcea
*/
@Stateful
@LocalBean
public class ConversationalEventManager {
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager em;
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public Event saveEvent(String eventName) {
final Event event = new Event();
event.setName( eventName );
em.persist( event );
return event;
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void endConversation() {
}
}

View File

@ -1,41 +0,0 @@
/*
* 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.orm.test.jpa.cdi.extended;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* @author Vlad Mihalcea
*/
@Entity(name = "Event")
public class Event {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,44 +0,0 @@
/*
* 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.orm.test.jpa.cdi.extended;
import javax.annotation.PostConstruct;
import javax.ejb.LocalBean;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import org.hibernate.FlushMode;
import org.hibernate.Session;
/**
* @author Vlad Mihalcea
*/
@Stateful
@LocalBean
public class ManualFlushConversationalEventManager {
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager em;
@PostConstruct
public void init() {
em.unwrap( Session.class ).setHibernateFlushMode( FlushMode.MANUAL );
}
public Event saveEvent(String eventName) {
final Event event = new Event();
event.setName( eventName );
em.persist( event );
return event;
}
public void endConversation() {
em.flush();
}
}

View File

@ -1,35 +0,0 @@
/*
* 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.orm.test.jpa.cdi.extended;
import javax.ejb.LocalBean;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
/**
* @author Vlad Mihalcea
*/
@Stateful
@LocalBean
public class NonConversationalEventManager {
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager em;
public Event saveEvent(String eventName) {
final Event event = new Event();
event.setName( eventName );
em.persist( event );
return event;
}
public void endConversation() {
em.flush();
}
}

View File

@ -13,7 +13,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ParameterContext;
@Inherited @Inherited
@Target( ElementType.TYPE ) @Target( ElementType.TYPE )