HHH-14503 - Migration of tests from jpa/test to orm/test/jpa

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2021-03-19 19:00:18 +01:00 committed by Andrea Boriero
parent 3d90dbfbae
commit e2225d8814
88 changed files with 1701 additions and 1615 deletions

View File

@ -11,7 +11,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0"
>
<package>org.hibernate.jpa.test.xml</package>
<package>org.hibernate.orm.test.jpa.xml</package>
<entity class="Light" access="FIELD" metadata-complete="true">
<attributes>
<id name="name">

View File

@ -1,36 +0,0 @@
package org.hibernate.jpa.test;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.core.Is.is;
@TestForIssue( jiraKey = "HHH-9029")
@RequiresDialectFeature(DialectChecks.SupportsRowValueConstructorSyntaxCheck.class)
public class CompositeIdRowValueTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testTupleAfterSubQuery() {
EntityManager em = getOrCreateEntityManager();
Query q = em.createQuery("SELECT e FROM EntityWithCompositeId e "
+ "WHERE EXISTS (SELECT 1 FROM EntityWithCompositeId) "
+ "AND e.id = :id");
q.setParameter("id", new CompositeId(1, 2));
assertThat(q.getResultList().size(), is(0));
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {EntityWithCompositeId.class, CompositeId.class};
}
}

View File

@ -1,38 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
*
*/
public class CountEntityWithCompositeIdTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void shouldCount() {
EntityManager em = getOrCreateEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<EntityWithCompositeId> r = cq.from(EntityWithCompositeId.class);
cq.multiselect(cb.count(r));
assertThat(em.createQuery(cq).getSingleResult().intValue(), is(0));
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {EntityWithCompositeId.class, CompositeId.class};
}
}

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>.
*/
//$Id$
package org.hibernate.jpa.test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import org.hibernate.SessionFactory;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.hibernate.testing.TestForIssue;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
/**
* Test various unwrap scenarios for {@code EntityManagerFactory}.
*/
@TestForIssue(jiraKey = "HHH-9665")
public class EntityManagerFactoryUnwrapTest extends BaseEntityManagerFunctionalTestCase {
private EntityManagerFactory entityManagerFactory;
@Override
public Class[] getAnnotatedClasses() {
return new Class[] { };
}
@Before
public void setUp() {
entityManagerFactory = entityManagerFactory();
}
@Test
public void testEntityManagerCanBeUnwrappedToSessionFactory() {
SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class );
assertNotNull( "Unwrapping to API class SessionFactory should be ok", sessionFactory );
}
@Test
public void testEntityManagerCanBeUnwrappedToSessionFactoryImplementor() {
SessionFactoryImplementor sessionFactoryImplementor = entityManagerFactory.unwrap( SessionFactoryImplementor.class );
assertNotNull( "Unwrapping to SPI class SessionFactoryImplementor should be ok", sessionFactoryImplementor );
}
@Test
public void testEntityManagerCanBeUnwrappedToDeprecatedHibernateEntityManagerFactory() {
HibernateEntityManagerFactory hibernateEntityManagerFactory = entityManagerFactory.unwrap(
HibernateEntityManagerFactory.class
);
assertNotNull(
"Unwrapping to SPI class HibernateEntityManagerFactory should be ok",
hibernateEntityManagerFactory
);
}
@Test
public void testEntityManagerCanBeUnwrappedToHibernateEntityManagerFactory() {
org.hibernate.jpa.HibernateEntityManagerFactory hibernateEntityManagerFactory = entityManagerFactory.unwrap( org.hibernate.jpa.HibernateEntityManagerFactory.class );
assertNotNull(
"Unwrapping to SPI class HibernateEntityManagerFactory should be ok",
hibernateEntityManagerFactory
);
}
@Test
public void testEntityManagerCanBeUnwrappedToObject() {
Object object = entityManagerFactory.unwrap( Object.class );
assertNotNull( "Unwrapping to public super type Object should work", object );
}
@Test
public void testEntityManagerCanBeUnwrappedToSessionFactoryImpl() {
SessionFactoryImpl sessionFactory = entityManagerFactory.unwrap( SessionFactoryImpl.class );
assertNotNull(
"Unwrapping to SessionFactoryImpl should be ok",
sessionFactory
);
}
@Test
public void testEntityManagerCannotBeUnwrappedToUnrelatedType() {
try {
entityManagerFactory.unwrap( EntityManager.class );
fail( "It should not be possible to unwrap to unrelated type." );
}
catch ( PersistenceException e ) {
// ignore
}
}
}

View File

@ -1,172 +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.orphan.onetomany;
import java.util.List;
import javax.persistence.EntityManager;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import static org.junit.Assert.assertEquals;
/**
* @author Gail Badner
*/
public class DeleteOneToManyOrphansTest extends BaseEntityManagerFunctionalTestCase {
private void createData() {
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
Feature newFeature = new Feature();
newFeature.setName("Feature 1");
entityManager.persist( newFeature );
Product product = new Product();
newFeature.setProduct( product );
product.getFeatures().add( newFeature );
entityManager.persist( product );
entityManager.getTransaction().commit();
entityManager.clear();
}
private void cleanupData() {
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
entityManager.createQuery( "delete Feature" ).executeUpdate();
entityManager.createQuery( "delete Product" ).executeUpdate();
entityManager.getTransaction().commit();
entityManager.close();
}
@Test
@TestForIssue( jiraKey = "HHH-9568")
@FailureExpected( jiraKey = "HHH-9568" )
public void testOrphanedWhileManaged() {
createData();
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 1, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
Product product = ( Product ) results.get( 0 );
assertEquals( 1, product.getFeatures().size() );
product.getFeatures().clear();
entityManager.getTransaction().commit();
entityManager.close();
entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
product = entityManager.find( Product.class, product.getId() );
assertEquals( 0, product.getFeatures().size() );
results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 0, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
entityManager.getTransaction().commit();
entityManager.close();
cleanupData();
}
@Test
@TestForIssue( jiraKey = "HHH-9568")
@FailureExpected( jiraKey = "HHH-9568" )
public void testOrphanedWhileManagedMergeOwner() {
createData();
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 1, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
Product product = ( Product ) results.get( 0 );
assertEquals( 1, product.getFeatures().size() );
product.getFeatures().clear();
entityManager.merge( product );
entityManager.getTransaction().commit();
entityManager.close();
entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
product = entityManager.find( Product.class, product.getId() );
assertEquals( 0, product.getFeatures().size() );
results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 0, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
entityManager.getTransaction().commit();
entityManager.close();
cleanupData();
}
@Test
@TestForIssue( jiraKey = "HHH-9568")
@FailureExpected( jiraKey = "HHH-9568" )
public void testReplacedWhileManaged() {
createData();
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 1, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
Product product = ( Product ) results.get( 0 );
assertEquals( 1, product.getFeatures().size() );
// Replace with a new Feature instance
product.getFeatures().remove( 0 );
Feature featureNew = new Feature();
featureNew.setName( "Feature 2" );
featureNew.setProduct( product );
product.getFeatures().add( featureNew );
entityManager.persist( featureNew );
entityManager.getTransaction().commit();
entityManager.close();
entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 1, results.size() );
Feature featureQueried = (Feature) results.get( 0 );
assertEquals( featureNew.getId(), featureQueried.getId() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
Product productQueried = (Product) results.get( 0 );
assertEquals( 1, productQueried.getFeatures().size() );
assertEquals( featureQueried, productQueried.getFeatures().get( 0 ) );
entityManager.getTransaction().commit();
entityManager.close();
cleanupData();
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[]{
Product.class,
Feature.class
};
}
}

View File

@ -1,187 +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.orphan.onetomany;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.Hibernate;
import org.hibernate.cfg.Environment;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/**
* @author Andrea Boriero
*/
public class DeleteSharedOneToManyOrphansTest extends BaseEntityManagerFunctionalTestCase {
/*
A value of BATCH_FETCH_SIZE > 1 along with the initialization of the Item#higherItemRelations
collection causes the issue
*/
private static final String BATCH_FETCH_SIZE = "2";
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {Item.class, ItemRelation.class};
}
@Override
protected void addConfigOptions(Map options) {
options.put( Environment.DEFAULT_BATCH_FETCH_SIZE, BATCH_FETCH_SIZE );
}
@Before
public void prepareTest() throws Exception {
doInJPA( this::entityManagerFactory, entityManager -> {
final Item item1 = new Item( "first" );
entityManager.persist( item1 );
final Item item2 = new Item( "second" );
entityManager.persist( item2 );
final ItemRelation rel = new ItemRelation();
item1.addLowerItemRelations( rel );
item2.addHigherItemRelations( rel );
entityManager.persist( rel );
} );
}
@After
public void cleanupTest() throws Exception {
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.createQuery( "delete from ItemRelation" ).executeUpdate();
entityManager.createQuery( "delete from Item" ).executeUpdate();
} );
}
@Test
@TestForIssue(jiraKey = "HHH-11144")
@FailureExpected( jiraKey = "HHH-11144" )
public void testInitializingSecondCollection() {
doInJPA( this::entityManagerFactory, entityManager -> {
Item item = entityManager.createQuery( "select x from Item x where x.code = 'first'", Item.class )
.getSingleResult();
Set<ItemRelation> lowerItemRelations = item.getLowerItemRelations();
Hibernate.initialize( lowerItemRelations );
Set<ItemRelation> higherItemRelations = item.getHigherItemRelations();
Hibernate.initialize( higherItemRelations );
Assert.assertEquals( 1, lowerItemRelations.size() );
lowerItemRelations.clear();
} );
checkLowerItemRelationsAreDeleted();
}
private void checkLowerItemRelationsAreDeleted() {
doInJPA( this::entityManagerFactory, entityManager -> {
Item item = entityManager.createQuery( "select x from Item x where x.code = 'first'", Item.class )
.getSingleResult();
Set<ItemRelation> lowerItemRelations = item.getLowerItemRelations();
Hibernate.initialize( lowerItemRelations );
Assert.assertEquals( "The collection should be empty", 0, lowerItemRelations.size() );
} );
}
@Entity(name = "Item")
public static class Item {
@Id
@GeneratedValue
protected Long id;
@Column
protected String code;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
protected Set<ItemRelation> lowerItemRelations = new LinkedHashSet<>();
@OneToMany(mappedBy = "child", cascade = CascadeType.ALL, orphanRemoval = true)
protected Set<ItemRelation> higherItemRelations = new LinkedHashSet<>();
public Item() {
}
public Item(String code) {
this.code = code;
}
public Set<ItemRelation> getLowerItemRelations() {
return lowerItemRelations;
}
public Set<ItemRelation> getHigherItemRelations() {
return higherItemRelations;
}
public void addHigherItemRelations(ItemRelation itemRelation) {
higherItemRelations.add( itemRelation );
itemRelation.setChild( this );
}
public void addLowerItemRelations(ItemRelation itemRelation) {
lowerItemRelations.add( itemRelation );
itemRelation.setParent( this );
}
}
@Entity(name = "ItemRelation")
public static class ItemRelation {
@Id
@GeneratedValue
protected Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "PARENT_ID")
private Item parent;
@ManyToOne(optional = false)
@JoinColumn(name = "CHILD_ID")
private Item child;
public Item getParent() {
return parent;
}
public void setParent(Item parent) {
this.parent = parent;
}
public Item getChild() {
return child;
}
public void setChild(Item child) {
this.child = child;
}
}
}

View File

@ -1,59 +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.orphan.onetoone;
import javax.persistence.EntityManager;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import static org.junit.Assert.fail;
/**
* @author Martin Simka
* @author Gail Badner
*/
public class OneToOneOrphanTest extends BaseEntityManagerFunctionalTestCase {
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
A.class,
B.class
};
}
@Test
@TestForIssue(jiraKey = "HHH-9568")
public void testFlushTransientOneToOneNoCascade() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
B b = new B();
A a = new A();
a.setB(b);
try {
em.persist( a );
em.flush();
em.getTransaction().commit();
fail( "should have raised an IllegalStateException" );
}
catch (IllegalStateException ex) {
if ( em.getTransaction().isActive() ) {
em.getTransaction().rollback();
}
// IllegalStateException caught as expected
}
finally {
em.close();
}
}
}

View File

@ -1,59 +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.refresh;
import java.util.Map;
import javax.persistence.EntityManager;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-11188")
public class RefreshDetachedInstanceWhenIsAllowedTest extends BaseEntityManagerFunctionalTestCase {
private TestEntity testEntity;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {TestEntity.class};
}
@Override
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY, "true" );
}
@Before
public void setUp() {
testEntity = new TestEntity();
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.persist( testEntity );
} );
}
@Test
public void testUnwrappedSessionRefreshDetachedInstance() {
final EntityManager entityManager = createEntityManager();
final Session session = entityManager.unwrap( Session.class );
session.refresh( testEntity );
}
@Test
public void testRefreshDetachedInstance() {
final EntityManager entityManager = createEntityManager();
entityManager.refresh( testEntity );
}
}

View File

@ -1,50 +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.refresh;
import javax.persistence.EntityManager;
import org.hibernate.Session;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/**
* @author Andrea Boriero
*/
public class RefreshDetachedInstanceWhenIsNotAllowedTest extends BaseEntityManagerFunctionalTestCase {
private TestEntity testEntity;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {TestEntity.class};
}
@Before
public void setUp() {
testEntity = new TestEntity();
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.persist( testEntity );
} );
}
@Test(expected = IllegalArgumentException.class)
public void testUnwrappedSessionRefreshDetachedInstance() {
final EntityManager entityManager = createEntityManager();
final Session session = entityManager.unwrap( Session.class );
session.refresh( testEntity );
}
@Test(expected = IllegalArgumentException.class)
public void testRefreshDetachedInstance() {
final EntityManager entityManager = createEntityManager();
entityManager.refresh( testEntity );
}
}

View File

@ -1,53 +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.schemagen;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.TypedQuery;
import java.util.List;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-10104")
public class SchemaCreateDropTest extends BaseEntityManagerFunctionalTestCase {
private EntityManager em;
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {Document.class};
}
@Before
public void setUp() {
em = getOrCreateEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist( new Document( "hibernate" ) );
tx.commit();
}
@Test
public void testQueryWithoutTransaction() {
TypedQuery<String> query = em.createQuery( "SELECT d.name FROM Document d", String.class );
List<String> results = query.getResultList();
assertThat( results.size(), is( 1 ) );
}
}

View File

@ -10,7 +10,7 @@ import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.test.schemagen.JpaSchemaGeneratorTest;
import org.hibernate.orm.test.jpa.schemagen.JpaSchemaGeneratorTest;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;

View File

@ -10,7 +10,7 @@ import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.test.schemagen.JpaSchemaGeneratorTest;
import org.hibernate.orm.test.jpa.schemagen.JpaSchemaGeneratorTest;
import org.hibernate.testing.RequiresDialect;

View File

@ -7,7 +7,7 @@
package org.hibernate.jpa.test.schemagen.iso8859;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.test.schemagen.JpaSchemaGeneratorTest;
import org.hibernate.orm.test.jpa.schemagen.JpaSchemaGeneratorTest;
import org.hibernate.testing.RequiresDialect;

View File

@ -9,7 +9,7 @@ package org.hibernate.jpa.test.schemagen.iso8859;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.test.schemagen.SchemaCreateDropUtf8WithoutHbm2DdlCharsetNameTest;
import org.hibernate.orm.test.jpa.schemagen.SchemaCreateDropUtf8WithoutHbm2DdlCharsetNameTest;
/**
* @author Vlad Mihalcea

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.statistics;
import java.util.Map;
import javax.persistence.EntityManager;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.stat.Statistics;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-11602")
public class SessionCloseCountTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.GENERATE_STATISTICS, "true" );
}
@Test
public void sessionCountClosetShouldBeIncrementedWhenTheEntityManagerIsClosed() {
final SessionFactoryImplementor entityManagerFactory = entityManagerFactory();
final Statistics statistics = entityManagerFactory.unwrap( SessionFactory.class ).getStatistics();
EntityManager em = createEntityManager();
assertThat( "The session close count should be zero", statistics.getSessionCloseCount(), is( 0L ) );
em.close();
assertThat( "The session close count was not incremented", statistics.getSessionCloseCount(), is( 1L ) );
}
}

View File

@ -1,100 +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.temporal;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Query;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
/**
* @author Brett Meyer
*/
public class TemporalTypeTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testTemporalType() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Date date = new Date();
Calendar calendar = Calendar.getInstance();
DataPoint dp = new DataPoint();
dp.date1 = date;
dp.date2 = date;
dp.calendar1 = calendar;
dp.calendar2 = calendar;
em.persist( dp );
em.getTransaction().commit();
em.close();
doTest("date1", date);
doTest("date1", calendar);
doTest("date2", date);
doTest("date2", calendar);
doTest("calendar1", date);
doTest("calendar1", calendar);
doTest("calendar2", date);
doTest("calendar2", calendar);
}
private void doTest(String property, Object obj) {
doTest( property, obj, TemporalType.DATE );
doTest( property, obj, TemporalType.TIMESTAMP );
}
private void doTest(String property, Object obj, TemporalType temporalType) {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Query query = em.createQuery("from DataPoint where " + property + " = :obj");
if (obj instanceof Calendar) {
query.setParameter("obj", (Calendar) obj, temporalType);
}
else {
query.setParameter("obj", (Date) obj, temporalType);
}
em.getTransaction().commit();
em.close();
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { DataPoint.class };
}
@Entity(name = "DataPoint")
private static class DataPoint {
@Id @GeneratedValue
public long id;
@Temporal( TemporalType.DATE )
public Date date1;
@Temporal( TemporalType.TIMESTAMP )
public Date date2;
@Temporal( TemporalType.DATE )
public Calendar calendar1;
@Temporal( TemporalType.TIMESTAMP )
public Calendar calendar2;
}
}

View File

@ -1,147 +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.transaction.batch;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.FlushModeType;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl;
import org.hibernate.engine.jdbc.batch.internal.BatchingBatch;
import org.hibernate.engine.jdbc.batch.spi.Batch;
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-13050")
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class JtaWithStatementsBatchTest extends AbstractJtaBatchTest {
private static TestBatch testBatch;
@Test
public void testUnableToReleaseStatementMessageIsNotLogged()
throws Exception {
TransactionManager transactionManager = TestingJtaPlatformImpl.INSTANCE.getTransactionManager();
EntityManager em = createEntityManager();
try {
transactionManager.begin();
em.setFlushMode( FlushModeType.AUTO );
// Persist entity with non-generated id
EventLog eventLog1 = new EventLog();
eventLog1.setMessage( "Foo1" );
em.persist( eventLog1 );
// Persist entity with non-generated id
EventLog eventLog2 = new EventLog();
eventLog2.setMessage( "Foo2" );
em.persist( eventLog2 );
Comment comment = new Comment();
comment.setMessage( "Bar" );
em.persist( comment );
transactionManager.commit();
assertStatementsListIsCleared();
assertAllStatementsAreClosed( testBatch.createtdStatements );
}
finally {
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
transactionManager.rollback();
}
em.close();
}
assertFalse( "HHH000352: Unable to release batch statement... has been thrown", triggerable.wasTriggered() );
em = createEntityManager();
try {
transactionManager.begin();
Integer savedComments
= em.createQuery( "from Comment" ).getResultList().size();
assertThat( savedComments, is( 1 ) );
Integer savedEventLogs
= em.createQuery( "from EventLog" ).getResultList().size();
assertThat( savedEventLogs, is( 2 ) );
}
finally {
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
transactionManager.rollback();
}
em.close();
}
}
private void assertStatementsListIsCleared() {
assertThat( testBatch.createtdStatements.size(), not( 0 ) );
assertThat(
"Not all PreparedStatements have been released",
testBatch.numberOfStatementsAfterReleasing,
is( 0 )
);
}
public static class TestBatch extends BatchingBatch {
private int numberOfStatementsAfterReleasing;
private List<PreparedStatement> createtdStatements = new ArrayList<>();
public TestBatch(BatchKey key, JdbcCoordinator jdbcCoordinator, int batchSize) {
super( key, jdbcCoordinator, batchSize );
}
protected void releaseStatements() {
createtdStatements.addAll( getStatements().values() );
super.releaseStatements();
numberOfStatementsAfterReleasing += getStatements().size();
}
}
@Override
protected String getBatchBuilderClassName() {
return TestBatchBuilder.class.getName();
}
public static class TestBatchBuilder extends BatchBuilderImpl {
private int jdbcBatchSize;
@Override
public void setJdbcBatchSize(int jdbcBatchSize) {
this.jdbcBatchSize = jdbcBatchSize;
}
@Override
public Batch buildBatch(BatchKey key, JdbcCoordinator jdbcCoordinator) {
return buildBatchTest( key, jdbcCoordinator, jdbcBatchSize );
}
protected BatchingBatch buildBatchTest(BatchKey key, JdbcCoordinator jdbcCoordinator, int jdbcBatchSize) {
testBatch = new TestBatch( key, jdbcCoordinator, jdbcBatchSize );
return testBatch;
}
}
}

View File

@ -1,41 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.xml;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
/**
* @author <a href="mailto:stliu@hibernate.org">Strong Liu</a>
*/
@TestForIssue( jiraKey = "HHH-6039, HHH-6100" )
public class JpaEntityNameTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected String[] getMappings() {
return new String[] { "org/hibernate/jpa/test/xml/Qualifier.hbm.xml" };
}
@Test
public void testUsingSimpleHbmInJpa(){
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Qualifier> cq = cb.createQuery(Qualifier.class);
Root<Qualifier> qualifRoot = cq.from(Qualifier.class);
cq.where( cb.equal( qualifRoot.get( "qualifierId" ), 32l ) );
em.createQuery(cq).getResultList();
em.getTransaction().commit();
em.close();
}
}

View File

@ -1,84 +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.xml;
import javax.persistence.EntityManager;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import static org.junit.Assert.assertEquals;
/**
* @author Emmanuel Bernard
*/
public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testAttributeOverriding() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Employee e = new Employee();
e.setId(Long.valueOf(100));
e.setName("Bubba");
e.setHomeAddress(new Address("123 Main St", "New York", "NY", "11111"));
e.setMailAddress(new Address("P.O. Box 123", "New York", "NY", "11111"));
em.persist(e);
em.flush();
em.getTransaction().rollback();
em.close();
}
@Test
public void testDefaultEventListener() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CounterListener.reset();
Employee e = new Employee();
e.setId(Long.valueOf(100));
e.setName("Bubba");
e.setHomeAddress(new Address("123 Main St", "New York", "NY", "11111"));
e.setMailAddress(new Address("P.O. Box 123", "New York", "NY", "11111"));
em.persist(e);
em.flush();
em.clear();
em.find( Employee.class, e.getId() ).setName( "Bibo" );
em.flush();
em.clear();
em.remove( em.find( Employee.class, e.getId() ) );
em.flush();
em.getTransaction().rollback();
em.close();
assertEquals( 1, CounterListener.insert );
assertEquals( 1, CounterListener.update );
assertEquals( 1, CounterListener.delete );
}
@Override
public String[] getEjb3DD() {
return new String[] {
"org/hibernate/jpa/test/xml/orm3.xml"
};
}
}

View File

@ -1,55 +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.xml;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.SharedCacheMode;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.persister.entity.EntityPersister;
import org.junit.Test;
import junit.framework.Assert;
/**
* @author Emmanuel Bernard
*/
public class XmlTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testXmlMappingCorrectness() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.close();
}
@Test
public void testXmlMappingWithCacheable() throws Exception{
EntityManager em = getOrCreateEntityManager();
SharedSessionContractImplementor session = em.unwrap( SharedSessionContractImplementor.class );
EntityPersister entityPersister= session.getFactory().getEntityPersister( Lighter.class.getName() );
Assert.assertTrue(entityPersister.hasCache());
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[0];
}
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
}
@Override
public String[] getEjb3DD() {
return new String[] {
"org/hibernate/jpa/test/xml/orm.xml",
"org/hibernate/jpa/test/xml/orm2.xml",
};
}
}

View File

@ -1,44 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.xml.sequences;
import javax.persistence.EntityManager;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
/**
* @author Emmanuel Bernard
*/
public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testAttributeOverriding() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Employee e = new Employee();
e.setId(Long.valueOf(100));
e.setName("Bubba");
e.setHomeAddress(new Address("123 Main St", "New York", "NY", "11111"));
e.setMailAddress(new Address("P.O. Box 123", "New York", "NY", "11111"));
em.persist(e);
em.flush();
em.getTransaction().rollback();
em.close();
}
@Override
public String[] getEjb3DD() {
return new String[] {
"org/hibernate/jpa/test/xml/sequences/orm3.xml"
};
}
}

View File

@ -1,36 +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.xml.sequences;
import javax.persistence.EntityManager;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
/**
* @author Emmanuel Bernard
*/
@RequiresDialectFeature( DialectChecks.SupportsSequences.class )
public class XmlTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testXmlMappingCorrectness() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.close();
}
@Override
public String[] getEjb3DD() {
return new String[] {
"org/hibernate/jpa/test/xml/sequences/orm.xml",
"org/hibernate/jpa/test/xml/sequences/orm2.xml",
};
}
}

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;
package org.hibernate.orm.test.jpa;
import java.io.Serializable;
import javax.persistence.Embeddable;

View File

@ -0,0 +1,38 @@
package org.hibernate.orm.test.jpa;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
@TestForIssue( jiraKey = "HHH-9029")
@Jpa(annotatedClasses = {
EntityWithCompositeId.class,
CompositeId.class
})
public class CompositeIdRowValueTest {
@Test
public void testTupleAfterSubQuery(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Query q = entityManager.createQuery("SELECT e FROM EntityWithCompositeId e "
+ "WHERE EXISTS (SELECT 1 FROM EntityWithCompositeId) "
+ "AND e.id = :id");
q.setParameter("id", new CompositeId(1, 2));
assertThat(q.getResultList().size(), is(0));
}
);
}
}

View File

@ -0,0 +1,38 @@
/*
* 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;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;
@Jpa(annotatedClasses = {
EntityWithCompositeId.class,
CompositeId.class
})
public class CountEntityWithCompositeIdTest {
@Test
public void shouldCount(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<EntityWithCompositeId> r = cq.from(EntityWithCompositeId.class);
cq.multiselect(cb.count(r));
assertThat(entityManager.createQuery(cq).getSingleResult().intValue(), is(0));
}
);
}
}

View File

@ -0,0 +1,85 @@
/*
* 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>.
*/
//$Id$
package org.hibernate.orm.test.jpa;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import org.hibernate.SessionFactory;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test various unwrap scenarios for {@code EntityManagerFactory}.
*/
@TestForIssue(jiraKey = "HHH-9665")
@Jpa
public class EntityManagerFactoryUnwrapTest {
@Test
public void testEntityManagerCanBeUnwrappedToSessionFactory(EntityManagerFactoryScope scope) {
SessionFactory sessionFactory = scope.getEntityManagerFactory().unwrap( SessionFactory.class );
assertNotNull( sessionFactory, "Unwrapping to API class SessionFactory should be ok" );
}
@Test
public void testEntityManagerCanBeUnwrappedToSessionFactoryImplementor(EntityManagerFactoryScope scope) {
SessionFactoryImplementor sessionFactoryImplementor = scope.getEntityManagerFactory().unwrap( SessionFactoryImplementor.class );
assertNotNull( sessionFactoryImplementor, "Unwrapping to SPI class SessionFactoryImplementor should be ok" );
}
@Test
public void testEntityManagerCanBeUnwrappedToDeprecatedHibernateEntityManagerFactory(EntityManagerFactoryScope scope) {
HibernateEntityManagerFactory hibernateEntityManagerFactory = scope.getEntityManagerFactory().unwrap(
HibernateEntityManagerFactory.class
);
assertNotNull( hibernateEntityManagerFactory, "Unwrapping to SPI class HibernateEntityManagerFactory should be ok" );
}
@Test
public void testEntityManagerCanBeUnwrappedToHibernateEntityManagerFactory(EntityManagerFactoryScope scope) {
org.hibernate.jpa.HibernateEntityManagerFactory hibernateEntityManagerFactory = scope.getEntityManagerFactory().unwrap(
org.hibernate.jpa.HibernateEntityManagerFactory.class );
assertNotNull( hibernateEntityManagerFactory, "Unwrapping to SPI class HibernateEntityManagerFactory should be ok" );
}
@Test
public void testEntityManagerCanBeUnwrappedToObject(EntityManagerFactoryScope scope) {
Object object = scope.getEntityManagerFactory().unwrap( Object.class );
assertNotNull( object, "Unwrapping to public super type Object should work" );
}
@Test
public void testEntityManagerCanBeUnwrappedToSessionFactoryImpl(EntityManagerFactoryScope scope) {
SessionFactoryImpl sessionFactory = scope.getEntityManagerFactory().unwrap( SessionFactoryImpl.class );
assertNotNull( sessionFactory, "Unwrapping to SessionFactoryImpl should be ok" );
}
@Test
public void testEntityManagerCannotBeUnwrappedToUnrelatedType(EntityManagerFactoryScope scope) {
try {
scope.getEntityManagerFactory().unwrap( EntityManager.class );
fail( "It should not be possible to unwrap to unrelated type." );
}
catch ( PersistenceException e ) {
// ignore
}
}
}

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;
package org.hibernate.orm.test.jpa;
import java.io.Serializable;
import javax.persistence.EmbeddedId;

View File

@ -4,15 +4,12 @@
* 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;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
package org.hibernate.orm.test.jpa;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.Column;
@ -30,58 +27,54 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.TestForIssue;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@TestForIssue(jiraKey = "HHH-13244")
public class JpaProxyComplianceWithDebug extends BaseEntityManagerFunctionalTestCase {
@Jpa(
annotatedClasses = {
JpaProxyComplianceWithDebugTest.MvnoBillingAgreement.class,
JpaProxyComplianceWithDebugTest.MvnoOpcio.class,
},
integrationSettings = { @Setting(name = AvailableSettings.JPA_PROXY_COMPLIANCE, value = "true") }
)
public class JpaProxyComplianceWithDebugTest {
@Override
protected void addConfigOptions(Map options) {
options.put(
AvailableSettings.JPA_PROXY_COMPLIANCE,
Boolean.TRUE);
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
MvnoBillingAgreement.class,
MvnoOpcio.class,
};
}
@Before
public void setUp() {
@BeforeAll
public void setUp(EntityManagerFactoryScope scope) {
List<Integer> opciok = Arrays.asList(2008, 2010, 2012, 2014, 2015, 2026, 2027, 2103, 2110, 2145, 992068, 992070);
doInJPA(this::entityManagerFactory, entityManager -> {
scope.inTransaction(
entityManager -> {
MvnoBillingAgreement ba = new MvnoBillingAgreement();
ba.setId(1);
ba.setName("1");
entityManager.persist(ba);
MvnoBillingAgreement ba = new MvnoBillingAgreement();
ba.setId(1);
ba.setName("1");
entityManager.persist(ba);
for (int opcioId : opciok) {
MvnoOpcio o = new MvnoOpcio();
o.setId(opcioId);
o.setMegnevezes(Integer.toString(opcioId));
o.getMvnoBillingAgreementekDefaultOpcioja().add(ba);
ba.getMvnoDefaultUniverzalisOpcioi().add(o);
entityManager.persist(o);
}
for (int opcioId : opciok) {
MvnoOpcio o = new MvnoOpcio();
o.setId(opcioId);
o.setMegnevezes(Integer.toString(opcioId));
o.getMvnoBillingAgreementekDefaultOpcioja().add(ba);
ba.getMvnoDefaultUniverzalisOpcioi().add(o);
entityManager.persist(o);
}
ba.setBehajtasEgyiranyusitasOpcio(entityManager.find(MvnoOpcio.class, 2026));
ba.setBehajtasFelfuggesztesOpcio(entityManager.find(MvnoOpcio.class, 992070));
ba.setHotlimitEmeltDijasBarOpcio(entityManager.find(MvnoOpcio.class, 2145));
});
ba.setBehajtasEgyiranyusitasOpcio(entityManager.find(MvnoOpcio.class, 2026));
ba.setBehajtasFelfuggesztesOpcio(entityManager.find(MvnoOpcio.class, 992070));
ba.setHotlimitEmeltDijasBarOpcio(entityManager.find(MvnoOpcio.class, 2145));
}
);
}
@Test
@TestForIssue(jiraKey = "HHH-13244")
public void testJpaComplianceProxyWithDebug() {
public void testJpaComplianceProxyWithDebug(EntityManagerFactoryScope scope) {
//This could be replaced with setting the root logger level, or the "org.hibernate" logger to debug.
//These are simply the narrowest log settings that trigger the bug
@ -91,17 +84,16 @@ public class JpaProxyComplianceWithDebug extends BaseEntityManagerFunctionalTest
Level oldEntityLogLevel = entityLogger.getLevel();
Level oldListenerLogLevel = listenerLogger.getLevel();
entityLogger.setLevel((Level) Level.DEBUG);
listenerLogger.setLevel((Level) Level.DEBUG);
entityLogger.setLevel(Level.DEBUG);
listenerLogger.setLevel(Level.DEBUG);
try {
doInJPA(this::entityManagerFactory, entityManager -> {
entityManager.find(MvnoBillingAgreement.class, 1);
});
scope.inTransaction(
entityManager -> entityManager.find( MvnoBillingAgreement.class, 1)
);
} finally {
entityLogger.setLevel(oldEntityLogLevel);
listenerLogger.setLevel(oldListenerLogLevel);
}
}
@Entity
@ -185,7 +177,6 @@ public class JpaProxyComplianceWithDebug extends BaseEntityManagerFunctionalTest
public void setHotlimitEmeltDijasBarOpcio(MvnoOpcio hotlimitEmeltDijasBarOpcio) {
this.hotlimitEmeltDijasBarOpcio = hotlimitEmeltDijasBarOpcio;
}
}
@Entity
@ -227,8 +218,5 @@ public class JpaProxyComplianceWithDebug extends BaseEntityManagerFunctionalTest
public void setMvnoBillingAgreementekDefaultOpcioja(Set<MvnoBillingAgreement> mvnoBillingAgreementekDefaultOpcioja) {
this.mvnoBillingAgreementekDefaultOpcioja = mvnoBillingAgreementekDefaultOpcioja;
}
}
}

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.EntityManagerFactory;

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

@ -27,8 +27,8 @@ import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.hibernate.jpa.test.Distributor;
import org.hibernate.jpa.test.Item;
import org.hibernate.jpa.test.xml.Light;
import org.hibernate.jpa.test.xml.Lighter;
import org.hibernate.orm.test.jpa.xml.Light;
import org.hibernate.orm.test.jpa.xml.Lighter;
import org.hibernate.testing.util.jpa.PersistenceUnitInfoAdapter;
import org.junit.jupiter.api.Assertions;

View File

@ -7,7 +7,6 @@
package org.hibernate.orm.test.jpa.mapping;
import java.util.Arrays;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@ -19,7 +18,6 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.jpa.NonStringValueSettingProvider;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

View File

@ -15,8 +15,6 @@ import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
@ -27,10 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12273")
@Jpa(
annotatedClasses = Workload.class,
integrationSettings = { @Setting(name = AvailableSettings.JPA_PROXY_COMPLIANCE, value = "false") }
)
public class GetLoadJpaComplianceDifferentSessionsTest extends EntityManagerFactoryBasedFunctionalTest {
@Override
@ -87,6 +81,4 @@ public class GetLoadJpaComplianceDifferentSessionsTest extends EntityManagerFact
assertEquals( "Package", _workload.getName() );
}
}

View File

@ -0,0 +1,154 @@
/*
* 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.orphan.onetomany;
import java.util.List;
import org.hibernate.testing.TestForIssue;
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.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Gail Badner
*/
@Jpa(annotatedClasses = {
Product.class,
Feature.class
})
public class DeleteOneToManyOrphansTest {
@BeforeEach
public void createData(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Feature newFeature = new Feature();
newFeature.setName("Feature 1");
entityManager.persist( newFeature );
Product product = new Product();
newFeature.setProduct( product );
product.getFeatures().add( newFeature );
entityManager.persist( product );
}
);
}
@AfterEach
public void cleanupData(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete Feature" ).executeUpdate();
entityManager.createQuery( "delete Product" ).executeUpdate();
}
);
}
@Test
@TestForIssue( jiraKey = "HHH-9568")
@FailureExpected( jiraKey = "HHH-9568" )
public void testOrphanedWhileManaged(EntityManagerFactoryScope scope) {
Long productId = scope.fromTransaction(
entityManager -> {
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 1, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
Product product = ( Product ) results.get( 0 );
assertEquals( 1, product.getFeatures().size() );
product.getFeatures().clear();
return product.getId();
}
);
scope.inTransaction(
entityManager -> {
Product _product = entityManager.find( Product.class, productId );
assertEquals( 0, _product.getFeatures().size() );
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 0, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
}
);
}
@Test
@TestForIssue( jiraKey = "HHH-9568")
@FailureExpected( jiraKey = "HHH-9568" )
public void testOrphanedWhileManagedMergeOwner(EntityManagerFactoryScope scope) {
Long productId = scope.fromTransaction(
entityManager -> {
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 1, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
Product product = ( Product ) results.get( 0 );
assertEquals( 1, product.getFeatures().size() );
product.getFeatures().clear();
entityManager.merge( product );
return product.getId();
}
);
scope.inTransaction(
entityManager -> {
Product _product = entityManager.find( Product.class, productId );
assertEquals( 0, _product.getFeatures().size() );
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 0, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
}
);
}
@Test
@TestForIssue( jiraKey = "HHH-9568")
@FailureExpected( jiraKey = "HHH-9568" )
public void testReplacedWhileManaged(EntityManagerFactoryScope scope) {
Long featureNewId = scope.fromTransaction(
entityManager -> {
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 1, results.size() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
Product product = ( Product ) results.get( 0 );
assertEquals( 1, product.getFeatures().size() );
// Replace with a new Feature instance
product.getFeatures().remove( 0 );
Feature featureNew = new Feature();
featureNew.setName( "Feature 2" );
featureNew.setProduct( product );
product.getFeatures().add( featureNew );
entityManager.persist( featureNew );
return featureNew.getId();
}
);
scope.inTransaction(
entityManager -> {
List results = entityManager.createQuery( "from Feature" ).getResultList();
assertEquals( 1, results.size() );
Feature featureQueried = (Feature) results.get( 0 );
assertEquals( featureNewId, featureQueried.getId() );
results = entityManager.createQuery( "from Product" ).getResultList();
assertEquals( 1, results.size() );
Product productQueried = (Product) results.get( 0 );
assertEquals( 1, productQueried.getFeatures().size() );
assertEquals( featureQueried, productQueried.getFeatures().get( 0 ) );
}
);
}
}

View File

@ -0,0 +1,187 @@
/*
* 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.orphan.onetomany;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.Hibernate;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
/**
* @author Andrea Boriero
*/
@Jpa(
annotatedClasses = {
DeleteSharedOneToManyOrphansTest.Item.class,
DeleteSharedOneToManyOrphansTest.ItemRelation.class
},
integrationSettings = { @Setting(name = Environment.DEFAULT_BATCH_FETCH_SIZE, value = "2") }
)
public class DeleteSharedOneToManyOrphansTest {
/*
A value of DEFAULT_BATCH_FETCH_SIZE > 1 along with the initialization of the Item#higherItemRelations
collection causes the issue
*/
@BeforeEach
public void prepareTest(EntityManagerFactoryScope scope) throws Exception {
scope.inTransaction(
entityManager -> {
final Item item1 = new Item( "first" );
entityManager.persist( item1 );
final Item item2 = new Item( "second" );
entityManager.persist( item2 );
final ItemRelation rel = new ItemRelation();
item1.addLowerItemRelations( rel );
item2.addHigherItemRelations( rel );
entityManager.persist( rel );
}
);
}
@AfterEach
public void cleanupTest(EntityManagerFactoryScope scope) throws Exception {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from ItemRelation" ).executeUpdate();
entityManager.createQuery( "delete from Item" ).executeUpdate();
}
);
}
@Test
@TestForIssue(jiraKey = "HHH-11144")
@FailureExpected( jiraKey = "HHH-11144" )
public void testInitializingSecondCollection(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Item item = entityManager.createQuery( "select x from Item x where x.code = 'first'", Item.class )
.getSingleResult();
Set<ItemRelation> lowerItemRelations = item.getLowerItemRelations();
Hibernate.initialize( lowerItemRelations );
Set<ItemRelation> higherItemRelations = item.getHigherItemRelations();
Hibernate.initialize( higherItemRelations );
Assertions.assertEquals( 1, lowerItemRelations.size() );
lowerItemRelations.clear();
}
);
checkLowerItemRelationsAreDeleted(scope);
}
private void checkLowerItemRelationsAreDeleted(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Item item = entityManager.createQuery( "select x from Item x where x.code = 'first'", Item.class )
.getSingleResult();
Set<ItemRelation> lowerItemRelations = item.getLowerItemRelations();
Hibernate.initialize( lowerItemRelations );
Assertions.assertEquals( 0, lowerItemRelations.size(), "The collection should be empty" );
}
);
}
@Entity(name = "Item")
public static class Item {
@Id
@GeneratedValue
protected Long id;
@Column
protected String code;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
protected Set<ItemRelation> lowerItemRelations = new LinkedHashSet<>();
@OneToMany(mappedBy = "child", cascade = CascadeType.ALL, orphanRemoval = true)
protected Set<ItemRelation> higherItemRelations = new LinkedHashSet<>();
public Item() {
}
public Item(String code) {
this.code = code;
}
public Set<ItemRelation> getLowerItemRelations() {
return lowerItemRelations;
}
public Set<ItemRelation> getHigherItemRelations() {
return higherItemRelations;
}
public void addHigherItemRelations(ItemRelation itemRelation) {
higherItemRelations.add( itemRelation );
itemRelation.setChild( this );
}
public void addLowerItemRelations(ItemRelation itemRelation) {
lowerItemRelations.add( itemRelation );
itemRelation.setParent( this );
}
}
@Entity(name = "ItemRelation")
public static class ItemRelation {
@Id
@GeneratedValue
protected Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "PARENT_ID")
private Item parent;
@ManyToOne(optional = false)
@JoinColumn(name = "CHILD_ID")
private Item child;
public Item getParent() {
return parent;
}
public void setParent(Item parent) {
this.parent = parent;
}
public Item getChild() {
return child;
}
public void setChild(Item child) {
this.child = child;
}
}
}

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.orphan.onetomany;
package org.hibernate.orm.test.jpa.orphan.onetomany;
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.orphan.onetomany;
package org.hibernate.orm.test.jpa.orphan.onetomany;
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.orphan.onetoone;
package org.hibernate.orm.test.jpa.orphan.onetoone;
import java.io.Serializable;
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.orphan.onetoone;
package org.hibernate.orm.test.jpa.orphan.onetoone;
import java.io.Serializable;
import javax.persistence.CascadeType;

View File

@ -0,0 +1,59 @@
/*
* 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.orphan.onetoone;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Martin Simka
* @author Gail Badner
*/
@Jpa(annotatedClasses = {
A.class,
B.class
})
public class OneToOneOrphanTest {
@Test
@TestForIssue(jiraKey = "HHH-9568")
public void testFlushTransientOneToOneNoCascade(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
entityManager.getTransaction().begin();
B b = new B();
A a = new A();
a.setB(b);
try {
entityManager.persist( a );
entityManager.flush();
entityManager.getTransaction().commit();
fail( "should have raised an IllegalStateException" );
}
catch (IllegalStateException ex) {
// IllegalStateException caught as expected
}
catch (Exception e) {
// Re-throw any other Exception that might have happened
throw e;
}
finally {
if ( entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().rollback();
}
}
}
);
}
}

View File

@ -0,0 +1,71 @@
/*
* 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.refresh;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-11188")
@Jpa(
annotatedClasses = {
TestEntity.class
},
integrationSettings = { @Setting(name = AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY, value = "true") }
)
public class RefreshDetachedInstanceWhenIsAllowedTest {
private TestEntity testEntity;
@BeforeEach
public void setUp(EntityManagerFactoryScope scope) {
testEntity = new TestEntity();
scope.inTransaction(
entityManager -> {
entityManager.persist( testEntity );
}
);
}
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from TestEntity" ).executeUpdate();
}
);
}
@Test
public void testUnwrappedSessionRefreshDetachedInstance(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
final Session session = entityManager.unwrap( Session.class );
session.refresh( testEntity );
}
);
}
@Test
public void testRefreshDetachedInstance(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
entityManager.refresh( testEntity );
}
);
}
}

View File

@ -0,0 +1,75 @@
/*
* 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.refresh;
import org.hibernate.Session;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* @author Andrea Boriero
*/
@Jpa(
annotatedClasses = {
TestEntity.class
}
)
public class RefreshDetachedInstanceWhenIsNotAllowedTest {
private TestEntity testEntity;
@BeforeEach
public void setUp(EntityManagerFactoryScope scope) {
testEntity = new TestEntity();
scope.inTransaction(
entityManager -> {
entityManager.persist( testEntity );
}
);
}
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from TestEntity" ).executeUpdate();
}
);
}
@Test
public void testUnwrappedSessionRefreshDetachedInstance(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
final Session session = entityManager.unwrap( Session.class );
Assertions.assertThrows(
IllegalArgumentException.class,
() -> session.refresh( testEntity ),
"Should have thrown an IllegalArgumentException"
);
}
);
}
@Test
public void testRefreshDetachedInstance(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Assertions.assertThrows(
IllegalArgumentException.class,
() -> entityManager.refresh( testEntity ),
"Should have thrown an IllegalArgumentException"
);
}
);
}
}

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.refresh;
package org.hibernate.orm.test.jpa.refresh;
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.schemagen;
package org.hibernate.orm.test.jpa.schemagen;
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.schemagen;
package org.hibernate.orm.test.jpa.schemagen;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

@ -4,12 +4,12 @@
* 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.schemagen;
package org.hibernate.orm.test.jpa.schemagen;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.RequiresDialect;
/**
* @author Vlad MIhalcea

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.schemagen;
package org.hibernate.orm.test.jpa.schemagen;
import java.net.URL;
import java.util.Map;
@ -15,19 +15,18 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect( H2Dialect.class )
public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase {
public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalTest {
private final String LOAD_SQL = getScriptFolderPath() + "load-script-source.sql";
private final String CREATE_SQL = getScriptFolderPath() + "create-script-source.sql";
@ -36,7 +35,7 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase
private static int schemagenNumber = 0;
public String getScriptFolderPath() {
return "org/hibernate/jpa/test/schemagen/";
return "org/hibernate/orm/test/jpa/schemagen/";
}
@Override
@ -65,14 +64,6 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase
doTest( settings );
}
protected String getResourceUrlString(String resource) {
final URL url = getClass().getClassLoader().getResource( resource );
if ( url == null ) {
throw new RuntimeException( "Unable to locate requested resource [" + resource + "]" );
}
return url.toString();
}
@SuppressWarnings("unchecked")
@Test
@TestForIssue(jiraKey = "HHH-8271")
@ -130,6 +121,18 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase
return DROP_SQL;
}
protected String encodedName() {
return "sch" + (char) 233 +"magen-test";
}
protected String getResourceUrlString(String resource) {
final URL url = getClass().getClassLoader().getResource( resource );
if ( url == null ) {
throw new RuntimeException( "Unable to locate requested resource [" + resource + "]" );
}
return url.toString();
}
@SuppressWarnings("unchecked")
private void doTest(Map settings) {
// We want a fresh db after emf close
@ -142,7 +145,7 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase
try {
EntityManager em = emf.createEntityManager();
try {
Assert.assertNotNull( em.find( Item.class, encodedName() ) );
Assertions.assertNotNull( em.find( Item.class, encodedName() ) );
}
finally {
em.close();
@ -153,14 +156,4 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase
emfb.cancel();
}
}
/* Disable hibernate schema export */
@Override
protected boolean createSchema() {
return false;
}
protected String encodedName() {
return "sch" + (char) 233 +"magen-test";
}
}

View File

@ -0,0 +1,60 @@
/*
* 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.schemagen;
import javax.persistence.TypedQuery;
import java.util.List;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
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.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-10104")
@Jpa(annotatedClasses = {
Document.class
})
public class SchemaCreateDropTest {
@BeforeEach
public void setUp(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.persist( new Document( "hibernate" ) );
}
);
}
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Document" ).executeUpdate();
}
);
}
@Test
public void testQueryWithoutTransaction(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
TypedQuery<String> query = entityManager.createQuery( "SELECT d.name FROM Document d", String.class );
List<String> results = query.getResultList();
assertThat( results.size(), is( 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.schemagen;
package org.hibernate.orm.test.jpa.schemagen;
import java.io.File;
import java.io.IOException;
@ -21,12 +21,12 @@ import org.hibernate.cfg.Environment;
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.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Vlad Mihalcea
@ -50,7 +50,7 @@ public class SchemaCreateDropUtf8WithoutHbm2DdlCharsetNameTest {
return config;
}
@Before
@BeforeEach
public void setUp() throws IOException {
createSchema = File.createTempFile( "create_schema", ".sql" );
dropSchema = File.createTempFile( "drop_schema", ".sql" );

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.schemagen;
package org.hibernate.orm.test.jpa.schemagen;
import java.io.IOException;
import java.sql.Connection;
@ -24,19 +24,19 @@ import org.hibernate.cfg.Environment;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
import org.hibernate.tool.schema.spi.SchemaManagementException;
import org.hibernate.testing.TestForIssue;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
@ -47,7 +47,7 @@ public class SchemaDatabaseFileGenerationFailureTest {
private Connection connection;
private EntityManagerFactoryBuilder entityManagerFactoryBuilder;
@Before
@BeforeEach
public void setUp() throws IOException, SQLException {
connection = Mockito.mock( Connection.class );
Statement statement = Mockito.mock( Statement.class );
@ -77,13 +77,12 @@ public class SchemaDatabaseFileGenerationFailureTest {
boolean ddlCommandFound = Pattern.compile( "drop table( if exists)? test_entity( if exists)?" )
.matcher( commandAcceptanceException.getMessage().toLowerCase() ).find();
assertTrue( "The Exception Message does not contain the DDL command causing the failure", ddlCommandFound );
assertTrue( ddlCommandFound, "The Exception Message does not contain the DDL command causing the failure" );
assertTrue( commandAcceptanceException.getCause() instanceof SQLException );
SQLException root = (SQLException) e.getCause().getCause().getCause();
assertEquals( "Expected", root.getMessage() );
}
}
@ -105,7 +104,7 @@ public class SchemaDatabaseFileGenerationFailureTest {
}
private PersistenceUnitDescriptor buildPersistenceUnitDescriptor() {
return new BaseEntityManagerFunctionalTestCase.TestingPersistenceUnitDescriptorImpl( getClass().getSimpleName() );
return new EntityManagerFactoryBasedFunctionalTest.TestingPersistenceUnitDescriptorImpl( getClass().getSimpleName() );
}
private Map getConfig() {
@ -119,5 +118,4 @@ public class SchemaDatabaseFileGenerationFailureTest {
config.put( org.hibernate.jpa.AvailableSettings.LOADED_CLASSES, classes );
return config;
}
}

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.schemagen;
package org.hibernate.orm.test.jpa.schemagen;
import java.io.IOException;
import java.io.Writer;
@ -22,17 +22,17 @@ import org.hibernate.cfg.Environment;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
import org.hibernate.tool.schema.spi.SchemaManagementException;
import org.hibernate.testing.TestForIssue;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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 Vlad Mihalcea
@ -42,7 +42,7 @@ public class SchemaScriptFileGenerationFailureTest {
private EntityManagerFactoryBuilder entityManagerFactoryBuilder;
@Before
@BeforeEach
public void setUp() {
writer = new FailingWriter();
@ -57,7 +57,7 @@ public class SchemaScriptFileGenerationFailureTest {
public void testErrorMessageContainsTheFailingDDLCommand() {
try {
entityManagerFactoryBuilder.generateSchema();
fail( "Should haave thrown IOException" );
fail( "Should have thrown IOException" );
}
catch (Exception e) {
assertTrue( e instanceof PersistenceException );
@ -70,7 +70,7 @@ public class SchemaScriptFileGenerationFailureTest {
boolean ddlCommandFound = Pattern.compile( "drop table( if exists)? test_entity( if exists)?" )
.matcher( commandAcceptanceException.getMessage().toLowerCase() ).find();
assertTrue( "The Exception Message does not contain the DDL command causing the failure", ddlCommandFound );
assertTrue( ddlCommandFound, "The Exception Message does not contain the DDL command causing the failure" );
assertTrue( commandAcceptanceException.getCause() instanceof IOException );
@ -97,7 +97,7 @@ public class SchemaScriptFileGenerationFailureTest {
}
private PersistenceUnitDescriptor buildPersistenceUnitDescriptor() {
return new BaseEntityManagerFunctionalTestCase.TestingPersistenceUnitDescriptorImpl( getClass().getSimpleName() );
return new EntityManagerFactoryBasedFunctionalTest.TestingPersistenceUnitDescriptorImpl( getClass().getSimpleName() );
}
private Map getConfig() {
@ -126,7 +126,6 @@ public class SchemaScriptFileGenerationFailureTest {
@Override
public void close() throws IOException {
}
}
}

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.schemagen;
package org.hibernate.orm.test.jpa.schemagen;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -22,15 +22,14 @@ import org.hibernate.cfg.Environment;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Andrea Boriero
@ -40,7 +39,7 @@ public class SchemaScriptFileGenerationTest {
private File dropSchema;
private EntityManagerFactoryBuilder entityManagerFactoryBuilder;
@Before
@BeforeEach
public void setUp() throws IOException {
createSchema = File.createTempFile( "create_schema", ".sql" );
dropSchema = File.createTempFile( "drop_schema", ".sql" );
@ -95,7 +94,7 @@ public class SchemaScriptFileGenerationTest {
}
private PersistenceUnitDescriptor buildPersistenceUnitDescriptor() {
return new BaseEntityManagerFunctionalTestCase.TestingPersistenceUnitDescriptorImpl( getClass().getSimpleName() );
return new EntityManagerFactoryBasedFunctionalTest.TestingPersistenceUnitDescriptorImpl( getClass().getSimpleName() );
}
private Map getConfig() {
@ -109,5 +108,4 @@ public class SchemaScriptFileGenerationTest {
config.put( org.hibernate.jpa.AvailableSettings.LOADED_CLASSES, classes );
return config;
}
}

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.serialization;
package org.hibernate.orm.test.jpa.serialization;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -19,39 +19,56 @@ import javax.persistence.Id;
import javax.persistence.PersistenceException;
import javax.persistence.Table;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* @author Andrea Boriero
*/
public class EntityManagerDeserializationTest extends BaseEntityManagerFunctionalTestCase {
@Jpa(annotatedClasses = {
EntityManagerDeserializationTest.TestEntity.class
})
public class EntityManagerDeserializationTest {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {TestEntity.class};
}
@Test(expected = PersistenceException.class)
@Test
@TestForIssue(jiraKey = "HHH-11555")
public void deserializedEntityManagerPersistenceExceptionManagementTest() throws IOException {
EntityManager entityManager = getOrCreateEntityManager();
final EntityManager deserializedSession = spoofSerialization( entityManager );
try {
deserializedSession.getTransaction().begin();
TestEntity entity = new TestEntity();
entity.setName( "Andrea" );
deserializedSession.persist( entity );
entity.setName( null );
deserializedSession.flush();
}
finally {
deserializedSession.getTransaction().rollback();
deserializedSession.close();
entityManager.close();
}
public void deserializedEntityManagerPersistenceExceptionManagementTest(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
final EntityManager deserializedSession;
try {
deserializedSession = spoofSerialization( entityManager );
}
catch (IOException ioe) {
throw new RuntimeException(ioe);
}
try {
Assertions.assertThrows(
PersistenceException.class,
() -> {
deserializedSession.getTransaction().begin();
TestEntity entity = new TestEntity();
entity.setName( "Andrea" );
deserializedSession.persist( entity );
entity.setName( null );
deserializedSession.flush();
},
"Should have thrown a PersistenceException"
);
}
finally {
if ( deserializedSession != null ) {
deserializedSession.getTransaction().rollback();
deserializedSession.close();
}
}
}
);
}
private EntityManager spoofSerialization(EntityManager entityManager) throws IOException {
@ -79,13 +96,12 @@ public class EntityManagerDeserializationTest extends BaseEntityManagerFunctiona
@Entity
@Table(name = "TEST_ENTITY")
public static class TestEntity {
@Column(nullable = false)
String name;
@Id
@GeneratedValue
private Long id;
@Column(nullable = false)
String name;
public Long getId() {
return id;
}

View File

@ -0,0 +1,49 @@
/*
* 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.statistics;
import javax.persistence.EntityManagerFactory;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.stat.Statistics;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-11602")
@Jpa(
integrationSettings = { @Setting(name = AvailableSettings.GENERATE_STATISTICS, value = "true") }
)
public class SessionCloseCountTest {
@Test
public void sessionCountClosetShouldBeIncrementedWhenTheEntityManagerIsClosed(EntityManagerFactoryScope scope) {
final EntityManagerFactory entityManagerFactory = scope.getEntityManagerFactory();
final Statistics statistics = entityManagerFactory.unwrap( SessionFactory.class ).getStatistics();
scope.inEntityManager(
entityManager -> {
assertThat( "The session close count should be zero", statistics.getSessionCloseCount(), is( 0L ) );
entityManager.close();
assertThat( "The session close count was not incremented", statistics.getSessionCloseCount(), is( 1L ) );
}
);
}
}

View File

@ -0,0 +1,94 @@
/*
* 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.temporal;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Query;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
/**
* @author Brett Meyer
*/
@Jpa(annotatedClasses = {
TemporalTypeTest.DataPoint.class
})
public class TemporalTypeTest {
@Test
public void testTemporalType(EntityManagerFactoryScope scope) {
Date date = new Date();
Calendar calendar = Calendar.getInstance();
scope.inTransaction(
entityManager -> {
DataPoint dp = new DataPoint();
dp.date1 = date;
dp.date2 = date;
dp.calendar1 = calendar;
dp.calendar2 = calendar;
entityManager.persist( dp );
}
);
doTest(scope, "date1", date);
doTest(scope, "date1", calendar);
doTest(scope, "date2", date);
doTest(scope, "date2", calendar);
doTest(scope, "calendar1", date);
doTest(scope, "calendar1", calendar);
doTest(scope, "calendar2", date);
doTest(scope, "calendar2", calendar);
}
private void doTest(EntityManagerFactoryScope scope, String property, Object obj) {
doTest( scope, property, obj, TemporalType.DATE );
doTest( scope, property, obj, TemporalType.TIMESTAMP );
}
private void doTest(EntityManagerFactoryScope scope, String property, Object obj, TemporalType temporalType) {
scope.inTransaction(
entityManager -> {
Query query = entityManager.createQuery("from DataPoint where " + property + " = :obj");
if (obj instanceof Calendar) {
query.setParameter("obj", (Calendar) obj, temporalType);
}
else {
query.setParameter("obj", (Date) obj, temporalType);
}
}
);
}
@Entity(name = "DataPoint")
public static class DataPoint {
@Id @GeneratedValue
public long id;
@Temporal( TemporalType.DATE )
public Date date1;
@Temporal( TemporalType.TIMESTAMP )
public Date date2;
@Temporal( TemporalType.DATE )
public Calendar calendar1;
@Temporal( TemporalType.TIMESTAMP )
public Calendar calendar2;
}
}

View File

@ -4,12 +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.transaction.batch;
package org.hibernate.orm.test.jpa.transaction.batch;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@ -19,53 +18,36 @@ import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderInitiator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.internal.HEMLogging;
import org.hibernate.jpa.boot.spi.ProviderChecker;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.jta.JtaAwareConnectionProviderImpl;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import org.hibernate.testing.logger.Triggerable;
import org.junit.Before;
import org.junit.Rule;
import org.hibernate.testing.orm.jpa.NonStringValueSettingProvider;
import org.hibernate.testing.orm.logger.Inspector;
import org.hibernate.testing.orm.logger.LogInspector;
import org.hibernate.testing.orm.logger.LoggerInspectionExtension;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.fail;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Andrea Boriero
*/
public abstract class AbstractJtaBatchTest extends BaseEntityManagerFunctionalTestCase {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
Logger.getMessageLogger( CoreMessageLogger.class, AbstractBatchImpl.class.getName() )
);
@ExtendWith(LoggerInspectionExtension.class)
public abstract class AbstractJtaBatchTest {
protected Triggerable triggerable;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Comment.class, EventLog.class };
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
TestingJtaBootstrap.prepare( options );
options.put( BatchBuilderInitiator.BUILDER, getBatchBuilderClassName() );
options.put( AvailableSettings.JPA_TRANSACTION_COMPLIANCE, "true" );
options.put( AvailableSettings.JPA_TRANSACTION_TYPE, "JTA" );
options.put( AvailableSettings.STATEMENT_BATCH_SIZE, "50" );
}
@Before
public void setUp() {
triggerable = logInspection.watchForLogMessages(
@BeforeEach
public void setUp(@LogInspector Inspector logInspector) {
logInspector.init( HEMLogging.messageLogger( ProviderChecker.class.getName() ) );
triggerable = logInspector.watchForLogMessages(
"HHH000352: Unable to release batch statement..." );
triggerable.reset();
}
@ -81,7 +63,29 @@ public abstract class AbstractJtaBatchTest extends BaseEntityManagerFunctionalTe
} );
}
protected abstract String getBatchBuilderClassName();
public static class JtaPlatformNonStringValueSettingProvider extends NonStringValueSettingProvider {
@Override
public String getKey() {
return AvailableSettings.JTA_PLATFORM;
}
@Override
public Object getValue() {
return TestingJtaPlatformImpl.INSTANCE;
}
}
public static class ConnectionNonStringValueSettingProvider extends NonStringValueSettingProvider {
@Override
public String getKey() {
return AvailableSettings.CONNECTION_PROVIDER;
}
@Override
public Object getValue() {
return JtaAwareConnectionProviderImpl.class.getName();
}
}
@Entity(name = "Comment")
@Table(name = "COMMENTS")
@ -138,5 +142,4 @@ public abstract class AbstractJtaBatchTest extends BaseEntityManagerFunctionalTe
this.message = message;
}
}
}

View File

@ -4,97 +4,123 @@
* 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.transaction.batch;
package org.hibernate.orm.test.jpa.transaction.batch;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.FlushModeType;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderInitiator;
import org.hibernate.engine.jdbc.batch.internal.BatchingBatch;
import org.hibernate.engine.jdbc.batch.spi.Batch;
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import org.junit.Test;
import org.hibernate.testing.orm.jpa.NonStringValueSettingProvider;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* @author Gail Badner
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-13050")
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@Jpa(
annotatedClasses = {
AbstractJtaBatchTest.Comment.class,
AbstractJtaBatchTest.EventLog.class
},
integrationSettings = { @Setting(name = AvailableSettings.JPA_TRANSACTION_TYPE, value = "JTA"),
@Setting(name = AvailableSettings.JPA_TRANSACTION_COMPLIANCE, value = "true"),
@Setting(name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "50") },
nonStringValueSettingProviders = {
AbstractJtaBatchTest.JtaPlatformNonStringValueSettingProvider.class,
AbstractJtaBatchTest.ConnectionNonStringValueSettingProvider.class,
JtaWithFailingBatchTest.BatchBuilderNonStringValueSettingProvider.class
}
)
public class JtaWithFailingBatchTest extends AbstractJtaBatchTest {
private static TestBatch testBatch;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Comment.class, EventLog.class };
}
@Test
public void testAllStatementsAreClosedInCaseOfBatchExecutionFailure() throws Exception {
public void testAllStatementsAreClosedInCaseOfBatchExecutionFailure(EntityManagerFactoryScope scope) {
TransactionManager transactionManager = TestingJtaPlatformImpl.INSTANCE.getTransactionManager();
EntityManager em = createEntityManager();
try {
transactionManager.begin();
em.setFlushMode( FlushModeType.AUTO );
scope.inEntityManager(
em -> {
try {
transactionManager.begin();
// Persist entity with non-generated id
EventLog eventLog1 = new EventLog();
eventLog1.setMessage( "Foo1" );
em.persist( eventLog1 );
em.setFlushMode( FlushModeType.AUTO );
// Persist entity with non-generated id
EventLog eventLog2 = new EventLog();
eventLog2.setMessage( "Foo2" );
em.persist( eventLog2 );
// Persist entity with non-generated id
EventLog eventLog1 = new EventLog();
eventLog1.setMessage( "Foo1" );
em.persist( eventLog1 );
Comment comment = new Comment();
comment.setMessage( "Bar" );
// Persist entity with non-generated id
EventLog eventLog2 = new EventLog();
eventLog2.setMessage( "Foo2" );
em.persist( eventLog2 );
try {
em.persist( comment );
transactionManager.commit();
}
catch (Exception expected) {
//expected
switch ( transactionManager.getStatus() ) {
case Status.STATUS_ACTIVE:
case Status.STATUS_MARKED_ROLLBACK:
transactionManager.rollback();
Comment comment = new Comment();
comment.setMessage( "Bar" );
try {
em.persist( comment );
transactionManager.commit();
}
catch (Exception expected) {
//expected
switch ( transactionManager.getStatus() ) {
case Status.STATUS_ACTIVE:
case Status.STATUS_MARKED_ROLLBACK:
transactionManager.rollback();
}
}
assertThat(
"AbstractBatchImpl#releaseStatements() has not been callled",
testBatch.calledReleaseStatements,
is( true )
);
assertAllStatementsAreClosed( testBatch.createdStatements );
assertStatementsListIsCleared();
}
catch (Exception e) {
try {
if (transactionManager.getStatus() == Status.STATUS_ACTIVE) {
transactionManager.rollback();
}
}
catch (Exception e2) {
// Ignore
}
}
assertFalse( triggerable.wasTriggered(), "HHH000352: Unable to release batch statement... has been thrown" );
}
}
assertThat(
"AbstractBatchImpl#releaseStatements() has not been callled",
testBatch.calledReleaseStatements,
is( true )
);
assertAllStatementsAreClosed( testBatch.createdStatements );
assertStatementsListIsCleared();
}
finally {
em.close();
}
assertFalse( "HHH000352: Unable to release batch statement... has been thrown", triggerable.wasTriggered() );
);
}
private void assertStatementsListIsCleared() {
@ -106,6 +132,18 @@ public class JtaWithFailingBatchTest extends AbstractJtaBatchTest {
);
}
public static class BatchBuilderNonStringValueSettingProvider extends NonStringValueSettingProvider {
@Override
public String getKey() {
return BatchBuilderInitiator.BUILDER;
}
@Override
public Object getValue() {
return JtaWithFailingBatchTest.TestBatchBuilder.class.getName();
}
}
public static class TestBatch extends BatchingBatch {
private int numberOfStatementsAfterReleasing;
private List<PreparedStatement> createdStatements = new ArrayList<>();
@ -145,11 +183,6 @@ public class JtaWithFailingBatchTest extends AbstractJtaBatchTest {
}
}
@Override
protected String getBatchBuilderClassName() {
return TestBatchBuilder.class.getName();
}
public static class TestBatchBuilder extends BatchBuilderImpl {
private int jdbcBatchSize;

View File

@ -0,0 +1,192 @@
/*
* 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.transaction.batch;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.FlushModeType;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderInitiator;
import org.hibernate.engine.jdbc.batch.internal.BatchingBatch;
import org.hibernate.engine.jdbc.batch.spi.Batch;
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import org.hibernate.testing.orm.jpa.NonStringValueSettingProvider;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-13050")
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@Jpa(
annotatedClasses = {
AbstractJtaBatchTest.Comment.class,
AbstractJtaBatchTest.EventLog.class
},
integrationSettings = {
@Setting(name = AvailableSettings.JPA_TRANSACTION_TYPE, value = "JTA"),
@Setting(name = AvailableSettings.JPA_TRANSACTION_COMPLIANCE, value = "true"),
@Setting(name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "50")
},
nonStringValueSettingProviders = {
AbstractJtaBatchTest.JtaPlatformNonStringValueSettingProvider.class,
AbstractJtaBatchTest.ConnectionNonStringValueSettingProvider.class,
JtaWithStatementsBatchTest.BatchBuilderNonStringValueSettingProvider.class
}
)
public class JtaWithStatementsBatchTest extends AbstractJtaBatchTest {
private static TestBatch testBatch;
@Test
public void testUnableToReleaseStatementMessageIsNotLogged(EntityManagerFactoryScope scope) {
TransactionManager transactionManager = TestingJtaPlatformImpl.INSTANCE.getTransactionManager();
scope.inEntityManager(
em -> {
try {
transactionManager.begin();
em.setFlushMode( FlushModeType.AUTO );
// Persist entity with non-generated id
EventLog eventLog1 = new EventLog();
eventLog1.setMessage( "Foo1" );
em.persist( eventLog1 );
// Persist entity with non-generated id
EventLog eventLog2 = new EventLog();
eventLog2.setMessage( "Foo2" );
em.persist( eventLog2 );
Comment comment = new Comment();
comment.setMessage( "Bar" );
em.persist( comment );
transactionManager.commit();
assertStatementsListIsCleared();
assertAllStatementsAreClosed( testBatch.createdStatements );
}
catch (Exception e) {
try {
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
transactionManager.rollback();
}
}
catch (Exception e2) {
// Ignore
}
}
assertFalse(
triggerable.wasTriggered(),
"HHH000352: Unable to release batch statement... has been thrown"
);
}
);
scope.inEntityManager(
em -> {
try {
transactionManager.begin();
Integer savedComments
= em.createQuery( "from Comment" ).getResultList().size();
assertThat( savedComments, is( 1 ) );
Integer savedEventLogs
= em.createQuery( "from EventLog" ).getResultList().size();
assertThat( savedEventLogs, is( 2 ) );
}
catch (Exception e) {
try {
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
transactionManager.rollback();
}
}
catch (Exception e2) {
// Ignore
}
}
}
);
}
private void assertStatementsListIsCleared() {
assertThat( testBatch.createdStatements.size(), not( 0 ) );
assertThat(
"Not all PreparedStatements have been released",
testBatch.numberOfStatementsAfterReleasing,
is( 0 )
);
}
public static class BatchBuilderNonStringValueSettingProvider extends NonStringValueSettingProvider {
@Override
public String getKey() {
return BatchBuilderInitiator.BUILDER;
}
@Override
public Object getValue() {
return JtaWithStatementsBatchTest.TestBatchBuilder.class.getName();
}
}
public static class TestBatch extends BatchingBatch {
private int numberOfStatementsAfterReleasing;
private List<PreparedStatement> createdStatements = new ArrayList<>();
public TestBatch(BatchKey key, JdbcCoordinator jdbcCoordinator, int batchSize) {
super( key, jdbcCoordinator, batchSize );
}
protected void releaseStatements() {
createdStatements.addAll( getStatements().values() );
super.releaseStatements();
numberOfStatementsAfterReleasing += getStatements().size();
}
}
public static class TestBatchBuilder extends BatchBuilderImpl {
private int jdbcBatchSize;
@Override
public void setJdbcBatchSize(int jdbcBatchSize) {
this.jdbcBatchSize = jdbcBatchSize;
}
@Override
public Batch buildBatch(BatchKey key, JdbcCoordinator jdbcCoordinator) {
return buildBatchTest( key, jdbcCoordinator, jdbcBatchSize );
}
protected BatchingBatch buildBatchTest(BatchKey key, JdbcCoordinator jdbcCoordinator, int jdbcBatchSize) {
testBatch = new TestBatch( key, jdbcCoordinator, jdbcBatchSize );
return testBatch;
}
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.xml;
package org.hibernate.orm.test.jpa.xml;
/**

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.xml;
package org.hibernate.orm.test.jpa.xml;
import javax.persistence.CascadeType;
import javax.persistence.Column;
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.xml;
package org.hibernate.orm.test.jpa.xml;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;

View File

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

View File

@ -0,0 +1,40 @@
/*
* 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.xml;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
/**
* @author <a href="mailto:stliu@hibernate.org">Strong Liu</a>
*/
@TestForIssue( jiraKey = "HHH-6039, HHH-6100" )
@Jpa(
xmlMappings = {"org/hibernate/orm/test/jpa/xml/Qualifier.hbm.xml"}
)
public class JpaEntityNameTest {
@Test
public void testUsingSimpleHbmInJpa(EntityManagerFactoryScope scope){
scope.inTransaction(
entityManager -> {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Qualifier> cq = cb.createQuery(Qualifier.class);
Root<Qualifier> qualifRoot = cq.from(Qualifier.class);
cq.where( cb.equal( qualifRoot.get( "qualifierId" ), 32l ) );
entityManager.createQuery(cq).getResultList();
}
);
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.xml;
package org.hibernate.orm.test.jpa.xml;
/**

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.jpa.test.xml;
package org.hibernate.orm.test.jpa.xml;
/**

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.xml;
package org.hibernate.orm.test.jpa.xml;
/**
* @author <a href="mailto:stliu@hibernate.org">Strong Liu</a>

View File

@ -0,0 +1,98 @@
/*
* 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.xml;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Emmanuel Bernard
*/
@Jpa(
xmlMappings = { "org/hibernate/orm/test/jpa/xml/orm3.xml" }
)
public class XmlAttributeOverrideTest {
@Test
public void testAttributeOverriding(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
try {
entityManager.getTransaction().begin();
Employee e = new Employee();
e.setId( 100L );
e.setName( "Bubba" );
e.setHomeAddress( new Address( "123 Main St", "New York", "NY", "11111" ) );
e.setMailAddress( new Address( "P.O. Box 123", "New York", "NY", "11111" ) );
entityManager.persist( e );
entityManager.flush();
entityManager.getTransaction().rollback();
}
catch (Exception e) {
if ( entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().rollback();
}
throw e;
}
}
);
}
@Test
public void testDefaultEventListener(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
try {
entityManager.getTransaction().begin();
CounterListener.reset();
Employee e = new Employee();
e.setId( 100L );
e.setName( "Bubba" );
e.setHomeAddress( new Address( "123 Main St", "New York", "NY", "11111" ) );
e.setMailAddress( new Address( "P.O. Box 123", "New York", "NY", "11111" ) );
entityManager.persist( e );
entityManager.flush();
entityManager.clear();
entityManager.find( Employee.class, e.getId() ).setName( "Bibo" );
entityManager.flush();
entityManager.clear();
entityManager.remove( entityManager.find( Employee.class, e.getId() ) );
entityManager.flush();
entityManager.getTransaction().rollback();
}
catch (Exception e) {
if ( entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().rollback();
}
throw e;
}
}
);
assertEquals( 1, CounterListener.insert );
assertEquals( 1, CounterListener.update );
assertEquals( 1, CounterListener.delete );
}
}

View File

@ -0,0 +1,57 @@
/*
* 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.xml;
import javax.persistence.EntityManager;
import javax.persistence.SharedCacheMode;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.orm.jpa.NonStringValueSettingProvider;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
/**
* @author Emmanuel Bernard
*/
@Jpa(
xmlMappings = {"org/hibernate/orm/test/jpa/xml/orm.xml", "org/hibernate/orm/test/jpa/xml/orm2.xml"},
nonStringValueSettingProviders = { XmlTest.SharedCacheModeProvider.class }
)
public class XmlTest {
@Test
public void testXmlMappingCorrectness(EntityManagerFactoryScope scope) {
EntityManager em = scope.getEntityManagerFactory().createEntityManager();
em.close();
}
@Test
public void testXmlMappingWithCacheable(EntityManagerFactoryScope scope) {
EntityManager em = scope.getEntityManagerFactory().createEntityManager();
SharedSessionContractImplementor session = em.unwrap( SharedSessionContractImplementor.class );
EntityPersister entityPersister= session.getFactory().getMetamodel().entityPersister( Lighter.class );
Assertions.assertTrue(entityPersister.canReadFromCache());
Assertions.assertTrue(entityPersister.canWriteToCache());
}
public static class SharedCacheModeProvider extends NonStringValueSettingProvider {
@Override
public String getKey() {
return AvailableSettings.JPA_SHARED_CACHE_MODE;
}
@Override
public Object getValue() {
return SharedCacheMode.ENABLE_SELECTIVE;
}
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id: $
package org.hibernate.jpa.test.xml.sequences;
package org.hibernate.orm.test.jpa.xml.sequences;
/**

View File

@ -6,7 +6,7 @@
*/
//$Id: $
package org.hibernate.jpa.test.xml.sequences;
package org.hibernate.orm.test.jpa.xml.sequences;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

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

View File

@ -6,7 +6,7 @@
*/
//$Id: $
package org.hibernate.jpa.test.xml.sequences;
package org.hibernate.orm.test.jpa.xml.sequences;
/**

View File

@ -6,7 +6,7 @@
*/
//$Id: $
package org.hibernate.jpa.test.xml.sequences;
package org.hibernate.orm.test.jpa.xml.sequences;
/**

View File

@ -0,0 +1,49 @@
/*
* 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.xml.sequences;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
/**
* @author Emmanuel Bernard
*/
@Jpa(
xmlMappings = {"org/hibernate/orm/test/jpa/xml/sequences/orm3.xml"}
)
public class XmlAttributeOverrideTest {
@Test
public void testAttributeOverriding(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
try {
entityManager.getTransaction().begin();
Employee e = new Employee();
e.setId( 100L );
e.setName("Bubba");
e.setHomeAddress(new Address("123 Main St", "New York", "NY", "11111"));
e.setMailAddress(new Address("P.O. Box 123", "New York", "NY", "11111"));
entityManager.persist(e);
entityManager.flush();
entityManager.getTransaction().rollback();
}
catch (Exception e) {
if ( entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().rollback();
}
throw e;
}
}
);
}
}

View File

@ -0,0 +1,31 @@
/*
* 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.xml.sequences;
import javax.persistence.EntityManager;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.jupiter.api.Test;
/**
* @author Emmanuel Bernard
*/
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsSequences.class )
@Jpa(
xmlMappings = {"org/hibernate/orm/test/jpa/xml/sequences/orm.xml", "org/hibernate/orm/test/jpa/xml/sequences/orm2.xml"}
)
public class XmlTest {
@Test
public void testXmlMappingCorrectness(EntityManagerFactoryScope scope) {
EntityManager em = scope.getEntityManagerFactory().createEntityManager();
em.close();
}
}

View File

@ -7,7 +7,7 @@
package org.hibernate.test.refresh;
import org.hibernate.Session;
import org.hibernate.jpa.test.refresh.TestEntity;
import org.hibernate.orm.test.jpa.refresh.TestEntity;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;

View File

@ -9,7 +9,7 @@ package org.hibernate.test.refresh;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.jpa.test.refresh.TestEntity;
import org.hibernate.orm.test.jpa.refresh.TestEntity;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Before;

View File

@ -13,7 +13,7 @@
-->
<hibernate-mapping package="org.hibernate.jpa.test.xml">
<hibernate-mapping package="org.hibernate.orm.test.jpa.xml">
<class name="Qualifier" table="QUALIFIER">
<id name="qualifierId" column="QUALIFIER_ID" type="long">

View File

@ -19,7 +19,7 @@
<cascade-persist/>
</persistence-unit-defaults>
</persistence-unit-metadata>
<package>org.hibernate.jpa.test.xml</package>
<package>org.hibernate.orm.test.jpa.xml</package>
<entity class="Light" metadata-complete="true" access="FIELD">
<attributes>
<id name="name">

View File

@ -11,7 +11,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0"
>
<entity class="org.hibernate.jpa.test.xml.Lighter" name="ALighter" cacheable="true" access="FIELD" metadata-complete="true">
<entity class="org.hibernate.orm.test.jpa.xml.Lighter" name="ALighter" cacheable="true" access="FIELD" metadata-complete="true">
<attributes>
<id name="name">
<column name="fld_id"/>

View File

@ -14,12 +14,12 @@
<persistence-unit-metadata>
<persistence-unit-defaults>
<entity-listeners>
<entity-listener class="org.hibernate.jpa.test.xml.CounterListener"/>
<entity-listener class="org.hibernate.orm.test.jpa.xml.CounterListener"/>
</entity-listeners>
</persistence-unit-defaults>
</persistence-unit-metadata>
<entity class="org.hibernate.jpa.test.xml.Employee" metadata-complete="false" access="FIELD">
<entity class="org.hibernate.orm.test.jpa.xml.Employee" metadata-complete="false" access="FIELD">
<attributes>
<id name="id"/>
<basic name="name"/>
@ -57,7 +57,7 @@
</attributes>
</entity>
<embeddable class="org.hibernate.jpa.test.xml.Address">
<embeddable class="org.hibernate.orm.test.jpa.xml.Address">
<attributes>
<basic name="street"/>
<basic name="city"/>

View File

@ -19,7 +19,7 @@
<cascade-persist/>
</persistence-unit-defaults>
</persistence-unit-metadata>
<package>org.hibernate.jpa.test.xml.sequences</package>
<package>org.hibernate.orm.test.jpa.xml.sequences</package>
<entity class="Light" metadata-complete="true" access="FIELD">
<attributes>
<id name="name">

View File

@ -11,7 +11,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0"
>
<entity class="org.hibernate.jpa.test.xml.sequences.Lighter" name="ALighter" access="FIELD" metadata-complete="true">
<entity class="org.hibernate.orm.test.jpa.xml.sequences.Lighter" name="ALighter" access="FIELD" metadata-complete="true">
<attributes>
<id name="name">
<column name="fld_id"/>

View File

@ -11,7 +11,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<entity class="org.hibernate.jpa.test.xml.sequences.Employee" metadata-complete="false" access="FIELD">
<entity class="org.hibernate.orm.test.jpa.xml.sequences.Employee" metadata-complete="false" access="FIELD">
<attributes>
<id name="id"/>
<basic name="name"/>
@ -49,7 +49,7 @@
</attributes>
</entity>
<embeddable class="org.hibernate.jpa.test.xml.sequences.Address">
<embeddable class="org.hibernate.orm.test.jpa.xml.sequences.Address">
<attributes>
<basic name="street"/>
<basic name="city"/>