Migrate tests from org.hibernate.jpa.test to org.hibernate.orm.test.jpa

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2020-12-02 15:03:27 +01:00
parent e3a36974a8
commit f9937f66be
104 changed files with 2283 additions and 2262 deletions

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.query.sql.internal;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.query.spi.NonSelectQueryPlan;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
@ -23,6 +24,6 @@ public class NativeNonSelectQueryPlanImpl implements NonSelectQueryPlan {
@Override
public int executeUpdate(ExecutionContext executionContext) {
throw new NotYetImplementedException();
throw new NotYetImplementedFor6Exception();
}
}

View File

@ -1,102 +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.jpa.test.beanvalidation;
import java.math.BigDecimal;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.RollbackException;
import javax.validation.ConstraintViolationException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.beanvalidation.ValidationMode;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Emmanuel Bernard
*/
public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected void addMappings(Map settings) {
settings.put(
AvailableSettings.JPA_VALIDATION_MODE,
ValidationMode.AUTO
);
}
@Test
public void testBeanValidationIntegrationOnFlush() {
CupHolder ch = new CupHolder();
ch.setRadius( new BigDecimal( "12" ) );
ch.setTitle( "foo" );
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
em.persist( ch );
em.flush();
fail( "invalid object should not be persisted" );
}
catch ( ConstraintViolationException e ) {
assertEquals( 1, e.getConstraintViolations().size() );
}
assertTrue(
"A constraint violation exception should mark the transaction for rollback",
em.getTransaction().getRollbackOnly()
);
em.getTransaction().rollback();
em.close();
}
@Test
public void testBeanValidationIntegrationOnCommit() {
CupHolder ch = new CupHolder();
ch.setRadius( new BigDecimal( "9" ) );
ch.setTitle( "foo" );
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( ch );
em.flush();
try {
ch.setRadius( new BigDecimal( "12" ) );
em.getTransaction().commit();
fail( "invalid object should not be persisted" );
}
catch ( RollbackException e ) {
final Throwable cve = e.getCause();
assertTrue( cve instanceof ConstraintViolationException );
assertEquals( 1, ( (ConstraintViolationException) cve ).getConstraintViolations().size() );
}
em.close();
}
@Test
@RequiresDialect(H2Dialect.class)
public void testTitleColumnHasExpectedLength() {
EntityManager em = getOrCreateEntityManager();
int len = (Integer) em.createNativeQuery(
"select CHARACTER_MAXIMUM_LENGTH from INFORMATION_SCHEMA.COLUMNS c where c.TABLE_NAME = 'CUPHOLDER' and c.COLUMN_NAME = 'TITLE'"
).getSingleResult();
assertEquals( 64, len );
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
CupHolder.class
};
}
}

View File

@ -1,62 +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.jpa.test.cacheable.api;
import javax.persistence.EntityManager;
import javax.persistence.SharedCacheMode;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import org.hibernate.testing.cache.CachingRegionFactory;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Steve Ebersole
*/
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
public void testEviction() {
// 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 ) );
}
}

View File

@ -1,101 +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.jpa.test.cacheable.cachemodes;
import javax.persistence.CacheRetrieveMode;
import javax.persistence.CacheStoreMode;
import javax.persistence.EntityManager;
import org.hibernate.CacheMode;
import org.hibernate.Session;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.HibernateEntityManager;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Steve Ebersole
*/
public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
@Override
public Class[] getAnnotatedClasses() {
return new Class[] { SimpleEntity.class };
}
@Test
public void testEntityManagerCacheModes() {
EntityManager em;
Session session;
em = getOrCreateEntityManager();
session = em.unwrap( Session.class );
// defaults...
assertEquals( CacheStoreMode.USE, em.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheRetrieveMode.USE, em.getProperties().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheMode.NORMAL, session.getCacheMode() );
// overrides...
em.setProperty( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.REFRESH );
assertEquals( CacheStoreMode.REFRESH, em.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.REFRESH, session.getCacheMode() );
em.setProperty( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.BYPASS );
assertEquals( CacheStoreMode.BYPASS, em.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.GET, session.getCacheMode() );
em.setProperty( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE, CacheRetrieveMode.BYPASS );
assertEquals( CacheRetrieveMode.BYPASS, em.getProperties().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheMode.IGNORE, session.getCacheMode() );
em.setProperty( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.USE );
assertEquals( CacheStoreMode.USE, em.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.PUT, session.getCacheMode() );
em.setProperty( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.REFRESH );
assertEquals( CacheStoreMode.REFRESH, em.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.REFRESH, session.getCacheMode() );
}
@Test
public void testQueryCacheModes() {
EntityManager em = getOrCreateEntityManager();
org.hibernate.query.Query query = em.createQuery( "from SimpleEntity" ).unwrap( org.hibernate.query.Query.class );
query.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.USE );
assertEquals( CacheStoreMode.USE, query.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.NORMAL, query.getCacheMode() );
query.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.BYPASS );
assertEquals( CacheStoreMode.BYPASS, query.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.GET, query.getCacheMode() );
query.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.REFRESH );
assertEquals( CacheStoreMode.REFRESH, query.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.REFRESH, query.getCacheMode() );
query.setHint( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE, CacheRetrieveMode.BYPASS );
assertEquals( CacheRetrieveMode.BYPASS, query.getHints().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheStoreMode.REFRESH, query.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.REFRESH, query.getCacheMode() );
query.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.BYPASS );
assertEquals( CacheRetrieveMode.BYPASS, query.getHints().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheStoreMode.BYPASS, query.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.IGNORE, query.getCacheMode() );
query.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.USE );
assertEquals( CacheRetrieveMode.BYPASS, query.getHints().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheStoreMode.USE, query.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.PUT, query.getCacheMode() );
}
}

View File

@ -1,65 +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.jpa.test.callbacks;
import java.util.Date;
import java.util.Map;
import javax.persistence.EntityManager;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.jpa.test.Cat;
import org.hibernate.jpa.test.Kitten;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Sanne Grinovero
*/
@SuppressWarnings("unchecked")
public class CallbacksDisabledTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testCallbacksAreDisabled() throws Exception {
EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
c.setName( "Kitty" );
c.setDateOfBirth( new Date( 90, 11, 15 ) );
em.getTransaction().begin();
em.persist( c );
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
c = em.find( Cat.class, c.getId() );
assertTrue( c.getAge() == 0 ); // With listeners enabled this would be false. Proven by org.hibernate.jpa.test.callbacks.CallbacksTest.testCallbackMethod
em.getTransaction().commit();
em.close();
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Cat.class,
Translation.class,
Television.class,
RemoteControl.class,
Rythm.class,
Plant.class,
Kitten.class
};
}
@Override
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.JPA_CALLBACKS_ENABLED, "false" );
}
}

View File

@ -1,257 +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.jpa.test.callbacks;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.jpa.test.Cat;
import org.hibernate.jpa.test.Kitten;
import org.hibernate.testing.FailureExpected;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Emmanuel Bernard
*/
@SuppressWarnings("unchecked")
public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testCallbackMethod() throws Exception {
EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
c.setName( "Kitty" );
c.setDateOfBirth( new Date( 90, 11, 15 ) );
em.getTransaction().begin();
em.persist( c );
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
c = em.find( Cat.class, c.getId() );
assertFalse( c.getAge() == 0 );
c.setName( "Tomcat" ); //update this entity
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
c = em.find( Cat.class, c.getId() );
assertEquals( "Tomcat", c.getName() );
em.getTransaction().commit();
em.close();
}
@Test
public void testEntityListener() throws Exception {
EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
c.setName( "Kitty" );
c.setLength( 12 );
c.setDateOfBirth( new Date( 90, 11, 15 ) );
em.getTransaction().begin();
int previousVersion = c.getManualVersion();
em.persist( c );
em.getTransaction().commit();
em.getTransaction().begin();
c = em.find( Cat.class, c.getId() );
assertNotNull( c.getLastUpdate() );
assertTrue( previousVersion < c.getManualVersion() );
assertEquals( 12, c.getLength() );
previousVersion = c.getManualVersion();
c.setName( "new name" );
em.getTransaction().commit();
em.getTransaction().begin();
c = em.find( Cat.class, c.getId() );
assertTrue( previousVersion < c.getManualVersion() );
em.getTransaction().commit();
em.close();
}
@Test
public void testPostPersist() throws Exception {
EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
em.getTransaction().begin();
c.setLength( 23 );
c.setAge( 2 );
c.setName( "Beetle" );
c.setDateOfBirth( new Date() );
em.persist( c );
em.getTransaction().commit();
em.close();
List ids = Cat.getIdList();
Object id = Cat.getIdList().get( ids.size() - 1 );
assertNotNull( id );
}
//Not a test since the spec did not make the proper change on listeners
public void listenerAnnotation() throws Exception {
EntityManager em = getOrCreateEntityManager();
Translation tl = new Translation();
em.getTransaction().begin();
tl.setInto( "France" );
em.persist( tl );
tl = new Translation();
tl.setInto( "Bimboland" );
try {
em.persist( tl );
em.flush();
fail( "Annotations annotated by a listener not used" );
}
catch (IllegalArgumentException e) {
//success
}
finally {
em.getTransaction().rollback();
em.close();
}
}
@Test
public void testPrePersistOnCascade() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Television tv = new Television();
RemoteControl rc = new RemoteControl();
em.persist( tv );
em.flush();
tv.setControl( rc );
tv.init();
em.flush();
assertNotNull( rc.getCreationDate() );
em.getTransaction().rollback();
em.close();
}
@Test
public void testCallBackListenersHierarchy() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Television tv = new Television();
em.persist( tv );
tv.setName( "Myaio" );
tv.init();
em.flush();
assertEquals( 1, tv.counter );
em.getTransaction().rollback();
em.close();
assertEquals( 5, tv.communication );
assertTrue( tv.isLast );
}
@Test
public void testException() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Rythm r = new Rythm();
try {
em.persist( r );
em.flush();
fail("should have raised an ArythmeticException:");
}
catch (ArithmeticException e) {
//success
}
catch( Exception e ) {
fail("should have raised an ArythmeticException:" + e.getClass() );
}
em.getTransaction().rollback();
em.close();
}
@Test
public void testIdNullSetByPrePersist() throws Exception {
Plant plant = new Plant();
plant.setName( "Origuna plantula gigantic" );
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( plant );
em.flush();
em.getTransaction().rollback();
em.close();
}
@Test
@FailureExpected(message = "collection change does not trigger an event", jiraKey = "EJB-288")
public void testPostUpdateCollection() throws Exception {
// create a cat
EntityManager em = getOrCreateEntityManager();
Cat cat = new Cat();
em.getTransaction().begin();
cat.setLength( 23 );
cat.setAge( 2 );
cat.setName( "Beetle" );
cat.setDateOfBirth( new Date() );
em.persist( cat );
em.getTransaction().commit();
// assert it is persisted
List ids = Cat.getIdList();
Object id = Cat.getIdList().get( ids.size() - 1 );
assertNotNull( id );
// add a kitten to the cat - triggers PostCollectionRecreateEvent
int postVersion = Cat.postVersion;
em.getTransaction().begin();
Kitten kitty = new Kitten();
kitty.setName("kitty");
List kittens = new ArrayList<Kitten>();
kittens.add(kitty);
cat.setKittens(kittens);
em.getTransaction().commit();
assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
// add another kitten - triggers PostCollectionUpdateEvent.
postVersion = Cat.postVersion;
em.getTransaction().begin();
Kitten tom = new Kitten();
tom.setName("Tom");
cat.getKittens().add(tom);
em.getTransaction().commit();
assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
// delete a kitty - triggers PostCollectionUpdateEvent
postVersion = Cat.postVersion;
em.getTransaction().begin();
cat.getKittens().remove(tom);
em.getTransaction().commit();
assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
// delete and recreate kittens - triggers PostCollectionRemoveEvent and PostCollectionRecreateEvent)
postVersion = Cat.postVersion;
em.getTransaction().begin();
cat.setKittens(new ArrayList<Kitten>());
em.getTransaction().commit();
assertEquals("Post version should have been incremented.", postVersion + 2, Cat.postVersion);
em.close();
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Cat.class,
Translation.class,
Television.class,
RemoteControl.class,
Rythm.class,
Plant.class,
Kitten.class
};
}
}

View File

@ -1,56 +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.jpa.test.callbacks.hbmxml;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
/**
* @author Felix Feisst (feisst dot felix at gmail dot com)
*/
public class MappingClassMoreThanOnceTest extends BaseUnitTestCase {
/**
* Tests that an entity manager can be created when a class is mapped more than once.
*/
@Test
@TestForIssue(jiraKey = "HHH-8775")
// @FailureExpected(jiraKey = "HHH-8775")
public void testBootstrapWithClassMappedMOreThanOnce() {
Map settings = new HashMap( );
settings.put( AvailableSettings.HBXML_FILES, "org/hibernate/jpa/test/callbacks/hbmxml/ClassMappedMoreThanOnce.hbm.xml" );
final EntityManagerFactoryBuilder builder = Bootstrap.getEntityManagerFactoryBuilder(
new BaseEntityManagerFunctionalTestCase.TestingPersistenceUnitDescriptorImpl( getClass().getSimpleName() ),
settings
);
HibernateEntityManagerFactory emf = null;
try {
emf = builder.build().unwrap( HibernateEntityManagerFactory.class );
}
finally {
if ( emf != null ) {
try {
emf.close();
}
catch (Exception ignore) {
}
}
}
}
}

View File

@ -1,46 +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.jpa.test.callbacks.xml;
import javax.persistence.EntityManager;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Steve Ebersole
*/
public class EntityListenerViaXmlTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected String[] getMappings() {
return new String[] { "org/hibernate/jpa/test/callbacks/xml/MyEntity.orm.xml" };
}
@Test
@TestForIssue( jiraKey = "HHH-9771" )
public void testUsage() {
JournalingListener.reset();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( new MyEntity( 1, "steve" ) );
em.getTransaction().commit();
em.close();
assertEquals( 1, JournalingListener.getPrePersistCount() );
em = getOrCreateEntityManager();
em.getTransaction().begin();
em.createQuery( "delete MyEntity" ).executeUpdate();
em.getTransaction().commit();
em.close();
}
}

View File

@ -1,96 +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.jpa.test.cascade;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
/**
* @author Max Rydahl Andersen
*/
public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testCascade() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Teacher teacher = new Teacher();
Student student = new Student();
teacher.setFavoriteStudent(student);
student.setFavoriteTeacher(teacher);
teacher.getStudents().add(student);
student.setPrimaryTeacher(teacher);
em.persist( teacher );
em.getTransaction().commit();
em = getOrCreateEntityManager();
em.getTransaction().begin();
Teacher foundTeacher = (Teacher) em.createQuery( "select t from Teacher as t" ).getSingleResult();
System.out.println(foundTeacher);
System.out.println(foundTeacher.getFavoriteStudent());
for (Student fstudent : foundTeacher.getStudents()) {
System.out.println(fstudent);
System.out.println(fstudent.getFavoriteTeacher());
System.out.println(fstudent.getPrimaryTeacher());
}
em.getTransaction().commit(); // here *alot* of flushes occur on an object graph that has *Zero* changes.
em.close();
}
@Test
public void testNoCascadeAndMerge() throws Exception {
Song e1 = new Song();
Author e2 = new Author();
e1.setAuthor(e2);
EntityManager em = getOrCreateEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(e2);
em.persist(e1);
tx.commit();
em.close();
em = getOrCreateEntityManager();
e1 = em.find(Song.class, e1.getId());
tx = em.getTransaction();
tx.begin();
em.merge(e1);
//em.refresh(e1);
tx.commit();
em.close();
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Teacher.class,
Student.class,
Song.class,
Author.class
};
}
}

View File

@ -1,101 +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.jpa.test.cascade;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.Hibernate;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
/**
* @author Emmanuel Bernard
*/
public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testDeleteOrphan() throws Exception {
EntityTransaction tx;
EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Troop disney = new Troop();
disney.setName( "Disney" );
Soldier mickey = new Soldier();
mickey.setName( "Mickey" );
disney.addSoldier( mickey );
em.persist( disney );
tx.commit();
em.close();
em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Troop troop = em.find( Troop.class, disney.getId() );
Hibernate.initialize( troop.getSoldiers() );
tx.commit();
em.close();
Soldier soldier = troop.getSoldiers().iterator().next();
troop.getSoldiers().remove( soldier );
troop = (Troop) deserialize( serialize( troop ) );
em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
em.merge( troop );
tx.commit();
em.close();
em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
soldier = em.find( Soldier.class, mickey.getId() );
Assert.assertNull( "delete-orphan should work", soldier );
troop = em.find( Troop.class, disney.getId() );
em.remove( troop );
tx.commit();
em.close();
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Troop.class,
Soldier.class
};
}
private byte[] serialize(Object object) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream( stream );
out.writeObject( object );
out.close();
byte[] serialized = stream.toByteArray();
stream.close();
return serialized;
}
private Object deserialize(byte[] serialized) throws IOException, ClassNotFoundException {
ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
ObjectInputStream in = new ObjectInputStream( byteIn );
Object result = in.readObject();
in.close();
byteIn.close();
return result;
}
}

View File

@ -1,95 +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.jpa.test.cascade;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import static javax.persistence.CascadeType.DETACH;
import static javax.persistence.CascadeType.REMOVE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
/**
* @author Emmanuel Bernard
*/
public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testDetach() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Tooth tooth = new Tooth();
Mouth mouth = new Mouth();
em.persist( mouth );
em.persist( tooth );
tooth.mouth = mouth;
mouth.teeth = new ArrayList<Tooth>();
mouth.teeth.add( tooth );
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
mouth = em.find( Mouth.class, mouth.id );
assertNotNull( mouth );
assertEquals( 1, mouth.teeth.size() );
tooth = mouth.teeth.iterator().next();
em.detach( mouth );
assertFalse( em.contains( tooth ) );
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
em.remove( em.find( Mouth.class, mouth.id ) );
em.getTransaction().commit();
em.close();
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
Mouth.class,
Tooth.class
};
}
@Entity
@Table(name = "mouth")
public static class Mouth {
@Id
@GeneratedValue
public Integer id;
@OneToMany(mappedBy = "mouth", cascade = { DETACH, REMOVE } )
public Collection<Tooth> teeth;
}
@Entity
@Table(name = "tooth")
public static class Tooth {
@Id
@GeneratedValue
public Integer id;
public String type;
@ManyToOne
public Mouth mouth;
}
}

View File

@ -1,160 +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.jpa.test.cascade;
import java.util.ArrayList;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.hibernate.Hibernate;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Emmanuel Bernard
*/
public class FetchTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testCascadeAndFetchCollection() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop disney = new Troop();
disney.setName( "Disney" );
Soldier mickey = new Soldier();
mickey.setName( "Mickey" );
disney.addSoldier( mickey );
em.persist( disney );
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop troop = em.find( Troop.class, disney.getId() );
assertFalse( Hibernate.isInitialized( troop.getSoldiers() ) );
em.getTransaction().commit();
assertFalse( Hibernate.isInitialized( troop.getSoldiers() ) );
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
troop = em.find( Troop.class, disney.getId() );
em.remove( troop );
//Fail because of HHH-1187
em.getTransaction().commit();
em.close();
}
@Test
public void testCascadeAndFetchEntity() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop disney = new Troop();
disney.setName( "Disney" );
Soldier mickey = new Soldier();
mickey.setName( "Mickey" );
disney.addSoldier( mickey );
em.persist( disney );
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
Soldier soldier = em.find( Soldier.class, mickey.getId() );
assertFalse( Hibernate.isInitialized( soldier.getTroop() ) );
em.getTransaction().commit();
assertFalse( Hibernate.isInitialized( soldier.getTroop() ) );
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop troop = em.find( Troop.class, disney.getId() );
em.remove( troop );
//Fail because of HHH-1187
em.getTransaction().commit();
em.close();
}
@Test
public void testTwoLevelDeepPersist() throws Exception {
EntityTransaction tx;
EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Conference jbwBarcelona = new Conference();
jbwBarcelona.setDate( new Date() );
ExtractionDocumentInfo info = new ExtractionDocumentInfo();
info.setConference( jbwBarcelona );
jbwBarcelona.setExtractionDocument( info );
info.setLastModified( new Date() );
ExtractionDocument doc = new ExtractionDocument();
doc.setDocumentInfo( info );
info.setDocuments( new ArrayList<ExtractionDocument>() );
info.getDocuments().add( doc );
doc.setBody( new byte[]{'c', 'f'} );
em.persist( jbwBarcelona );
tx.commit();
em.close();
em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
jbwBarcelona = em.find( Conference.class, jbwBarcelona.getId() );
assertTrue( Hibernate.isInitialized( jbwBarcelona ) );
assertTrue( Hibernate.isInitialized( jbwBarcelona.getExtractionDocument() ) );
assertFalse( Hibernate.isInitialized( jbwBarcelona.getExtractionDocument().getDocuments() ) );
em.flush();
assertTrue( Hibernate.isInitialized( jbwBarcelona ) );
assertTrue( Hibernate.isInitialized( jbwBarcelona.getExtractionDocument() ) );
assertFalse( Hibernate.isInitialized( jbwBarcelona.getExtractionDocument().getDocuments() ) );
em.remove( jbwBarcelona );
tx.commit();
em.close();
}
@Test
public void testTwoLevelDeepPersistOnManyToOne() throws Exception {
EntityTransaction tx;
EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Grandson gs = new Grandson();
gs.setParent( new Son() );
gs.getParent().setParent( new Parent() );
em.persist( gs );
tx.commit();
em.close();
em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
gs = em.find( Grandson.class, gs.getId() );
em.flush();
assertTrue( Hibernate.isInitialized( gs.getParent() ) );
assertFalse( Hibernate.isInitialized( gs.getParent().getParent() ) );
em.remove( gs );
tx.commit();
em.close();
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Troop.class,
Soldier.class,
Conference.class,
ExtractionDocument.class,
ExtractionDocumentInfo.class,
Parent.class,
Son.class,
Grandson.class
};
}
}

View File

@ -1,77 +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.jpa.test.cascade;
import javax.persistence.EntityManager;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import static org.junit.Assert.fail;
public class FetchTest2 extends BaseEntityManagerFunctionalTestCase {
@Test
public void testProxyTransientStuff() throws Exception {
EntityManager em = entityManagerFactory().createEntityManager();
em.getTransaction().begin();
Troop2 disney = new Troop2();
disney.setName( "Disney" );
Soldier2 mickey = new Soldier2();
mickey.setName( "Mickey" );
mickey.setTroop( disney );
em.persist( disney );
em.persist( mickey );
em.getTransaction().commit();
em.close();
em = entityManagerFactory().createEntityManager();
em.getTransaction().begin();
Soldier2 soldier = em.find( Soldier2.class, mickey.getId() );
soldier.getTroop().getId();
try {
em.flush();
}
catch (IllegalStateException e) {
fail( "Should not raise an exception" );
}
em.getTransaction().commit();
em.close();
em = entityManagerFactory().createEntityManager();
em.getTransaction().begin();
//load troop wo a proxy
disney = em.find( Troop2.class, disney.getId() );
soldier = em.find( Soldier2.class, mickey.getId() );
try {
em.flush();
}
catch (IllegalStateException e) {
fail( "Should not raise an exception" );
}
em.remove( soldier );
em.remove( disney );
em.getTransaction().commit();
em.close();
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Troop2.class,
Soldier2.class
};
}
}

View File

@ -1,131 +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.jpa.test.cascade;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import static org.junit.Assert.assertEquals;
public class MergeTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testMergeDetachedEntityWithNewOneToManyElements() {
Order order = new Order();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( order );
em.getTransaction().commit();
em.close();
Item item1 = new Item();
item1.name = "i1";
Item item2 = new Item();
item2.name = "i2";
order.addItem( item1 );
order.addItem( item2 );
em = getOrCreateEntityManager();
em.getTransaction().begin();
order = em.merge( order );
em.flush();
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
order = em.find( Order.class, order.id );
assertEquals( 2, order.items.size() );
em.remove( order );
em.getTransaction().commit();
em.close();
}
@Test
public void testMergeLoadedEntityWithNewOneToManyElements() {
Order order = new Order();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( order );
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
order = em.find( Order.class, order.id );
Item item1 = new Item();
item1.name = "i1";
Item item2 = new Item();
item2.name = "i2";
order.addItem( item1 );
order.addItem( item2 );
order = em.merge( order );
em.flush();
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
order = em.find( Order.class, order.id );
assertEquals( 2, order.items.size() );
em.remove( order );
em.getTransaction().commit();
em.close();
}
protected Class[] getAnnotatedClasses() {
return new Class[] {
Order.class,
Item.class
};
}
@Entity
private static class Order {
@Id
@GeneratedValue
private Long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "order", orphanRemoval = true)
private List<Item> items = new ArrayList<Item>();
public Order() {
}
public void addItem(Item item) {
items.add( item );
item.order = this;
}
}
@Entity
private static class Item {
@Id
@GeneratedValue
private Long id;
private String name;
@ManyToOne
private Order order;
}
}

View File

@ -1,86 +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.jpa.test.cascade;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.fail;
/**
* @author Steve Ebersole
*/
public class MergeWithTransientNonCascadedAssociationTest extends BaseEntityManagerFunctionalTestCase {
@Override
public Class[] getAnnotatedClasses() {
return new Class[] { Person.class, Address.class };
}
@Test
public void testMergeWithTransientNonCascadedAssociation() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Person person = new Person();
em.persist( person );
em.getTransaction().commit();
em.close();
person.address = new Address();
em = getOrCreateEntityManager();
em.getTransaction().begin();
em.merge( person );
try {
em.flush();
fail( "Expecting IllegalStateException" );
}
catch (IllegalStateException ise) {
// expected...
em.getTransaction().rollback();
}
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
person.address = null;
em.unwrap( Session.class ).lock( person, LockMode.NONE );
em.unwrap( Session.class ).delete( person );
em.getTransaction().commit();
em.close();
}
@Entity( name = "Person" )
public static class Person {
@Id
@GeneratedValue( generator = "increment" )
@GenericGenerator( name = "increment", strategy = "increment" )
private Integer id;
@ManyToOne
private Address address;
public Person() {
}
}
@Entity( name = "Address" )
public static class Address {
@Id
@GeneratedValue( generator = "increment_1" )
@GenericGenerator( name = "increment_1", strategy = "increment" )
private Integer id;
}
}

View File

@ -1,317 +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.jpa.test.cascade.multicircle;
import javax.persistence.EntityManager;
import javax.persistence.RollbackException;
import org.hibernate.TransientPropertyValueException;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import junit.framework.Assert;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* This test uses a complicated model that requires Hibernate to delay
* inserts until non-nullable transient entity dependencies are resolved.
*
* All IDs are generated from a sequence.
*
* JPA cascade types are used (javax.persistence.CascadeType)..
*
* This test uses the following model:
*
* <code>
* ------------------------------ N G
* |
* | 1
* | |
* | |
* | N
* |
* | E N--------------0,1 * F
* |
* | 1 N
* | | |
* | | |
* 1 N |
* * |
* B * N---1 D * 1------------------
* *
* N N
* | |
* | |
* 1 |
* |
* C * 1-----
*</code>
*
* In the diagram, all associations are bidirectional;
* assocations marked with '*' cascade persist, save, merge operations to the
* associated entities (e.g., B cascades persist to D, but D does not cascade
* persist to B);
*
* b, c, d, e, f, and g are all transient unsaved that are associated with each other.
*
* When saving b, the entities are added to the ActionQueue in the following order:
* c, d (depends on e), f (depends on d, g), e, b, g.
*
* Entities are inserted in the following order:
* c, e, d, b, g, f.
*/
public class MultiCircleJpaCascadeTest extends BaseEntityManagerFunctionalTestCase {
private B b;
private C c;
private D d;
private E e;
private F f;
private G g;
private boolean skipCleanup;
@Before
public void setup() {
b = new B();
c = new C();
d = new D();
e = new E();
f = new F();
g = new G();
b.getGCollection().add( g );
b.setC( c );
b.setD( d );
c.getBCollection().add( b );
c.getDCollection().add( d );
d.getBCollection().add( b );
d.setC( c );
d.setE( e );
d.getFCollection().add( f );
e.getDCollection().add( d );
e.setF( f );
f.getECollection().add( e );
f.setD( d );
f.setG( g );
g.setB( b );
g.getFCollection().add( f );
skipCleanup = false;
}
@After
public void cleanup() {
if ( ! skipCleanup ) {
b.setC( null );
b.setD( null );
b.getGCollection().remove( g );
c.getBCollection().remove( b );
c.getDCollection().remove( d );
d.getBCollection().remove( b );
d.setC( null );
d.setE( null );
d.getFCollection().remove( f );
e.getDCollection().remove( d );
e.setF( null );
f.setD( null );
f.getECollection().remove( e );
f.setG( null );
g.setB( null );
g.getFCollection().remove( f );
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
b = em.merge( b );
c = em.merge( c );
d = em.merge( d );
e = em.merge( e );
f = em.merge( f );
g = em.merge( g );
em.remove( f );
em.remove( g );
em.remove( b );
em.remove( d );
em.remove( e );
em.remove( c );
em.getTransaction().commit();
em.close();
}
}
@Test
public void testPersist() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( b );
em.getTransaction().commit();
em.close();
check();
}
@Test
public void testPersistNoCascadeToTransient() {
skipCleanup = true;
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
em.persist( c );
fail( "should have failed." );
}
catch( IllegalStateException ex ) {
assertTrue( TransientPropertyValueException.class.isInstance( ex.getCause() ) );
TransientPropertyValueException pve = (TransientPropertyValueException) ex.getCause();
assertEquals( G.class.getName(), pve.getTransientEntityName() );
assertEquals( F.class.getName(), pve.getPropertyOwnerEntityName() );
assertEquals( "g", pve.getPropertyName() );
}
em.getTransaction().rollback();
em.close();
}
@Test
@FailureExpected( jiraKey = "HHH-6999" )
// fails on d.e; should pass
public void testPersistThenUpdate() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( b );
// remove old e from associations
e.getDCollection().remove( d );
d.setE( null );
f.getECollection().remove( e );
e.setF( null );
// add new e to associations
e = new E();
e.getDCollection().add( d );
f.getECollection().add( e );
d.setE( e );
e.setF( f );
em.getTransaction().commit();
em.close();
check();
}
@Test
public void testPersistThenUpdateNoCascadeToTransient() {
// expected to fail, so nothing will be persisted.
skipCleanup = true;
// remove elements from collections and persist
c.getBCollection().clear();
c.getDCollection().clear();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( c );
// now add the elements back
c.getBCollection().add( b );
c.getDCollection().add( d );
try {
em.getTransaction().commit();
fail( "should have thrown IllegalStateException");
}
catch ( RollbackException ex ) {
assertTrue( ex.getCause() instanceof IllegalStateException );
IllegalStateException ise = ( IllegalStateException ) ex.getCause();
// should fail on entity g (due to no cascade to f.g);
// instead it fails on entity e ( due to no cascade to d.e)
// because e is not in the process of being saved yet.
// when HHH-6999 is fixed, this test should be changed to
// check for g and f.g
//noinspection ThrowableResultOfMethodCallIgnored
TransientPropertyValueException tpve = assertTyping( TransientPropertyValueException.class, ise.getCause() );
assertEquals( E.class.getName(), tpve.getTransientEntityName() );
assertEquals( D.class.getName(), tpve.getPropertyOwnerEntityName() );
assertEquals( "e", tpve.getPropertyName() );
}
em.close();
}
@Test
public void testMerge() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
b = em.merge( b );
c = b.getC();
d = b.getD();
e = d.getE();
f = e.getF();
g = f.getG();
em.getTransaction().commit();
em.close();
check();
}
private void check() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
B bRead = em.find( B.class, b.getId() );
Assert.assertEquals( b, bRead );
G gRead = bRead.getGCollection().iterator().next();
Assert.assertEquals( g, gRead );
C cRead = bRead.getC();
Assert.assertEquals( c, cRead );
D dRead = bRead.getD();
Assert.assertEquals( d, dRead );
Assert.assertSame( bRead, cRead.getBCollection().iterator().next() );
Assert.assertSame( dRead, cRead.getDCollection().iterator().next() );
Assert.assertSame( bRead, dRead.getBCollection().iterator().next() );
Assert.assertEquals( cRead, dRead.getC() );
E eRead = dRead.getE();
Assert.assertEquals( e, eRead );
F fRead = dRead.getFCollection().iterator().next();
Assert.assertEquals( f, fRead );
Assert.assertSame( dRead, eRead.getDCollection().iterator().next() );
Assert.assertSame( fRead, eRead.getF() );
Assert.assertSame( eRead, fRead.getECollection().iterator().next() );
Assert.assertSame( dRead, fRead.getD() );
Assert.assertSame( gRead, fRead.getG());
Assert.assertSame( bRead, gRead.getB() );
Assert.assertSame( fRead, gRead.getFCollection().iterator().next() );
em.getTransaction().commit();
em.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
B.class,
C.class,
D.class,
E.class,
F.class,
G.class
};
}
}

View File

@ -1,70 +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.jpa.test.cascade.multilevel;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.transaction.TransactionUtil;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
public class MultiLevelCascadeTest extends BaseEntityManagerFunctionalTestCase {
@TestForIssue( jiraKey = "HHH-5299" )
@Test
public void test() {
final Top top = new Top();
;
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.persist( top );
// Flush 1
entityManager.flush();
Middle middle = new Middle( 1l );
top.addMiddle( middle );
middle.setTop( top );
Bottom bottom = new Bottom();
middle.setBottom( bottom );
bottom.setMiddle( middle );
Middle middle2 = new Middle( 2l );
top.addMiddle( middle2 );
middle2.setTop( top );
Bottom bottom2 = new Bottom();
middle2.setBottom( bottom2 );
bottom2.setMiddle( middle2 );
// Flush 2
entityManager.flush();
} );
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
Top finded = entityManager.find( Top.class, top.getId() );
assertEquals( 2, finded.getMiddles().size() );
for ( Middle loadedMiddle : finded.getMiddles() ) {
assertSame( finded, loadedMiddle.getTop() );
assertNotNull( loadedMiddle.getBottom() );
}
entityManager.remove( finded );
} );
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] { Top.class, Middle.class, Bottom.class };
}
}

View File

@ -26,9 +26,9 @@ import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.jpa.test.callbacks.RemoteControl;
import org.hibernate.jpa.test.callbacks.Television;
import org.hibernate.jpa.test.callbacks.VideoSystem;
import org.hibernate.orm.test.jpa.callbacks.RemoteControl;
import org.hibernate.orm.test.jpa.callbacks.Television;
import org.hibernate.orm.test.jpa.callbacks.VideoSystem;
import org.hibernate.jpa.test.inheritance.Fruit;
import org.hibernate.jpa.test.inheritance.Strawberry;
import org.hibernate.jpa.test.metamodel.Address;

View File

@ -0,0 +1,97 @@
/*
* 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.beanvalidation;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import javax.persistence.RollbackException;
import javax.validation.ConstraintViolationException;
import java.math.BigDecimal;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Emmanuel Bernard
*/
@Jpa(
annotatedClasses = { CupHolder.class },
integrationSettings = { @Setting(name = AvailableSettings.JPA_VALIDATION_MODE, value = "auto") }
)
public class BeanValidationTest {
@Test
public void testBeanValidationIntegrationOnFlush(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
CupHolder ch = new CupHolder();
ch.setRadius( new BigDecimal( "12" ) );
ch.setTitle( "foo" );
entityManager.getTransaction().begin();
try {
entityManager.persist(ch);
entityManager.flush();
fail( "invalid object should not be persisted" );
}
catch (ConstraintViolationException e) {
assertEquals( 1, e.getConstraintViolations().size() );
}
assertTrue(
entityManager.getTransaction().getRollbackOnly(),
"A constraint violation exception should mark the transaction for rollback"
);
entityManager.getTransaction().rollback();
entityManager.clear();
}
);
}
@Test
public void testBeanValidationIntegrationOnCommit(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
CupHolder ch = new CupHolder();
ch.setRadius(new BigDecimal("9"));
ch.setTitle("foo");
entityManager.getTransaction().begin();
entityManager.persist(ch);
entityManager.flush();
try {
ch.setRadius(new BigDecimal("12"));
entityManager.getTransaction().commit();
fail("invalid object should not be persisted");
}
catch (RollbackException e) {
final Throwable cve = e.getCause();
assertTrue(cve instanceof ConstraintViolationException);
assertEquals(1, ((ConstraintViolationException) cve).getConstraintViolations().size());
}
entityManager.close();
}
);
}
@Test
@RequiresDialect(H2Dialect.class)
public void testTitleColumnHasExpectedLength(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
int len = (Integer) entityManager.createNativeQuery(
"select CHARACTER_MAXIMUM_LENGTH from INFORMATION_SCHEMA.COLUMNS c where c.TABLE_NAME = 'CUPHOLDER' and c.COLUMN_NAME = 'TITLE'"
).getSingleResult();
assertEquals(64, len);
}
);
}
}

View File

@ -4,7 +4,7 @@
* 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.beanvalidation;
package org.hibernate.orm.test.jpa.beanvalidation;
import java.math.BigDecimal;
import javax.persistence.Entity;

View File

@ -4,7 +4,7 @@
* 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.beanvalidation;
package org.hibernate.orm.test.jpa.beanvalidation;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

View File

@ -4,7 +4,7 @@
* 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.beanvalidation;
package org.hibernate.orm.test.jpa.beanvalidation;
import java.net.URL;
import java.util.Collections;
@ -13,7 +13,7 @@ import javax.persistence.EntityManagerFactory;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
@ -24,7 +24,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertSame;
/**
* Test injection of ValidatorFactory using WF/Hibernate 2-phase boot process
@ -62,7 +62,7 @@ public class ValidatorFactory2PhaseInjectionTest extends BaseUnitTestCase {
EntityManagerFactory emf = emfb.build();
try {
assertSame( vf, emf.getProperties().get( AvailableSettings.VALIDATION_FACTORY ) );
assertSame( vf, emf.getProperties().get( AvailableSettings.JPA_VALIDATION_FACTORY ) );
}
finally {
emf.close();

View File

@ -4,10 +4,8 @@
* 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.boot;
package org.hibernate.orm.test.jpa.boot;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
@ -19,10 +17,9 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.service.spi.ServiceException;
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
import org.junit.Test;
/**
@ -32,7 +29,7 @@ import org.junit.Test;
* @author Andrea Boriero
* @author Sanne Grinovero
*/
public class BootFailureTest extends BaseEntityManagerFunctionalTestCase {
public class BootFailureTest {
@Test(expected = ServiceException.class)
public void exceptionOnIllegalPUTest() {
@ -57,7 +54,8 @@ public class BootFailureTest extends BaseEntityManagerFunctionalTestCase {
}
private static class TestClassLoader extends ClassLoader {
static final List<URL> urls = Arrays.asList( ConfigHelper.findAsResource( "org/hibernate/jpa/test/bootstrap/META-INF/persistence.xml" ) );
static final List<URL> urls = Arrays.asList( ClassLoaderServiceTestingImpl.INSTANCE.locateResource(
"org/hibernate/orm/test/jpa/boot/META-INF/persistence.xml" ) );
@Override
protected Enumeration<URL> findResources(String name) {
@ -66,6 +64,5 @@ public class BootFailureTest extends BaseEntityManagerFunctionalTestCase {
Collections.emptyEnumeration();
}
}
}

View File

@ -4,7 +4,7 @@
* 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.boot;
package org.hibernate.orm.test.jpa.boot;
import org.hibernate.internal.HEMLogging;
@ -17,8 +17,8 @@ import org.junit.Rule;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests that deprecated (and removed) provider, "org.hibernate.ejb.HibernatePersistence",

View File

@ -4,7 +4,7 @@
* 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.boot;
package org.hibernate.orm.test.jpa.boot;
import javax.persistence.EntityManagerFactory;
import java.net.URL;

View File

@ -4,7 +4,7 @@
* 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.annotation;
package org.hibernate.orm.test.jpa.cacheable.annotation;
import java.util.Arrays;
import java.util.HashMap;
@ -15,7 +15,7 @@ import javax.persistence.SharedCacheMode;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.Environment;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.test.PersistenceUnitInfoAdapter;
@ -30,8 +30,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* this is hacky transient step until EMF building is integrated with metamodel
*
* @author Steve Ebersole
*/
public class ConfigurationTest extends BaseUnitTestCase {
@ -117,7 +115,7 @@ public class ConfigurationTest extends BaseUnitTestCase {
@SuppressWarnings("unchecked")
private MetadataImplementor buildMetadata(SharedCacheMode mode) {
Map settings = new HashMap();
settings.put( AvailableSettings.SHARED_CACHE_MODE, mode );
settings.put( AvailableSettings.JPA_SHARED_CACHE_MODE, mode );
settings.put( Environment.CACHE_REGION_FACTORY, CustomRegionFactory.class.getName() );
settings.put(
AvailableSettings.LOADED_CLASSES,

View File

@ -4,7 +4,7 @@
* 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.annotation;
package org.hibernate.orm.test.jpa.cacheable.annotation;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -4,7 +4,7 @@
* 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.annotation;
package org.hibernate.orm.test.jpa.cacheable.annotation;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -4,7 +4,7 @@
* 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.annotation;
package org.hibernate.orm.test.jpa.cacheable.annotation;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -0,0 +1,111 @@
/*
* 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.junit.jupiter.api.Test;
import org.hibernate.testing.cache.CachingRegionFactory;
import org.hibernate.testing.orm.junit.NotImplementedYet;
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

@ -4,7 +4,7 @@
* 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;
package org.hibernate.orm.test.jpa.cacheable.api;
import javax.persistence.Cacheable;
import javax.persistence.Entity;

View File

@ -0,0 +1,100 @@
/*
* 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.cachemodes;
import javax.persistence.CacheRetrieveMode;
import javax.persistence.CacheStoreMode;
import org.hibernate.CacheMode;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.junit.DomainModel;
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;
/**
* @author Steve Ebersole
*/
@DomainModel(
annotatedClasses = { SimpleEntity.class }
)
@SessionFactory
public class SharedCacheModesTest {
@Test
public void testEntityManagerCacheModes(SessionFactoryScope scope) {
scope.inSession(
session -> {
// defaults...
assertEquals( CacheStoreMode.USE, session.getProperties().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheRetrieveMode.USE, session.getProperties().get( AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheMode.NORMAL, session.getCacheMode() );
// overrides...
session.setProperty( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.REFRESH );
assertEquals( CacheStoreMode.REFRESH, session.getProperties().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.REFRESH, session.getCacheMode() );
session.setProperty( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.BYPASS );
assertEquals( CacheStoreMode.BYPASS, session.getProperties().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.GET, session.getCacheMode() );
session.setProperty( AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE, CacheRetrieveMode.BYPASS );
assertEquals(CacheRetrieveMode.BYPASS, session.getProperties().get( AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheMode.IGNORE, session.getCacheMode() );
session.setProperty( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.USE );
assertEquals( CacheStoreMode.USE, session.getProperties().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.PUT, session.getCacheMode() );
session.setProperty( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.REFRESH );
assertEquals( CacheStoreMode.REFRESH, session.getProperties().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.REFRESH, session.getCacheMode() );
}
);
}
@Test
public void testQueryCacheModes(SessionFactoryScope scope) {
scope.inSession(
session -> {
org.hibernate.query.Query query = session.createQuery( "from SimpleEntity" );
query.setHint( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.USE );
assertEquals( CacheStoreMode.USE, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.NORMAL, query.getCacheMode() );
query.setHint( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.BYPASS );
assertEquals( CacheStoreMode.BYPASS, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.GET, query.getCacheMode() );
query.setHint( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.REFRESH );
assertEquals( CacheStoreMode.REFRESH, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.REFRESH, query.getCacheMode() );
query.setHint( AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE, CacheRetrieveMode.BYPASS );
assertEquals( CacheRetrieveMode.BYPASS, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheStoreMode.REFRESH, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.REFRESH, query.getCacheMode() );
query.setHint( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.BYPASS );
assertEquals( CacheRetrieveMode.BYPASS, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheStoreMode.BYPASS, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.IGNORE, query.getCacheMode() );
query.setHint( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, CacheStoreMode.USE );
assertEquals( CacheRetrieveMode.BYPASS, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE ) );
assertEquals( CacheStoreMode.USE, query.getHints().get( AvailableSettings.JPA_SHARED_CACHE_STORE_MODE ) );
assertEquals( CacheMode.PUT, query.getCacheMode() );
}
);
}
}

View File

@ -4,7 +4,7 @@
* 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.cachemodes;
package org.hibernate.orm.test.jpa.cacheable.cachemodes;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -0,0 +1,68 @@
/*
* 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.callbacks;
import java.util.Date;
import java.util.function.Function;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jpa.test.Cat;
import org.hibernate.jpa.test.Kitten;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Sanne Grinovero
*/
@SuppressWarnings("unchecked")
@ServiceRegistry(
settings = {
@Setting(name = AvailableSettings.JPA_CALLBACKS_ENABLED, value = "false"),
}
)
@DomainModel(
annotatedClasses = {
Cat.class,
Kitten.class,
Plant.class,
Television.class,
RemoteControl.class,
Translation.class,
Rythm.class
}
)
@SessionFactory
public class CallbacksDisabledTest {
@Test
public void testCallbacksAreDisabled(SessionFactoryScope scope) throws Exception {
int id = scope.fromTransaction(
session -> {
Cat c = new Cat();
c.setName( "Kitty" );
c.setDateOfBirth( new Date( 90, 11, 15 ) );
session.persist( c );
return c.getId();
}
);
scope.inTransaction(
session -> {
Cat _c = session.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
}
);
}
}

View File

@ -0,0 +1,290 @@
/*
* 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.callbacks;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.hibernate.jpa.test.Cat;
import org.hibernate.jpa.test.Kitten;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Emmanuel Bernard
*/
@SuppressWarnings("unchecked")
@DomainModel(annotatedClasses = {
Cat.class,
Kitten.class,
Plant.class,
Television.class,
RemoteControl.class,
Rythm.class
})
@SessionFactory
public class CallbacksTest {
@Test
public void testCallbackMethod(SessionFactoryScope scope) {
int id = scope.fromTransaction(
session -> {
Cat c = new Cat();
c.setName( "Kitty" );
c.setDateOfBirth( new Date( 90, 11, 15 ) );
session.persist( c );
return c.getId();
}
);
scope.inTransaction(
session -> {
Cat _c = session.find( Cat.class, id );
assertFalse( _c.getAge() == 0 );
_c.setName( "Tomcat" ); //update this entity
}
);
scope.inTransaction(
session -> {
Cat _c = session.find( Cat.class, id );
assertEquals( "Tomcat", _c.getName() );
}
);
}
@Test
public void testEntityListener(SessionFactoryScope scope) {
final class PV {
PV(int version) {
this.version = version;
}
private int version;
private void set(int version) {
this.version = version;
}
private int get() {
return version;
}
}
Cat c = new Cat();
c.setName( "Kitty" );
c.setLength( 12 );
c.setDateOfBirth( new Date( 90, 11, 15 ) );
PV previousVersion = new PV( c.getManualVersion() );
scope.inTransaction(
session -> session.persist( c )
);
scope.inTransaction(
session -> {
Cat _c = session.find( Cat.class, c.getId() );
assertNotNull( _c.getLastUpdate() );
assertTrue( previousVersion.get() < _c.getManualVersion() );
assertEquals( 12, _c.getLength() );
previousVersion.set( _c.getManualVersion() );
_c.setName( "new name" );
}
);
scope.inTransaction(
session -> {
Cat _c = session.find( Cat.class, c.getId() );
assertTrue( previousVersion.get() < _c.getManualVersion() );
}
);
}
@Test
public void testPostPersist(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Cat c = new Cat();
c.setLength( 23 );
c.setAge( 2 );
c.setName( "Beetle" );
c.setDateOfBirth( new Date() );
session.persist( c );
}
);
List ids = Cat.getIdList();
Object id = Cat.getIdList().get( ids.size() - 1 );
assertNotNull( id );
}
//Not a test since the spec did not make the proper change on listeners
public void listenerAnnotation(SessionFactoryScope scope) {
scope.inSession(
session -> {
Translation tl = new Translation();
session.getTransaction().begin();
tl.setInto( "France" );
session.persist( tl );
tl = new Translation();
tl.setInto( "Bimboland" );
try {
session.persist( tl );
session.flush();
fail( "Annotations annotated by a listener not used" );
}
catch (IllegalArgumentException e) {
//success
}
finally {
session.getTransaction().rollback();
session.close();
}
}
);
}
@Test
public void testPrePersistOnCascade(SessionFactoryScope scope) {
scope.inSession(
session -> {
session.getTransaction().begin();
Television tv = new Television();
RemoteControl rc = new RemoteControl();
session.persist( tv );
session.flush();
tv.setControl( rc );
tv.init();
session.flush();
assertNotNull( rc.getCreationDate() );
session.getTransaction().rollback();
session.close();
}
);
}
@Test
public void testCallBackListenersHierarchy(SessionFactoryScope scope) {
scope.inSession(
session -> {
session.getTransaction().begin();
Television tv = new Television();
session.persist( tv );
tv.setName( "Myaio" );
tv.init();
session.flush();
assertEquals( 1, tv.counter );
session.getTransaction().rollback();
session.close();
assertEquals( 5, tv.communication );
assertTrue( tv.isLast );
}
);
}
@Test
public void testException(SessionFactoryScope scope) {
scope.inSession(
session -> {
session.getTransaction().begin();
Rythm r = new Rythm();
try {
session.persist( r );
session.flush();
fail( "should have raised an ArythmeticException:" );
}
catch (ArithmeticException e) {
//success
}
catch (Exception e) {
fail( "should have raised an ArythmeticException:" + e.getClass() );
}
session.getTransaction().rollback();
session.close();
}
);
}
@Test
public void testIdNullSetByPrePersist(SessionFactoryScope scope) {
scope.inSession(
session -> {
Plant plant = new Plant();
plant.setName( "Origuna plantula gigantic" );
session.getTransaction().begin();
session.persist( plant );
session.flush();
session.getTransaction().rollback();
session.close();
}
);
}
@Test
@FailureExpected(reason = "collection change does not trigger an event", jiraKey = "EJB-288")
public void testPostUpdateCollection(SessionFactoryScope scope) {
scope.inSession(
session -> {
// create a cat
Cat cat = new Cat();
session.getTransaction().begin();
cat.setLength( 23 );
cat.setAge( 2 );
cat.setName( "Beetle" );
cat.setDateOfBirth( new Date() );
session.persist( cat );
session.getTransaction().commit();
// assert it is persisted
List ids = Cat.getIdList();
Object id = Cat.getIdList().get( ids.size() - 1 );
assertNotNull( id );
// add a kitten to the cat - triggers PostCollectionRecreateEvent
int postVersion = Cat.postVersion;
session.getTransaction().begin();
Kitten kitty = new Kitten();
kitty.setName( "kitty" );
List kittens = new ArrayList<Kitten>();
kittens.add( kitty );
cat.setKittens( kittens );
session.getTransaction().commit();
assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." );
// add another kitten - triggers PostCollectionUpdateEvent.
postVersion = Cat.postVersion;
session.getTransaction().begin();
Kitten tom = new Kitten();
tom.setName( "Tom" );
cat.getKittens().add( tom );
session.getTransaction().commit();
assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." );
// delete a kitty - triggers PostCollectionUpdateEvent
postVersion = Cat.postVersion;
session.getTransaction().begin();
cat.getKittens().remove( tom );
session.getTransaction().commit();
assertEquals( postVersion + 1, Cat.postVersion, "Post version should have been incremented." );
// delete and recreate kittens - triggers PostCollectionRemoveEvent and PostCollectionRecreateEvent)
postVersion = Cat.postVersion;
session.getTransaction().begin();
cat.setKittens( new ArrayList<Kitten>() );
session.getTransaction().commit();
assertEquals( postVersion + 2, Cat.postVersion, "Post version should have been incremented." );
session.close();
}
);
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

View File

@ -6,12 +6,14 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import org.hibernate.orm.test.jpa.callbacks.Translation;
/**
* @author Emmanuel Bernard
*/

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.PrePersist;
/**

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.PreUpdate;
/**

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.PreUpdate;
/**

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PrePersist;

View File

@ -4,7 +4,7 @@
* 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.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import java.time.Instant;
import java.util.ArrayList;
@ -20,56 +20,60 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.PreUpdate;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@TestForIssue(jiraKey = "HHH-13466")
public class PreUpdateNewBidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Person.class, Tag.class };
}
@DomainModel(annotatedClasses = {
PreUpdateNewBidirectionalBagTest.Person.class,
PreUpdateNewBidirectionalBagTest.Tag.class
})
@SessionFactory
public class PreUpdateNewBidirectionalBagTest {
@Test
public void testPreUpdateModifications() {
public void testPreUpdateModifications(SessionFactoryScope scope) {
Person person = new Person();
person.id = 1;
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.persist( person );
} );
scope.inTransaction(
session -> session.persist( person )
);
doInJPA( this::entityManagerFactory, entityManager -> {
Person p = entityManager.find( Person.class, person.id );
assertNotNull( p );
final Tag tag = new Tag();
tag.id = 2;
tag.description = "description";
tag.person = p;
final Set<Tag> tags = new HashSet<Tag>();
tags.add( tag );
p.tags = tags;
entityManager.merge( p );
} );
scope.inTransaction(
session -> {
Person p = session.find( Person.class, person.id );
assertNotNull( p );
final Tag tag = new Tag();
tag.id = 2;
tag.description = "description";
tag.person = p;
final Set<Tag> tags = new HashSet<Tag>();
tags.add( tag );
p.tags = tags;
session.merge( p );
}
);
doInJPA( this::entityManagerFactory, entityManager -> {
Person p = entityManager.find( Person.class, person.id );
assertEquals( 1, p.tags.size() );
assertEquals( "description", p.tags.iterator().next().description );
assertNotNull( p.getLastUpdatedAt() );
} );
scope.inTransaction(
session -> {
Person p = session.find( Person.class, person.id );
assertEquals( 1, p.tags.size() );
assertEquals( "description", p.tags.iterator().next().description );
assertNotNull( p.getLastUpdatedAt() );
}
);
}
@Entity(name = "Person")
@EntityListeners( PersonListener.class )
private static class Person {
public static class Person {
@Id
private int id;

View File

@ -4,7 +4,7 @@
* 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.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import java.time.Instant;
import java.util.ArrayList;
@ -19,55 +19,59 @@ import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.PreUpdate;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@TestForIssue(jiraKey = "HHH-13466")
public class PreUpdateNewUnidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Person.class, Tag.class };
}
@DomainModel(annotatedClasses = {
PreUpdateNewUnidirectionalBagTest.Person.class,
PreUpdateNewUnidirectionalBagTest.Tag.class
})
@SessionFactory
public class PreUpdateNewUnidirectionalBagTest {
@Test
public void testPreUpdateModifications() {
public void testPreUpdateModifications(SessionFactoryScope scope) {
Person person = new Person();
person.id = 1;
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.persist( person );
} );
scope.inTransaction(
session -> session.persist( person )
);
doInJPA( this::entityManagerFactory, entityManager -> {
Person p = entityManager.find( Person.class, person.id );
assertNotNull( p );
final Tag tag = new Tag();
tag.id = 2;
tag.description = "description";
final Set<Tag> tags = new HashSet<Tag>();
tags.add( tag );
p.tags = tags;
entityManager.merge( p );
} );
scope.inTransaction(
session -> {
Person p = session.find( Person.class, person.id );
assertNotNull( p );
final Tag tag = new Tag();
tag.id = 2;
tag.description = "description";
final Set<Tag> tags = new HashSet<Tag>();
tags.add( tag );
p.tags = tags;
session.merge( p );
}
);
doInJPA( this::entityManagerFactory, entityManager -> {
Person p = entityManager.find( Person.class, person.id );
assertEquals( 1, p.tags.size() );
assertEquals( "description", p.tags.iterator().next().description );
assertNotNull( p.getLastUpdatedAt() );
} );
scope.inTransaction(
session -> {
Person p = session.find( Person.class, person.id );
assertEquals( 1, p.tags.size() );
assertEquals( "description", p.tags.iterator().next().description );
assertNotNull( p.getLastUpdatedAt() );
}
);
}
@Entity(name = "Person")
@EntityListeners( PersonListener.class )
private static class Person {
public static class Person {
@Id
private int id;

View File

@ -4,7 +4,7 @@
* 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.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import java.time.Instant;
import java.util.ArrayList;
@ -23,56 +23,61 @@ import javax.persistence.PreUpdate;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@TestForIssue(jiraKey = "HHH-13466")
public class PreUpdateNewUnidirectionalIdBagTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Person.class, Tag.class };
}
@DomainModel(annotatedClasses = {
PreUpdateNewUnidirectionalIdBagTest.Person.class,
PreUpdateNewUnidirectionalIdBagTest.Tag.class
})
@SessionFactory
public class PreUpdateNewUnidirectionalIdBagTest {
@Test
public void testPreUpdateModifications() {
public void testPreUpdateModifications(SessionFactoryScope scope) {
Person person = new Person();
person.id = 1;
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.persist( person );
} );
scope.inTransaction(
session -> session.persist( person )
);
doInJPA( this::entityManagerFactory, entityManager -> {
Person p = entityManager.find( Person.class, person.id );
assertNotNull( p );
final Tag tag = new Tag();
tag.id = 2;
tag.description = "description";
final Set<Tag> tags = new HashSet<Tag>();
tags.add( tag );
p.tags = tags;
entityManager.merge( p );
} );
scope.inTransaction(
session -> {
Person p = session.find( Person.class, person.id );
assertNotNull( p );
final Tag tag = new Tag();
tag.id = 2;
tag.description = "description";
final Set<Tag> tags = new HashSet<Tag>();
tags.add( tag );
p.tags = tags;
session.merge( p );
}
);
doInJPA( this::entityManagerFactory, entityManager -> {
Person p = entityManager.find( Person.class, person.id );
assertEquals( 1, p.tags.size() );
assertEquals( "description", p.tags.iterator().next().description );
assertNotNull( p.getLastUpdatedAt() );
} );
scope.inTransaction(
session -> {
Person p = session.find( Person.class, person.id );
assertEquals( 1, p.tags.size() );
assertEquals( "description", p.tags.iterator().next().description );
assertNotNull( p.getLastUpdatedAt() );
}
);
}
@Entity(name = "Person")
@EntityListeners( PersonListener.class )
@GenericGenerator(name="increment", strategy = "increment")
private static class Person {
public static class Person {
@Id
private int id;

View File

@ -4,7 +4,7 @@
* 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.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import java.util.List;
import javax.persistence.Basic;
@ -22,9 +22,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@RunWith(BytecodeEnhancerRunner.class)
public class PrivateConstructorEnhancerTest extends BaseNonConfigCoreFunctionalTestCase {

View File

@ -4,13 +4,11 @@
* 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.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@ -20,24 +18,31 @@ import javax.persistence.ManyToOne;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyFactory;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.util.ExceptionUtil;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@TestForIssue(jiraKey = "HHH-13020")
public class PrivateConstructorTest extends BaseEntityManagerFunctionalTestCase {
@DomainModel(annotatedClasses = {
PrivateConstructorTest.Parent.class,
PrivateConstructorTest.Child.class
})
@SessionFactory
public class PrivateConstructorTest {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule( Logger.getMessageLogger(
@ -46,56 +51,30 @@ public class PrivateConstructorTest extends BaseEntityManagerFunctionalTestCase
.getName()
) );
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Parent.class,
Child.class
};
}
@Test
public void test() {
public void test(SessionFactoryScope scope) {
Child child = new Child();
EntityManager entityManager = null;
EntityTransaction txn = null;
try {
entityManager = createEntityManager();
txn = entityManager.getTransaction();
txn.begin();
entityManager.persist( child );
txn.commit();
scope.inTransaction(
session -> session.persist( child )
);
entityManager.clear();
Integer childId = child.getId();
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000143:" );
Child childReference = entityManager.getReference( Child.class, childId );
try {
assertEquals( child.getParent().getName(), childReference.getParent().getName() );
}
catch (Exception expected) {
assertEquals( NoSuchMethodException.class, ExceptionUtil.rootCause( expected ).getClass() );
assertTrue( expected.getMessage().contains(
"Bytecode enhancement failed because no public, protected or package-private default constructor was found for entity"
) );
}
assertTrue( triggerable.wasTriggered() );
}
catch (Throwable e) {
if ( txn != null && txn.isActive() ) {
txn.rollback();
}
throw e;
}
finally {
if ( entityManager != null ) {
entityManager.close();
}
}
scope.inTransaction(
session -> {
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000143:" );
Child childReference = session.getReference( Child.class, child.getId() );
try {
assertEquals( child.getParent().getName(), childReference.getParent().getName() );
}
catch (Exception expected) {
assertEquals( NoSuchMethodException.class, ExceptionUtil.rootCause( expected ).getClass() );
assertTrue( expected.getMessage().contains(
"Bytecode enhancement failed because no public, protected or package-private default constructor was found for entity"
) );
}
assertTrue( triggerable.wasTriggered() );
}
);
}
private static Class<? extends ProxyFactory> proxyFactoryClass() {

View File

@ -4,68 +4,47 @@
* 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.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
@TestForIssue( jiraKey = "HHH-13020" )
public class ProtectedConstructorTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Parent.class,
Child.class
};
}
@DomainModel(annotatedClasses = {
ProtectedConstructorTest.Parent.class,
ProtectedConstructorTest.Child.class
})
@SessionFactory
public class ProtectedConstructorTest {
@Test
public void test() {
public void test(SessionFactoryScope scope) {
Child child = new Child();
EntityManager entityManager = null;
EntityTransaction txn = null;
try {
entityManager = createEntityManager();
txn = entityManager.getTransaction();
txn.begin();
entityManager.persist( child );
txn.commit();
scope.inTransaction(
session -> session.persist( child )
);
entityManager.clear();
Integer childId = child.getId();
Child childReference = entityManager.getReference( Child.class, childId );
assertEquals( child.getParent().getName(), childReference.getParent().getName() );
}
catch (Throwable e) {
if ( txn != null && txn.isActive() ) {
txn.rollback();
}
throw e;
}
finally {
if ( entityManager != null ) {
entityManager.close();
}
}
scope.inTransaction(
session -> {
Child childReference = session.getReference( Child.class, child.getId() );
assertEquals( child.getParent().getName(), childReference.getParent().getName() );
}
);
}
@Entity(name = "Parent")

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Entity;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.callbacks;
package org.hibernate.orm.test.jpa.callbacks;
import javax.persistence.EntityListeners;
import javax.persistence.ExcludeSuperclassListeners;
import javax.persistence.MappedSuperclass;

View File

@ -4,7 +4,7 @@
* 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.callbacks.hbmxml;
package org.hibernate.orm.test.jpa.callbacks.hbmxml;
/**
* @author Steve Ebersole

View File

@ -0,0 +1,46 @@
/*
* 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.callbacks.hbmxml;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
/**
* @author Felix Feisst (feisst dot felix at gmail dot com)
*/
@DomainModel(
xmlMappings = "org/hibernate/orm/test/jpa/callbacks/hbmxml/ClassMappedMoreThanOnce.hbm.xml"
)
@SessionFactory
public class MappingClassMoreThanOnceTest {
/**
* Tests that an entity manager can be created when a class is mapped more than once.
*/
@Test
@TestForIssue(jiraKey = "HHH-8775")
public void testBootstrapWithClassMappedMOreThanOnce(SessionFactoryScope scope) {
SessionFactoryImplementor sfi = null;
try {
sfi = scope.getSessionFactory();
}
finally {
if ( sfi != null ) {
try {
sfi.close();
}
catch (Exception ignore) {
}
}
}
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.callbacks.xml;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
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;
/**
* @author Steve Ebersole
*/
@DomainModel(
xmlMappings = "org/hibernate/orm/test/jpa/callbacks/xml/MyEntity.orm.xml"
)
@SessionFactory
public class EntityListenerViaXmlTest {
@Test
@TestForIssue(jiraKey = "HHH-9771")
public void testUsage(SessionFactoryScope scope) {
JournalingListener.reset();
scope.inTransaction(
session -> session.persist( new MyEntity( 1, "steve" ) )
);
assertEquals( 1, JournalingListener.getPrePersistCount() );
scope.inTransaction(
session -> session.createQuery( "delete MyEntity" ).executeUpdate()
);
}
}

View File

@ -4,7 +4,7 @@
* 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.callbacks.xml;
package org.hibernate.orm.test.jpa.callbacks.xml;
/**
* An entity listener that keeps a journal of calls

View File

@ -4,7 +4,7 @@
* 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.callbacks.xml;
package org.hibernate.orm.test.jpa.callbacks.xml;
/**
* @author Steve Ebersole

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -0,0 +1,80 @@
/*
* 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.cascade;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
/**
* @author Max Rydahl Andersen
*/
@DomainModel(annotatedClasses = {
Teacher.class,
Student.class,
Song.class,
Author.class
})
@SessionFactory
public class CascadeTest {
@Test
public void testCascade(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Teacher teacher = new Teacher();
Student student = new Student();
teacher.setFavoriteStudent( student );
student.setFavoriteTeacher( teacher );
teacher.getStudents().add( student );
student.setPrimaryTeacher( teacher );
session.persist( teacher );
}
);
scope.inTransaction(
session -> {
Teacher foundTeacher = (Teacher) session.createQuery( "select t from Teacher as t" )
.getSingleResult();
System.out.println( foundTeacher );
System.out.println( foundTeacher.getFavoriteStudent() );
for ( Student fstudent : foundTeacher.getStudents() ) {
System.out.println( fstudent );
System.out.println( fstudent.getFavoriteTeacher() );
System.out.println( fstudent.getPrimaryTeacher() );
}
}
);
}
@Test
public void testNoCascadeAndMerge(SessionFactoryScope scope) {
Song s1 = new Song();
Author a1 = new Author();
s1.setAuthor( a1 );
scope.inTransaction(
session -> {
session.persist( a1 );
session.persist( s1 );
}
);
Song s2 = scope.fromSession(
session -> session.find( Song.class, s1.getId() )
);
scope.inTransaction(
session -> session.merge( s2 )
);
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;

View File

@ -0,0 +1,92 @@
/*
* 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.cascade;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import org.junit.jupiter.api.Test;
import org.hibernate.Hibernate;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* @author Emmanuel Bernard
*/
@DomainModel(annotatedClasses = {
Troop.class,
Soldier.class
})
@SessionFactory
public class DeleteOrphanTest {
@Test
public void testDeleteOrphan(SessionFactoryScope scope) throws Exception {
Troop disney = new Troop();
Soldier mickey = new Soldier();
scope.inTransaction(
session -> {
disney.setName( "Disney" );
mickey.setName( "Mickey" );
disney.addSoldier( mickey );
session.persist( disney );
}
);
Troop troop2 = scope.fromTransaction(
session -> {
Troop troop = session.find( Troop.class, disney.getId() );
Hibernate.initialize( troop.getSoldiers() );
return troop;
}
);
Soldier soldier = troop2.getSoldiers().iterator().next();
troop2.getSoldiers().remove( soldier );
Troop troop3 = (Troop) deserialize( serialize( troop2 ) );
scope.inTransaction(
session -> session.merge( troop3 )
);
scope.inTransaction(
session -> {
Soldier _soldier = session.find( Soldier.class, mickey.getId() );
assertNull( _soldier, "delete-orphan should work" );
Troop _troop = session.find( Troop.class, disney.getId() );
session.remove( _troop );
}
);
}
private byte[] serialize(Object object) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream( stream );
out.writeObject( object );
out.close();
byte[] serialized = stream.toByteArray();
stream.close();
return serialized;
}
private Object deserialize(byte[] serialized) throws IOException, ClassNotFoundException {
ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
ObjectInputStream in = new ObjectInputStream( byteIn );
Object result = in.readObject();
in.close();
byteIn.close();
return result;
}
}

View File

@ -0,0 +1,89 @@
/*
* 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.cascade;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.junit.jupiter.api.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import static javax.persistence.CascadeType.DETACH;
import static javax.persistence.CascadeType.REMOVE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Emmanuel Bernard
*/
@DomainModel(annotatedClasses = {
DetachAndContainsTest.Mouth.class,
DetachAndContainsTest.Tooth.class
})
@SessionFactory
public class DetachAndContainsTest {
@Test
public void testDetach(SessionFactoryScope scope) {
Tooth tooth = new Tooth();
Mouth mouth = new Mouth();
scope.inTransaction(
session -> {
session.persist( mouth );
session.persist( tooth );
tooth.mouth = mouth;
mouth.teeth = new ArrayList<>();
mouth.teeth.add( tooth );
}
);
scope.inTransaction(
session -> {
Mouth _mouth = session.find( Mouth.class, mouth.id );
assertNotNull( _mouth );
assertEquals( 1, _mouth.teeth.size() );
Tooth _tooth = _mouth.teeth.iterator().next();
session.detach( _mouth );
assertFalse( session.contains( _tooth ) );
}
);
scope.inTransaction(
session -> session.remove( session.find( Mouth.class, mouth.id ) )
);
}
@Entity
@Table(name = "mouth")
public static class Mouth {
@Id
@GeneratedValue
public Integer id;
@OneToMany(mappedBy = "mouth", cascade = { DETACH, REMOVE } )
public Collection<Tooth> teeth;
}
@Entity
@Table(name = "tooth")
public static class Tooth {
@Id
@GeneratedValue
public Integer id;
public String type;
@ManyToOne
public Mouth mouth;
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import java.io.Serializable;
import javax.persistence.Column;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;

View File

@ -0,0 +1,152 @@
/*
* 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.cascade;
import java.util.ArrayList;
import java.util.Date;
import org.hibernate.Hibernate;
import org.hibernate.testing.orm.junit.DomainModel;
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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Emmanuel Bernard
*/
@DomainModel(annotatedClasses = {
Troop.class,
Soldier.class,
Conference.class,
ExtractionDocument.class,
ExtractionDocumentInfo.class,
Parent.class,
Son.class,
Grandson.class
})
@SessionFactory
public class FetchTest {
@Test
public void testCascadeAndFetchCollection(SessionFactoryScope scope) {
Troop disney = new Troop();
Soldier mickey = new Soldier();
disney.setName( "Disney" );
mickey.setName( "Mickey" );
disney.addSoldier( mickey );
scope.inTransaction(
session -> session.persist( disney )
);
Troop troop2 = scope.fromTransaction(
session -> {
Troop troop = session.find( Troop.class, disney.getId() );
assertFalse( Hibernate.isInitialized( troop.getSoldiers() ) );
return troop;
}
);
assertFalse( Hibernate.isInitialized( troop2.getSoldiers() ) );
scope.inTransaction(
session -> {
Troop troop = session.find( Troop.class, disney.getId() );
session.remove( troop );
}
);
}
@Test
public void testCascadeAndFetchEntity(SessionFactoryScope scope) {
Troop disney = new Troop();
Soldier mickey = new Soldier();
disney.setName( "Disney" );
mickey.setName( "Mickey" );
disney.addSoldier( mickey );
scope.inTransaction(
session -> session.persist( disney )
);
Soldier soldier2 = scope.fromTransaction(
session -> {
Soldier soldier = session.find( Soldier.class, mickey.getId() );
assertFalse( Hibernate.isInitialized( soldier.getTroop() ) );
return soldier;
}
);
assertFalse( Hibernate.isInitialized( soldier2.getTroop() ) );
scope.inTransaction(
session -> {
Troop troop = session.find( Troop.class, disney.getId() );
session.remove( troop );
}
);
}
@Test
public void testTwoLevelDeepPersist(SessionFactoryScope scope) {
Conference jbwBarcelona = new Conference();
jbwBarcelona.setDate( new Date() );
ExtractionDocumentInfo info = new ExtractionDocumentInfo();
info.setConference( jbwBarcelona );
jbwBarcelona.setExtractionDocument( info );
info.setLastModified( new Date() );
ExtractionDocument doc = new ExtractionDocument();
doc.setDocumentInfo( info );
info.setDocuments( new ArrayList<ExtractionDocument>() );
info.getDocuments().add( doc );
doc.setBody( new byte[]{'c', 'f'} );
scope.inTransaction(
session -> session.persist( jbwBarcelona )
);
scope.inSession(
session -> {
session.getTransaction().begin();
Conference _jbwBarcelona = session.find( Conference.class, jbwBarcelona.getId() );
assertTrue( Hibernate.isInitialized( _jbwBarcelona ) );
assertTrue( Hibernate.isInitialized( _jbwBarcelona.getExtractionDocument() ) );
assertFalse( Hibernate.isInitialized( _jbwBarcelona.getExtractionDocument().getDocuments() ) );
session.flush();
assertTrue( Hibernate.isInitialized( _jbwBarcelona ) );
assertTrue( Hibernate.isInitialized( _jbwBarcelona.getExtractionDocument() ) );
assertFalse( Hibernate.isInitialized( _jbwBarcelona.getExtractionDocument().getDocuments() ) );
session.remove( _jbwBarcelona );
session.getTransaction().commit();
}
);
}
@Test
public void testTwoLevelDeepPersistOnManyToOne(SessionFactoryScope scope) {
Grandson gs = new Grandson();
gs.setParent( new Son() );
gs.getParent().setParent( new Parent() );
scope.inTransaction(
session -> session.persist( gs )
);
scope.inSession(
session -> {
session.getTransaction().begin();
Grandson _gs = session.find( Grandson.class, gs.getId() );
session.flush();
assertTrue( Hibernate.isInitialized( _gs.getParent() ) );
assertFalse( Hibernate.isInitialized( _gs.getParent().getParent() ) );
session.remove( _gs );
session.getTransaction().commit();
}
);
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.cascade;
import org.hibernate.testing.orm.junit.DomainModel;
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.fail;
@DomainModel(annotatedClasses = {
Troop2.class,
Soldier2.class
})
@SessionFactory
public class FetchTest2 {
@Test
public void testProxyTransientStuff(SessionFactoryScope scope) {
Troop2 disney = new Troop2();
disney.setName( "Disney" );
Soldier2 mickey = new Soldier2();
mickey.setName( "Mickey" );
mickey.setTroop( disney );
scope.inTransaction(
session -> {
session.persist( disney );
session.persist( mickey );
}
);
scope.inTransaction(
session -> {
Soldier2 _soldier = session.find( Soldier2.class, mickey.getId() );
_soldier.getTroop().getId();
try {
session.flush();
}
catch (IllegalStateException e) {
fail( "Should not raise an exception" );
}
}
);
scope.inTransaction(
session -> {
//load troop wo a proxy
Troop2 _troop = session.find( Troop2.class, disney.getId() );
Soldier2 _soldier = session.find( Soldier2.class, mickey.getId() );
try {
session.flush();
}
catch (IllegalStateException e) {
fail( "Should not raise an exception" );
}
session.remove( _troop );
session.remove( _soldier );
}
);
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;

View File

@ -0,0 +1,129 @@
/*
* 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.cascade;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.testing.orm.junit.DomainModel;
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;
@DomainModel(annotatedClasses = {
MergeTest.Order.class,
MergeTest.Item.class
})
@SessionFactory
public class MergeTest {
@Test
public void testMergeDetachedEntityWithNewOneToManyElements(SessionFactoryScope scope) {
Order order = new Order();
scope.inTransaction(
session -> {
session.persist( order );
}
);
Item item1 = new Item();
item1.name = "i1";
Item item2 = new Item();
item2.name = "i2";
order.addItem( item1 );
order.addItem( item2 );
scope.inTransaction(
session -> {
session.merge( order );
session.flush();
}
);
scope.inTransaction(
session -> {
Order _order = session.find( Order.class, order.id );
assertEquals( 2, _order.items.size() );
session.remove( _order );
}
);
}
@Test
public void testMergeLoadedEntityWithNewOneToManyElements(SessionFactoryScope scope) {
Order order = new Order();
scope.inTransaction(
session -> {
session.persist( order );
}
);
scope.inTransaction(
session -> {
Order _order = session.find( Order.class, order.id );
Item item1 = new Item();
item1.name = "i1";
Item item2 = new Item();
item2.name = "i2";
_order.addItem( item1 );
_order.addItem( item2 );
session.merge( _order );
session.flush();
}
);
scope.inTransaction(
session -> {
Order _order = session.find( Order.class, order.id );
assertEquals( 2, _order.items.size() );
session.remove( _order );
}
);
}
@Entity
public static class Order {
@Id
@GeneratedValue
private Long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "order", orphanRemoval = true)
private List<Item> items = new ArrayList<Item>();
public Order() {
}
public void addItem(Item item) {
items.add( item );
item.order = this;
}
}
@Entity
public static class Item {
@Id
@GeneratedValue
private Long id;
private String name;
@ManyToOne
private Order order;
}
}

View File

@ -0,0 +1,89 @@
/*
* 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.cascade;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.testing.orm.junit.DomainModel;
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.fail;
/**
* @author Steve Ebersole
*/
@DomainModel(annotatedClasses = {
MergeWithTransientNonCascadedAssociationTest.Person.class,
MergeWithTransientNonCascadedAssociationTest.Address.class
})
@SessionFactory
public class MergeWithTransientNonCascadedAssociationTest {
@Test
public void testMergeWithTransientNonCascadedAssociation(SessionFactoryScope scope) {
Person person = new Person();
scope.inTransaction(
session -> {
session.persist( person );
}
);
person.address = new Address();
scope.inSession(
session -> {
session.getTransaction().begin();
session.merge( person );
try {
session.flush();
fail( "Expecting IllegalStateException" );
}
catch (IllegalStateException ise) {
// expected...
session.getTransaction().rollback();
}
}
);
scope.inTransaction(
session -> {
person.address = null;
session.unwrap( Session.class ).lock( person, LockMode.NONE );
session.unwrap( Session.class ).delete( person );
}
);
}
@Entity(name = "Person")
public static class Person {
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private Integer id;
@ManyToOne
private Address address;
public Person() {
}
}
@Entity(name = "Address")
public static class Address {
@Id
@GeneratedValue(generator = "increment_1")
@GenericGenerator(name = "increment_1", strategy = "increment")
private Integer id;
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

View File

@ -4,7 +4,7 @@
* 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.cascade;
package org.hibernate.orm.test.jpa.cascade;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;

View File

@ -4,7 +4,7 @@
* 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.cascade;
package org.hibernate.orm.test.jpa.cascade;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

View File

@ -4,7 +4,7 @@
* 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.cascade;
package org.hibernate.orm.test.jpa.cascade;
import java.util.HashSet;
import java.util.Set;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.cascade;
package org.hibernate.orm.test.jpa.cascade;
import java.io.Serializable;
import java.util.HashSet;

View File

@ -4,7 +4,7 @@
* 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.cascade;
package org.hibernate.orm.test.jpa.cascade;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -4,7 +4,7 @@
* 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.cascade.multicircle;
package org.hibernate.orm.test.jpa.cascade.multicircle;
import java.io.Serializable;
import java.util.Date;

View File

@ -4,7 +4,7 @@
* 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.cascade.multicircle;
package org.hibernate.orm.test.jpa.cascade.multicircle;
/**
* No Documentation

View File

@ -4,7 +4,7 @@
* 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.cascade.multicircle;
package org.hibernate.orm.test.jpa.cascade.multicircle;
import java.util.Set;

View File

@ -4,7 +4,7 @@
* 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.cascade.multicircle;
package org.hibernate.orm.test.jpa.cascade.multicircle;
/**
* No Documentation

View File

@ -4,7 +4,7 @@
* 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.cascade.multicircle;
package org.hibernate.orm.test.jpa.cascade.multicircle;
/**
* No Documentation

View File

@ -4,7 +4,7 @@
* 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.cascade.multicircle;
package org.hibernate.orm.test.jpa.cascade.multicircle;
/**
* No Documentation

View File

@ -4,7 +4,7 @@
* 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.cascade.multicircle;
package org.hibernate.orm.test.jpa.cascade.multicircle;
/**
* No Documentation

View File

@ -0,0 +1,321 @@
/*
* 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.cascade.multicircle;
import javax.persistence.RollbackException;
import org.hibernate.TransientPropertyValueException;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;
/**
* This test uses a complicated model that requires Hibernate to delay
* inserts until non-nullable transient entity dependencies are resolved.
* <p>
* All IDs are generated from a sequence.
* <p>
* JPA cascade types are used (javax.persistence.CascadeType)..
* <p>
* This test uses the following model:
*
* <code>
* ------------------------------ N G
* |
* | 1
* | |
* | |
* | N
* |
* | E N--------------0,1 * F
* |
* | 1 N
* | | |
* | | |
* 1 N |
* * |
* B * N---1 D * 1------------------
* *
* N N
* | |
* | |
* 1 |
* |
* C * 1-----
* </code>
* <p>
* In the diagram, all associations are bidirectional;
* assocations marked with '*' cascade persist, save, merge operations to the
* associated entities (e.g., B cascades persist to D, but D does not cascade
* persist to B);
* <p>
* b, c, d, e, f, and g are all transient unsaved that are associated with each other.
* <p>
* When saving b, the entities are added to the ActionQueue in the following order:
* c, d (depends on e), f (depends on d, g), e, b, g.
* <p>
* Entities are inserted in the following order:
* c, e, d, b, g, f.
*/
@Jpa(
annotatedClasses = {
B.class,
C.class,
D.class,
E.class,
F.class,
G.class
}
)
public class MultiCircleJpaCascadeTest {
private B b;
private C c;
private D d;
private E e;
private F f;
private G g;
private boolean skipCleanup;
@BeforeEach
public void setup() {
b = new B();
c = new C();
d = new D();
e = new E();
f = new F();
g = new G();
b.getGCollection().add( g );
b.setC( c );
b.setD( d );
c.getBCollection().add( b );
c.getDCollection().add( d );
d.getBCollection().add( b );
d.setC( c );
d.setE( e );
d.getFCollection().add( f );
e.getDCollection().add( d );
e.setF( f );
f.getECollection().add( e );
f.setD( d );
f.setG( g );
g.setB( b );
g.getFCollection().add( f );
skipCleanup = false;
}
@AfterEach
public void cleanup(EntityManagerFactoryScope scope) {
if ( !skipCleanup ) {
b.setC( null );
b.setD( null );
b.getGCollection().remove( g );
c.getBCollection().remove( b );
c.getDCollection().remove( d );
d.getBCollection().remove( b );
d.setC( null );
d.setE( null );
d.getFCollection().remove( f );
e.getDCollection().remove( d );
e.setF( null );
f.setD( null );
f.getECollection().remove( e );
f.setG( null );
g.setB( null );
g.getFCollection().remove( f );
scope.inTransaction(
entityManager -> {
b = entityManager.merge( b );
c = entityManager.merge( c );
d = entityManager.merge( d );
e = entityManager.merge( e );
f = entityManager.merge( f );
g = entityManager.merge( g );
entityManager.remove( f );
entityManager.remove( g );
entityManager.remove( b );
entityManager.remove( d );
entityManager.remove( e );
entityManager.remove( c );
}
);
}
}
@Test
public void testPersist(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.persist( b );
}
);
check( scope );
}
@Test
public void testPersistNoCascadeToTransient(EntityManagerFactoryScope scope) {
skipCleanup = true;
scope.inEntityManager(
entityManager -> {
entityManager.getTransaction().begin();
try {
entityManager.persist( c );
fail( "should have failed." );
}
catch (IllegalStateException ex) {
assertTrue( TransientPropertyValueException.class.isInstance( ex.getCause() ) );
TransientPropertyValueException pve = (TransientPropertyValueException) ex.getCause();
assertEquals( G.class.getName(), pve.getTransientEntityName() );
assertEquals( F.class.getName(), pve.getPropertyOwnerEntityName() );
assertEquals( "g", pve.getPropertyName() );
}
entityManager.getTransaction().rollback();
}
);
}
@Test
@FailureExpected(jiraKey = "HHH-6999") // remove skipCleanup below when this annotation is removed, added it to avoid failure in the cleanup
// fails on d.e; should pass
public void testPersistThenUpdate(EntityManagerFactoryScope scope) {
skipCleanup = true;
scope.inTransaction(
entityManager -> {
entityManager.persist( b );
// remove old e from associations
e.getDCollection().remove( d );
d.setE( null );
f.getECollection().remove( e );
e.setF( null );
// add new e to associations
e = new E();
e.getDCollection().add( d );
f.getECollection().add( e );
d.setE( e );
e.setF( f );
}
);
check( scope );
}
@Test
public void testPersistThenUpdateNoCascadeToTransient(EntityManagerFactoryScope scope) {
// expected to fail, so nothing will be persisted.
skipCleanup = true;
scope.inEntityManager(
entityManager -> {
// remove elements from collections and persist
c.getBCollection().clear();
c.getDCollection().clear();
entityManager.getTransaction().begin();
entityManager.persist( c );
// now add the elements back
c.getBCollection().add( b );
c.getDCollection().add( d );
try {
entityManager.getTransaction().commit();
fail( "should have thrown IllegalStateException" );
}
catch (RollbackException ex) {
assertTrue( ex.getCause() instanceof IllegalStateException );
IllegalStateException ise = (IllegalStateException) ex.getCause();
// should fail on entity g (due to no cascade to f.g);
// instead it fails on entity e ( due to no cascade to d.e)
// because e is not in the process of being saved yet.
// when HHH-6999 is fixed, this test should be changed to
// check for g and f.g
//noinspection ThrowableResultOfMethodCallIgnored
TransientPropertyValueException tpve = assertTyping(
TransientPropertyValueException.class,
ise.getCause()
);
assertEquals( E.class.getName(), tpve.getTransientEntityName() );
assertEquals( D.class.getName(), tpve.getPropertyOwnerEntityName() );
assertEquals( "e", tpve.getPropertyName() );
}
}
);
}
@Test
public void testMerge(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
b = entityManager.merge( b );
c = b.getC();
d = b.getD();
e = d.getE();
f = e.getF();
g = f.getG();
}
);
check( scope );
}
private void check(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
B bRead = entityManager.find( B.class, b.getId() );
assertEquals( b, bRead );
G gRead = bRead.getGCollection().iterator().next();
assertEquals( g, gRead );
C cRead = bRead.getC();
assertEquals( c, cRead );
D dRead = bRead.getD();
assertEquals( d, dRead );
assertSame( bRead, cRead.getBCollection().iterator().next() );
assertSame( dRead, cRead.getDCollection().iterator().next() );
assertSame( bRead, dRead.getBCollection().iterator().next() );
assertEquals( cRead, dRead.getC() );
E eRead = dRead.getE();
assertEquals( e, eRead );
F fRead = dRead.getFCollection().iterator().next();
assertEquals( f, fRead );
assertSame( dRead, eRead.getDCollection().iterator().next() );
assertSame( fRead, eRead.getF() );
assertSame( eRead, fRead.getECollection().iterator().next() );
assertSame( dRead, fRead.getD() );
assertSame( gRead, fRead.getG() );
assertSame( bRead, gRead.getB() );
assertSame( fRead, gRead.getFCollection().iterator().next() );
}
);
}
}

View File

@ -4,7 +4,7 @@
* 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.cascade.multilevel;
package org.hibernate.orm.test.jpa.cascade.multilevel;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -4,7 +4,7 @@
* 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.cascade.multilevel;
package org.hibernate.orm.test.jpa.cascade.multilevel;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

View File

@ -4,7 +4,7 @@
* 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.cascade.multilevel;
package org.hibernate.orm.test.jpa.cascade.multilevel;
import java.io.Serializable;
import java.util.ArrayList;
@ -20,7 +20,6 @@ import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
@ -28,75 +27,91 @@ import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class MultiLevelCascadeCollectionEmbeddableTest extends BaseEntityManagerFunctionalTestCase {
@DomainModel(annotatedClasses = {
MultiLevelCascadeCollectionEmbeddableTest.MainEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.SubEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.AnotherSubSubEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.SubSubEntity.class
})
@SessionFactory
@NotImplementedYet(reason = "NotImplementedYetException thrown in the initialization method, by NativeNonSelectQueryPlanImpl.executeUpdate()")
public class MultiLevelCascadeCollectionEmbeddableTest {
private static final Logger log = Logger.getLogger( MultiLevelCascadeCollectionEmbeddableTest.class );
private boolean initialized = false;
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
MainEntity.class,
SubEntity.class,
AnotherSubSubEntity.class,
SubSubEntity.class
};
}
protected void afterEntityManagerFactoryBuilt() {
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.createNativeQuery( "INSERT INTO MAIN_TABLE(ID_NUM) VALUES (99427)" ).executeUpdate();
entityManager.createNativeQuery( "INSERT INTO SUB_TABLE(ID_NUM, SUB_ID, FAMILY_IDENTIFIER, IND_NUM) VALUES (99427, 1, 'A', '123A')" ).executeUpdate();
entityManager.createNativeQuery( "INSERT INTO SUB_TABLE(ID_NUM, SUB_ID, FAMILY_IDENTIFIER, IND_NUM) VALUES (99427, 2, 'S', '321A')" ).executeUpdate();
entityManager.createNativeQuery( "INSERT INTO SUB_SUB_TABLE(ID_NUM, CODE, IND_NUM) VALUES (99427, 'CODE1', '123A')" ).executeUpdate();
} );
//TODO this could be implemented with @BeforeAll, if we move to Junit 5.5 or higher. The way to intercept exceptions in this method, inside
// the @NotImplementedYet extension would be by harnessing LifecycleMethodExecutionExceptionHandler, or InvocationInterceptor,
// and both are Junit 5.5 (and experimental)
protected void initialize(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createNativeQuery( "INSERT INTO MAIN_TABLE(ID_NUM) VALUES (99427)" ).executeUpdate();
session.createNativeQuery( "INSERT INTO SUB_TABLE(ID_NUM, SUB_ID, FAMILY_IDENTIFIER, IND_NUM) VALUES (99427, 1, 'A', '123A')" ).executeUpdate();
session.createNativeQuery( "INSERT INTO SUB_TABLE(ID_NUM, SUB_ID, FAMILY_IDENTIFIER, IND_NUM) VALUES (99427, 2, 'S', '321A')" ).executeUpdate();
session.createNativeQuery( "INSERT INTO SUB_SUB_TABLE(ID_NUM, CODE, IND_NUM) VALUES (99427, 'CODE1', '123A')" ).executeUpdate();
}
);
initialized = true;
}
@Test
@FailureExpected( jiraKey = "HHH-12291" )
public void testHibernateDeleteEntityWithoutInitializingCollections() throws Exception {
doInJPA( this::entityManagerFactory, entityManager -> {
MainEntity mainEntity = entityManager.find(MainEntity.class, 99427L);
public void testHibernateDeleteEntityWithoutInitializingCollections(SessionFactoryScope scope) {
if ( !initialized ) {
initialize(scope);
}
scope.inTransaction(
session -> {
MainEntity mainEntity = session.find(MainEntity.class, 99427L);
assertNotNull(mainEntity);
assertFalse(mainEntity.getSubEntities().isEmpty());
assertNotNull(mainEntity);
assertFalse(mainEntity.getSubEntities().isEmpty());
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
subEntityToRemove.ifPresent( mainEntity::removeSubEntity );
} );
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
subEntityToRemove.ifPresent( mainEntity::removeSubEntity );
}
);
}
@Test
@TestForIssue( jiraKey = "HHH-12294" )
public void testHibernateDeleteEntityInitializeCollections() throws Exception {
doInJPA( this::entityManagerFactory, entityManager -> {
MainEntity mainEntity = entityManager.find(MainEntity.class, 99427L);
public void testHibernateDeleteEntityInitializeCollections(SessionFactoryScope scope) {
if ( !initialized ) {
initialize(scope);
}
scope.inTransaction(
session -> {
MainEntity mainEntity = session.find(MainEntity.class, 99427L);
assertNotNull(mainEntity);
assertFalse(mainEntity.getSubEntities().isEmpty());
assertNotNull(mainEntity);
assertFalse(mainEntity.getSubEntities().isEmpty());
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
if ( subEntityToRemove.isPresent() ) {
SubEntity subEntity = subEntityToRemove.get();
assertEquals( 1, subEntity.getSubSubEntities().size() );
assertEquals( 0, subEntity.getAnotherSubSubEntities().size() );
mainEntity.removeSubEntity( subEntity );
}
} );
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
if ( subEntityToRemove.isPresent() ) {
SubEntity subEntity = subEntityToRemove.get();
assertEquals( 1, subEntity.getSubSubEntities().size() );
assertEquals( 0, subEntity.getAnotherSubSubEntities().size() );
mainEntity.removeSubEntity( subEntity );
}
}
);
}

View File

@ -4,7 +4,7 @@
* 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.cascade.multilevel;
package org.hibernate.orm.test.jpa.cascade.multilevel;
import java.io.Serializable;
import java.util.ArrayList;
@ -26,78 +26,93 @@ import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class MultiLevelCascadeCollectionIdClassTest extends BaseEntityManagerFunctionalTestCase {
@DomainModel(annotatedClasses = {
MultiLevelCascadeCollectionIdClassTest.MainEntity.class,
MultiLevelCascadeCollectionIdClassTest.SubEntity.class,
MultiLevelCascadeCollectionIdClassTest.AnotherSubSubEntity.class,
MultiLevelCascadeCollectionIdClassTest.SubSubEntity.class
})
@SessionFactory
@NotImplementedYet(reason = "NotImplementedYetException thrown in the initialization method, by NativeNonSelectQueryPlanImpl.executeUpdate()")
public class MultiLevelCascadeCollectionIdClassTest {
private static final Logger log = Logger.getLogger( MultiLevelCascadeCollectionIdClassTest.class );
private boolean initialized = false;
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
MainEntity.class,
SubEntity.class,
AnotherSubSubEntity.class,
SubSubEntity.class
};
}
protected void afterEntityManagerFactoryBuilt() {
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.createNativeQuery( "INSERT INTO MAIN_TABLE(ID_NUM) VALUES (99427)" ).executeUpdate();
entityManager.createNativeQuery( "INSERT INTO SUB_TABLE(ID_NUM, SUB_ID, FAMILY_IDENTIFIER, IND_NUM) VALUES (99427, 1, 'A', '123A')" ).executeUpdate();
entityManager.createNativeQuery( "INSERT INTO SUB_TABLE(ID_NUM, SUB_ID, FAMILY_IDENTIFIER, IND_NUM) VALUES (99427, 2, 'S', '321A')" ).executeUpdate();
entityManager.createNativeQuery( "INSERT INTO SUB_SUB_TABLE(ID_NUM, CODE, IND_NUM) VALUES (99427, 'CODE1', '123A')" ).executeUpdate();
} );
//TODO this could be implemented with @BeforeAll, if we move to Junit 5.5 or higher. The way to intercept exceptions in this method, inside
// the @NotImplementedYet extension would be by harnessing LifecycleMethodExecutionExceptionHandler, or InvocationInterceptor,
// and both are Junit 5.5 (and experimental)
protected void initialize(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createNativeQuery( "INSERT INTO MAIN_TABLE(ID_NUM) VALUES (99427)" ).executeUpdate();
session.createNativeQuery( "INSERT INTO SUB_TABLE(ID_NUM, SUB_ID, FAMILY_IDENTIFIER, IND_NUM) VALUES (99427, 1, 'A', '123A')" ).executeUpdate();
session.createNativeQuery( "INSERT INTO SUB_TABLE(ID_NUM, SUB_ID, FAMILY_IDENTIFIER, IND_NUM) VALUES (99427, 2, 'S', '321A')" ).executeUpdate();
session.createNativeQuery( "INSERT INTO SUB_SUB_TABLE(ID_NUM, CODE, IND_NUM) VALUES (99427, 'CODE1', '123A')" ).executeUpdate();
}
);
initialized = true;
}
@Test
@FailureExpected( jiraKey = "HHH-12291" )
public void testHibernateDeleteEntityWithoutInitializingCollections() throws Exception {
doInJPA( this::entityManagerFactory, entityManager -> {
MainEntity mainEntity = entityManager.find(MainEntity.class, 99427L);
public void testHibernateDeleteEntityWithoutInitializingCollections(SessionFactoryScope scope) {
if ( !initialized ) {
initialize(scope);
}
scope.inTransaction(
session -> {
MainEntity mainEntity = session.find(MainEntity.class, 99427L);
assertNotNull(mainEntity);
assertFalse(mainEntity.getSubEntities().isEmpty());
assertNotNull(mainEntity);
assertFalse(mainEntity.getSubEntities().isEmpty());
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
subEntityToRemove.ifPresent( mainEntity::removeSubEntity );
} );
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
subEntityToRemove.ifPresent( mainEntity::removeSubEntity );
}
);
}
@Test
@TestForIssue( jiraKey = "HHH-12294" )
public void testHibernateDeleteEntityInitializeCollections() throws Exception {
doInJPA( this::entityManagerFactory, entityManager -> {
MainEntity mainEntity = entityManager.find(MainEntity.class, 99427L);
public void testHibernateDeleteEntityInitializeCollections(SessionFactoryScope scope) {
if ( !initialized ) {
initialize(scope);
}
scope.inTransaction(
session -> {
MainEntity mainEntity = session.find(MainEntity.class, 99427L);
assertNotNull(mainEntity);
assertFalse(mainEntity.getSubEntities().isEmpty());
assertNotNull(mainEntity);
assertFalse(mainEntity.getSubEntities().isEmpty());
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
if ( subEntityToRemove.isPresent() ) {
SubEntity subEntity = subEntityToRemove.get();
assertEquals( 1, subEntity.getSubSubEntities().size() );
assertEquals( 0, subEntity.getAnotherSubSubEntities().size() );
mainEntity.removeSubEntity( subEntity );
}
} );
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
if ( subEntityToRemove.isPresent() ) {
SubEntity subEntity = subEntityToRemove.get();
assertEquals( 1, subEntity.getSubSubEntities().size() );
assertEquals( 0, subEntity.getAnotherSubSubEntities().size() );
mainEntity.removeSubEntity( subEntity );
}
}
);
}
@Entity
@Table(name = "MAIN_TABLE")
public static class MainEntity implements Serializable {

View File

@ -4,7 +4,7 @@
* 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.cascade.multilevel;
package org.hibernate.orm.test.jpa.cascade.multilevel;
import java.util.ArrayList;
import java.util.List;
@ -16,66 +16,68 @@ import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class MultiLevelCascadeRegularIdBasedParentChildAssociationTest extends BaseEntityManagerFunctionalTestCase {
@DomainModel(annotatedClasses = {
MultiLevelCascadeRegularIdBasedParentChildAssociationTest.Parent.class,
MultiLevelCascadeRegularIdBasedParentChildAssociationTest.Child.class,
MultiLevelCascadeRegularIdBasedParentChildAssociationTest.Skill.class,
MultiLevelCascadeRegularIdBasedParentChildAssociationTest.Hobby.class
})
@SessionFactory
public class MultiLevelCascadeRegularIdBasedParentChildAssociationTest {
private static final Logger log = Logger.getLogger( MultiLevelCascadeRegularIdBasedParentChildAssociationTest.class );
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
Parent.class,
Child.class,
Skill.class,
Hobby.class
};
}
@BeforeAll
protected void initialize(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Parent parent = new Parent();
parent.id = 1L;
protected void afterEntityManagerFactoryBuilt() {
doInJPA( this::entityManagerFactory, entityManager -> {
Parent parent = new Parent();
parent.id = 1L;
Child child1 = new Child();
child1.id = 1L;
parent.addChild( child1 );
Child child1 = new Child();
child1.id = 1L;
parent.addChild( child1 );
Child child2 = new Child();
child2.id = 2L;
parent.addChild( child2 );
Child child2 = new Child();
child2.id = 2L;
parent.addChild( child2 );
Skill skill = new Skill();
skill.id = 1L;
child1.addSkill( skill );
Skill skill = new Skill();
skill.id = 1L;
child1.addSkill( skill );
entityManager.persist( parent );
} );
session.persist( parent );
}
);
}
@Test
@TestForIssue( jiraKey = "HHH-12291" )
public void testHibernateDeleteEntityWithoutInitializingCollections() throws Exception {
doInJPA( this::entityManagerFactory, entityManager -> {
Parent mainEntity = entityManager.find( Parent.class, 1L);
public void testHibernateDeleteEntityWithoutInitializingCollections(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Parent mainEntity = session.find( Parent.class, 1L);
assertNotNull(mainEntity);
assertFalse(mainEntity.getChildren().isEmpty());
assertNotNull(mainEntity);
assertFalse(mainEntity.getChildren().isEmpty());
Optional<Child> childToRemove = mainEntity.getChildren().stream()
.filter(child -> Long.valueOf( 1L ).equals(child.id)).findFirst();
childToRemove.ifPresent( mainEntity::removeChild );
} );
Optional<Child> childToRemove = mainEntity.getChildren().stream()
.filter(child -> Long.valueOf( 1L ).equals(child.id)).findFirst();
childToRemove.ifPresent( mainEntity::removeChild );
}
);
}
@Entity(name = "Parent")

View File

@ -0,0 +1,70 @@
/*
* 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.cascade.multilevel;
import org.junit.jupiter.api.Test;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
@DomainModel(annotatedClasses = {
Top.class,
Middle.class,
Bottom.class
})
@SessionFactory
public class MultiLevelCascadeTest {
@TestForIssue(jiraKey = "HHH-5299")
@Test
public void test(SessionFactoryScope scope) {
final Top top = new Top();
scope.inTransaction(
session -> {
session.persist( top );
// Flush 1
session.flush();
Middle middle = new Middle( 1l );
top.addMiddle( middle );
middle.setTop( top );
Bottom bottom = new Bottom();
middle.setBottom( bottom );
bottom.setMiddle( middle );
Middle middle2 = new Middle( 2l );
top.addMiddle( middle2 );
middle2.setTop( top );
Bottom bottom2 = new Bottom();
middle2.setBottom( bottom2 );
bottom2.setMiddle( middle2 );
// Flush 2
session.flush();
}
);
scope.inTransaction(
session -> {
Top found = session.find( Top.class, top.getId() );
assertEquals( 2, found.getMiddles().size() );
for ( Middle loadedMiddle : found.getMiddles() ) {
assertSame( found, loadedMiddle.getTop() );
assertNotNull( loadedMiddle.getBottom() );
}
session.remove( found );
}
);
}
}

View File

@ -4,7 +4,7 @@
* 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.cascade.multilevel;
package org.hibernate.orm.test.jpa.cascade.multilevel;
import java.util.ArrayList;
import java.util.List;

View File

@ -4,7 +4,7 @@
* 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.cdi;
package org.hibernate.orm.test.jpa.cdi;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -27,11 +27,11 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.tool.schema.Action;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Steve Ebersole

View File

@ -4,25 +4,24 @@
* 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.cdi;
package org.hibernate.orm.test.jpa.cdi;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.persistence.EntityManagerFactory;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.junit4.ClassLoadingIsolater;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test JPA bootstrapping when CDI is not available for classloading.
*
* @author Steve Ebersole
*/
public class NoCdiAvailableTest extends BaseUnitTestCase {
public class NoCdiAvailableTest {
public static final String[] EXCLUDED_PACKAGES = new String[] {
"javax.enterprise.inject.",
"javax.enterprise.context."
@ -62,7 +61,7 @@ public class NoCdiAvailableTest extends BaseUnitTestCase {
@Test
public void testJpaBootstrapWithoutCdiAvailable() throws Exception {
Class delegateClass = Thread.currentThread().getContextClassLoader().loadClass(
"org.hibernate.jpa.test.cdi.NoCdiAvailableTestDelegate"
"org.hibernate.orm.test.jpa.cdi.NoCdiAvailableTestDelegate"
);
Method mainMethod = delegateClass.getMethod( "passingNoBeanManager" );
EntityManagerFactory entityManagerFactory = null;
@ -79,7 +78,7 @@ public class NoCdiAvailableTest extends BaseUnitTestCase {
@Test
public void testJpaBootstrapWithoutCdiAvailablePassingCdi() throws Throwable {
Class delegateClass = Thread.currentThread().getContextClassLoader().loadClass(
"org.hibernate.jpa.test.cdi.NoCdiAvailableTestDelegate"
"org.hibernate.orm.test.jpa.cdi.NoCdiAvailableTestDelegate"
);
Method mainMethod = delegateClass.getMethod( "passingBeanManager" );
try {

View File

@ -4,7 +4,7 @@
* 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.cdi;
package org.hibernate.orm.test.jpa.cdi;
import java.util.Collections;

View File

@ -4,7 +4,7 @@
* 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.cdi.extended;
package org.hibernate.orm.test.jpa.cdi.extended;
import javax.ejb.LocalBean;
import javax.ejb.Stateful;

View File

@ -4,7 +4,7 @@
* 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.cdi.extended;
package org.hibernate.orm.test.jpa.cdi.extended;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -4,7 +4,7 @@
* 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.cdi.extended;
package org.hibernate.orm.test.jpa.cdi.extended;
import javax.annotation.PostConstruct;
import javax.ejb.LocalBean;

Some files were not shown because too many files have changed in this diff Show More