test cleanup
This commit is contained in:
parent
3f24a0064f
commit
e090480ea1
|
@ -331,7 +331,7 @@ public class BooleanMappingTests {
|
|||
|
||||
@Test
|
||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||
public void testBooleanFunctionAsPredicate(SessionFactoryScope scope) {
|
||||
// Not strictly relevant to boolean mappings, but test that boolean
|
||||
|
@ -350,7 +350,7 @@ public class BooleanMappingTests {
|
|||
|
||||
@Test
|
||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||
public void testBooleanFunctionInPredicate(SessionFactoryScope scope) {
|
||||
// Not strictly relevant to boolean mappings, but test that boolean
|
||||
|
|
|
@ -6,222 +6,215 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.annotations.manytoonewithformula;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.HSQLDialect;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Sharath Reddy
|
||||
*/
|
||||
public class ManyToOneWithFormulaTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel( annotatedClasses = {
|
||||
Menu.class,
|
||||
FoodItem.class,
|
||||
Company.class,
|
||||
Person.class,
|
||||
Message.class,
|
||||
Language.class,
|
||||
Contract.class,
|
||||
ContractId.class,
|
||||
Model.class,
|
||||
ModelId.class,
|
||||
Manufacturer.class,
|
||||
ManufacturerId.class,
|
||||
Product.class,
|
||||
ProductSqlServer.class
|
||||
} )
|
||||
@SessionFactory
|
||||
public class ManyToOneWithFormulaTest {
|
||||
@Test
|
||||
public void testManyToOneFromNonPk() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Menu menu = new Menu();
|
||||
menu.setOrderNbr( "123" );
|
||||
menu.setDefault( "F" );
|
||||
s.persist( menu );
|
||||
FoodItem foodItem = new FoodItem();
|
||||
foodItem.setItem( "Mouse" );
|
||||
foodItem.setOrder( menu );
|
||||
s.persist( foodItem );
|
||||
s.flush();
|
||||
s.clear();
|
||||
foodItem = ( FoodItem ) s.get( FoodItem.class, foodItem.getId() );
|
||||
assertNotNull( foodItem.getOrder() );
|
||||
assertEquals( "123", foodItem.getOrder().getOrderNbr() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
public void testManyToOneFromNonPk(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> {
|
||||
Menu menu = new Menu();
|
||||
menu.setOrderNbr( "123" );
|
||||
menu.setDefault( "F" );
|
||||
session.persist( menu );
|
||||
FoodItem foodItem = new FoodItem();
|
||||
foodItem.setItem( "Mouse" );
|
||||
foodItem.setOrder( menu );
|
||||
session.persist( foodItem );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
foodItem = session.get( FoodItem.class, foodItem.getId() );
|
||||
assertThat( foodItem.getOrder() ).isNotNull();
|
||||
assertThat( foodItem.getOrder().getOrderNbr() ).isEqualTo( "123" );
|
||||
|
||||
session.getTransaction().markRollbackOnly();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManyToOneFromPk() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
public void testManyToOneFromPk(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> {
|
||||
Company company = new Company();
|
||||
session.persist( company );
|
||||
|
||||
Company company = new Company();
|
||||
s.persist( company );
|
||||
Person person = new Person();
|
||||
person.setDefaultFlag( "T" );
|
||||
person.setCompanyId( company.getId() );
|
||||
session.persist( person );
|
||||
|
||||
Person person = new Person();
|
||||
person.setDefaultFlag( "T" );
|
||||
person.setCompanyId( company.getId() );
|
||||
s.persist( person );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
company = session.get( Company.class, company.getId() );
|
||||
assertThat( company.getDefaultContactPerson() ).isNotNull();
|
||||
assertThat( company.getDefaultContactPerson().getId() ).isEqualTo( person.getId() );
|
||||
|
||||
company = ( Company ) s.get( Company.class, company.getId() );
|
||||
assertNotNull( company.getDefaultContactPerson() );
|
||||
assertEquals( person.getId(), company.getDefaultContactPerson().getId() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
session.getTransaction().markRollbackOnly();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = { HSQLDialect.class }, comment = "The used join conditions does not work in HSQLDB. See HHH-4497")
|
||||
public void testManyToOneToPkWithOnlyFormula() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
@SkipForDialect( dialectClass = HSQLDialect.class, reason = "The used join conditions does not work in HSQLDB. See HHH-4497" )
|
||||
public void testManyToOneToPkWithOnlyFormula(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> {
|
||||
Language language = new Language();
|
||||
language.setCode( "EN" );
|
||||
language.setName( "English" );
|
||||
session.persist( language );
|
||||
|
||||
Language language = new Language();
|
||||
language.setCode( "EN" );
|
||||
language.setName( "English" );
|
||||
s.persist( language );
|
||||
Message msg = new Message();
|
||||
msg.setLanguageCode( "en" );
|
||||
msg.setLanguageName( "English" );
|
||||
session.persist( msg );
|
||||
|
||||
Message msg = new Message();
|
||||
msg.setLanguageCode( "en" );
|
||||
msg.setLanguageName( "English" );
|
||||
s.persist( msg );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
msg = session.get( Message.class, msg.getId() );
|
||||
assertThat( msg.getLanguage() ).isNotNull();
|
||||
assertThat( msg.getLanguage().getCode() ).isEqualTo( "EN" );
|
||||
|
||||
msg = ( Message ) s.get( Message.class, msg.getId() );
|
||||
assertNotNull( msg.getLanguage() );
|
||||
assertEquals( "EN", msg.getLanguage().getCode() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
session.getTransaction().markRollbackOnly();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferencedColumnNameBelongsToEmbeddedIdOfReferencedEntity() throws Exception {
|
||||
Session session = openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
public void testReferencedColumnNameBelongsToEmbeddedIdOfReferencedEntity(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> { Integer companyCode = 10;
|
||||
Integer mfgCode = 100;
|
||||
String contractNumber = "NSAR97841";
|
||||
ContractId contractId = new ContractId(companyCode, 12457l, 1);
|
||||
|
||||
Integer companyCode = 10;
|
||||
Integer mfgCode = 100;
|
||||
String contractNumber = "NSAR97841";
|
||||
ContractId contractId = new ContractId(companyCode, 12457l, 1);
|
||||
Manufacturer manufacturer = new Manufacturer(new ManufacturerId(
|
||||
companyCode, mfgCode), "FORD");
|
||||
|
||||
Manufacturer manufacturer = new Manufacturer(new ManufacturerId(
|
||||
companyCode, mfgCode), "FORD");
|
||||
Model model = new Model(new ModelId(companyCode, mfgCode, "FOCUS"),
|
||||
"FORD FOCUS");
|
||||
|
||||
Model model = new Model(new ModelId(companyCode, mfgCode, "FOCUS"),
|
||||
"FORD FOCUS");
|
||||
session.persist(manufacturer);
|
||||
session.persist(model);
|
||||
|
||||
session.persist(manufacturer);
|
||||
session.persist(model);
|
||||
Contract contract = new Contract();
|
||||
contract.setId(contractId);
|
||||
contract.setContractNumber(contractNumber);
|
||||
contract.setManufacturer(manufacturer);
|
||||
contract.setModel(model);
|
||||
|
||||
Contract contract = new Contract();
|
||||
contract.setId(contractId);
|
||||
contract.setContractNumber(contractNumber);
|
||||
contract.setManufacturer(manufacturer);
|
||||
contract.setModel(model);
|
||||
session.persist(contract);
|
||||
|
||||
session.persist(contract);
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
contract = session.get( Contract.class, contractId );
|
||||
assertThat( contract.getContractNumber() ).isEqualTo( "NSAR97841" );
|
||||
assertThat( contract.getManufacturer().getName() ).isEqualTo( "FORD" );
|
||||
assertThat( contract.getModel().getName() ).isEqualTo( "FORD FOCUS" );
|
||||
|
||||
contract = (Contract) session.load(Contract.class, contractId);
|
||||
assertEquals("NSAR97841", contract.getContractNumber());
|
||||
assertEquals("FORD", contract.getManufacturer().getName());
|
||||
assertEquals("FORD FOCUS", contract.getModel().getName());
|
||||
|
||||
tx.commit();
|
||||
session.close();
|
||||
session.getTransaction().markRollbackOnly();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect( value = { HSQLDialect.class }, comment = "The used join conditions does not work in HSQLDB. See HHH-4497." )
|
||||
@SkipForDialect( value = { OracleDialect.class }, comment = "Oracle do not support 'substring' function" )
|
||||
public void testManyToOneFromNonPkToNonPk() throws Exception {
|
||||
// also tests usage of the stand-alone @JoinFormula annotation (i.e. not wrapped within @JoinColumnsOrFormulas)
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
@SkipForDialect( dialectClass =HSQLDialect.class, reason = "The used join conditions does not work in HSQLDB. See HHH-4497." )
|
||||
@SkipForDialect( dialectClass = OracleDialect.class, reason = "Oracle do not support 'substring' function" )
|
||||
public void testManyToOneFromNonPkToNonPk(SessionFactoryScope scope) {
|
||||
// also tests usage of the stand-alone @JoinFormula annotation
|
||||
// (i.e. not wrapped within @JoinColumnsOrFormulas)
|
||||
|
||||
Product kit = new Product();
|
||||
kit.id = 1;
|
||||
kit.productIdnf = "KIT";
|
||||
kit.description = "Kit";
|
||||
s.persist(kit);
|
||||
scope.inTransaction( (session) -> {
|
||||
Product kit = new Product();
|
||||
kit.id = 1;
|
||||
kit.productIdnf = "KIT";
|
||||
kit.description = "Kit";
|
||||
session.persist(kit);
|
||||
|
||||
Product kitkat = new Product();
|
||||
kitkat.id = 2;
|
||||
kitkat.productIdnf = "KIT_KAT";
|
||||
kitkat.description = "Chocolate";
|
||||
s.persist(kitkat);
|
||||
Product kitkat = new Product();
|
||||
kitkat.id = 2;
|
||||
kitkat.productIdnf = "KIT_KAT";
|
||||
kitkat.description = "Chocolate";
|
||||
session.persist(kitkat);
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
kit = (Product) s.get(Product.class, 1);
|
||||
kitkat = (Product) s.get(Product.class, 2);
|
||||
System.out.println(kitkat.description);
|
||||
assertNotNull(kitkat);
|
||||
assertEquals(kit, kitkat.getProductFamily());
|
||||
assertEquals(kit.productIdnf, kitkat.getProductFamily().productIdnf);
|
||||
assertEquals("KIT_KAT", kitkat.productIdnf.trim());
|
||||
assertEquals("Chocolate", kitkat.description.trim());
|
||||
kit = session.get(Product.class, 1);
|
||||
kitkat = session.get(Product.class, 2);
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
assertThat( kitkat ).isNotNull();
|
||||
assertThat( kitkat.getProductFamily() ).isEqualTo( kit );
|
||||
assertThat( kit.productIdnf ).isEqualTo( kitkat.getProductFamily().productIdnf );
|
||||
assertThat( kitkat.productIdnf.trim() ).isEqualTo( "KIT_KAT" );
|
||||
assertThat( kitkat.description.trim() ).isEqualTo( "Chocolate" );
|
||||
|
||||
session.getTransaction().markRollbackOnly();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresDialect(value = { SQLServerDialect.class})
|
||||
public void testManyToOneFromNonPkToNonPkSqlServer() throws Exception {
|
||||
// also tests usage of the stand-alone @JoinFormula annotation (i.e. not wrapped within @JoinColumnsOrFormulas)
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
@RequiresDialect( SQLServerDialect.class )
|
||||
public void testManyToOneFromNonPkToNonPkSqlServer(SessionFactoryScope scope) {
|
||||
// also tests usage of the stand-alone @JoinFormula annotation
|
||||
// (i.e. not wrapped within @JoinColumnsOrFormulas)
|
||||
|
||||
ProductSqlServer kit = new ProductSqlServer();
|
||||
kit.id = 1;
|
||||
kit.productIdnf = "KIT";
|
||||
kit.description = "Kit";
|
||||
s.persist(kit);
|
||||
scope.inTransaction( (session) -> {
|
||||
ProductSqlServer kit = new ProductSqlServer();
|
||||
kit.id = 1;
|
||||
kit.productIdnf = "KIT";
|
||||
kit.description = "Kit";
|
||||
session.persist(kit);
|
||||
|
||||
ProductSqlServer kitkat = new ProductSqlServer();
|
||||
kitkat.id = 2;
|
||||
kitkat.productIdnf = "KIT_KAT";
|
||||
kitkat.description = "Chocolate";
|
||||
s.persist(kitkat);
|
||||
ProductSqlServer kitkat = new ProductSqlServer();
|
||||
kitkat.id = 2;
|
||||
kitkat.productIdnf = "KIT_KAT";
|
||||
kitkat.description = "Chocolate";
|
||||
session.persist(kitkat);
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
kit = (ProductSqlServer) s.get(ProductSqlServer.class, 1);
|
||||
kitkat = (ProductSqlServer) s.get(ProductSqlServer.class, 2);
|
||||
System.out.println(kitkat.description);
|
||||
assertNotNull(kitkat);
|
||||
assertEquals(kit, kitkat.getProductFamily());
|
||||
assertEquals(kit.productIdnf, kitkat.getProductFamily().productIdnf);
|
||||
assertEquals("KIT_KAT", kitkat.productIdnf.trim());
|
||||
assertEquals("Chocolate", kitkat.description.trim());
|
||||
kit = session.get(ProductSqlServer.class, 1);
|
||||
kitkat = session.get(ProductSqlServer.class, 2);
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
assertThat( kitkat ).isNotNull();
|
||||
assertThat( kitkat.getProductFamily() ).isEqualTo( kit );
|
||||
assertThat( kit.productIdnf ).isEqualTo( kitkat.getProductFamily().productIdnf );
|
||||
assertThat( kitkat.productIdnf.trim() ).isEqualTo( "KIT_KAT" );
|
||||
assertThat( kitkat.description.trim() ).isEqualTo( "Chocolate" );
|
||||
|
||||
session.getTransaction().markRollbackOnly();
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Menu.class,
|
||||
FoodItem.class,
|
||||
Company.class,
|
||||
Person.class,
|
||||
Message.class,
|
||||
Language.class,
|
||||
Contract.class,
|
||||
ContractId.class,
|
||||
Model.class,
|
||||
ModelId.class,
|
||||
Manufacturer.class,
|
||||
ManufacturerId.class,
|
||||
Product.class,
|
||||
ProductSqlServer.class
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,15 +6,17 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.annotations.uniqueconstraint;
|
||||
|
||||
import jakarta.persistence.PersistenceException;
|
||||
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.PersistenceException;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -23,52 +25,45 @@ import static org.junit.Assert.fail;
|
|||
* @author Manuel Bernhardt
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
@SkipForDialect(value = SybaseDialect.class,
|
||||
comment = "Sybase does not properly support unique constraints on nullable columns")
|
||||
public class UniqueConstraintTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Room.class,
|
||||
Building.class,
|
||||
House.class
|
||||
};
|
||||
}
|
||||
@DomainModel( annotatedClasses = { Room.class, Building.class, House.class } )
|
||||
@SessionFactory
|
||||
@SkipForDialect( dialectClass = SybaseDialect.class,
|
||||
reason = "Sybase does not properly support unique constraints on nullable columns" )
|
||||
public class UniqueConstraintTest {
|
||||
|
||||
@Test
|
||||
public void testUniquenessConstraintWithSuperclassProperty() {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Room livingRoom = new Room();
|
||||
livingRoom.setId(1l);
|
||||
livingRoom.setName("livingRoom");
|
||||
s.persist(livingRoom);
|
||||
s.flush();
|
||||
House house = new House();
|
||||
house.setId(1l);
|
||||
house.setCost(100);
|
||||
house.setHeight(1000l);
|
||||
house.setRoom(livingRoom);
|
||||
s.persist(house);
|
||||
s.flush();
|
||||
House house2 = new House();
|
||||
house2.setId(2l);
|
||||
house2.setCost(100);
|
||||
house2.setHeight(1001l);
|
||||
house2.setRoom(livingRoom);
|
||||
s.persist(house2);
|
||||
try {
|
||||
public void testUniquenessConstraintWithSuperclassProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (s) -> {
|
||||
Room livingRoom = new Room();
|
||||
livingRoom.setId(1l);
|
||||
livingRoom.setName("livingRoom");
|
||||
s.persist(livingRoom);
|
||||
s.flush();
|
||||
fail( "Database constraint non-existent" );
|
||||
}
|
||||
catch (PersistenceException e) {
|
||||
assertTyping( JDBCException.class, e );
|
||||
//success
|
||||
}
|
||||
finally {
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
House house = new House();
|
||||
house.setId(1l);
|
||||
house.setCost(100);
|
||||
house.setHeight(1000l);
|
||||
house.setRoom(livingRoom);
|
||||
s.persist(house);
|
||||
s.flush();
|
||||
House house2 = new House();
|
||||
house2.setId(2l);
|
||||
house2.setCost(100);
|
||||
house2.setHeight(1001l);
|
||||
house2.setRoom(livingRoom);
|
||||
s.persist(house2);
|
||||
try {
|
||||
s.flush();
|
||||
fail( "Database constraint non-existent" );
|
||||
}
|
||||
catch (PersistenceException e) {
|
||||
assertTyping( JDBCException.class, e );
|
||||
//success
|
||||
}
|
||||
finally {
|
||||
s.getTransaction().markRollbackOnly();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,142 +9,130 @@ package org.hibernate.orm.test.annotations.xml.ejb3;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.persister.collection.BasicCollectionPersister;
|
||||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class Ejb3XmlTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapRegistryBuilder( builder );
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = {PostgreSQLDialect.class, CockroachDialect.class},
|
||||
comment = "postgresql jdbc driver does not implement the setQueryTimeout method")
|
||||
public void testEjb3Xml() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
CarModel model = new CarModel();
|
||||
model.setYear( new Date() );
|
||||
Manufacturer manufacturer = new Manufacturer();
|
||||
//s.persist( manufacturer );
|
||||
model.setManufacturer( manufacturer );
|
||||
manufacturer.getModels().add( model );
|
||||
s.persist( model );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
model.setYear( new Date() );
|
||||
manufacturer = (Manufacturer) s.get( Manufacturer.class, manufacturer.getId() );
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Model> cars = s.getNamedQuery( "allModelsPerManufacturer" )
|
||||
.setParameter( "manufacturer", manufacturer )
|
||||
.list();
|
||||
assertEquals( 1, cars.size() );
|
||||
for ( Model car : cars ) {
|
||||
assertNotNull( car.getManufacturer() );
|
||||
s.delete( manufacturer );
|
||||
s.delete( car );
|
||||
}
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXMLEntityHandled() throws Exception {
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
Lighter l = new Lighter();
|
||||
l.name = "Blue";
|
||||
l.power = "400F";
|
||||
s.persist( l );
|
||||
s.flush();
|
||||
s.getTransaction().rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlDefaultOverriding() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Manufacturer manufacturer = new Manufacturer();
|
||||
s.persist( manufacturer );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
assertEquals( 1, s.getNamedQuery( "manufacturer.findAll" ).list().size() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMapXMLSupport() throws Exception {
|
||||
Session s = openSession();
|
||||
SessionFactory sf = s.getSessionFactory();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
// Verify that we can persist an object with a couple Map mappings
|
||||
VicePresident vpSales = new VicePresident();
|
||||
vpSales.name = "Dwight";
|
||||
Company company = new Company();
|
||||
company.conferenceRoomExtensions.put( "8932", "x1234" );
|
||||
company.organization.put( "sales", vpSales );
|
||||
s.persist( company );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
// For the element-collection, check that the orm.xml entries are honored.
|
||||
// This includes: map-key-column/column/collection-table/join-column
|
||||
BasicCollectionPersister confRoomMeta = (BasicCollectionPersister) sf
|
||||
.unwrap( SessionFactoryImplementor.class )
|
||||
.getMappingMetamodel()
|
||||
.getCollectionDescriptor( Company.class.getName() + ".conferenceRoomExtensions" );
|
||||
assertEquals( "company_id", confRoomMeta.getKeyColumnNames()[0] );
|
||||
assertEquals( "phone_extension", confRoomMeta.getElementColumnNames()[0] );
|
||||
assertEquals( "room_number", confRoomMeta.getIndexColumnNames()[0] );
|
||||
assertEquals( "phone_extension_lookup", confRoomMeta.getTableName() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
CarModel.class,
|
||||
Manufacturer.class,
|
||||
Model.class,
|
||||
Light.class
|
||||
//Lighter.class xml only entuty
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getOrmXmlFiles() {
|
||||
return new String[] {
|
||||
@DomainModel(
|
||||
annotatedClasses = { CarModel.class, Manufacturer.class, Model.class, Light.class },
|
||||
xmlMappings = {
|
||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm.xml",
|
||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm2.xml",
|
||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm3.xml",
|
||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm4.xml"
|
||||
};
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class Ejb3XmlTest {
|
||||
|
||||
@Test
|
||||
@SkipForDialect( dialectClass = PostgreSQLDialect.class,
|
||||
reason = "driver does not implement the setQueryTimeout method" )
|
||||
@SkipForDialect( dialectClass = CockroachDialect.class,
|
||||
reason = "driver does not implement the setQueryTimeout method" )
|
||||
public void testEjb3Xml(SessionFactoryScope scope) {
|
||||
scope.inSession( (s) -> {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CarModel model = new CarModel();
|
||||
model.setYear( new Date() );
|
||||
Manufacturer manufacturer = new Manufacturer();
|
||||
//s.persist( manufacturer );
|
||||
model.setManufacturer( manufacturer );
|
||||
manufacturer.getModels().add( model );
|
||||
s.persist( model );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
model.setYear( new Date() );
|
||||
manufacturer = s.get( Manufacturer.class, manufacturer.getId() );
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Model> cars = s.getNamedQuery( "allModelsPerManufacturer" )
|
||||
.setParameter( "manufacturer", manufacturer )
|
||||
.list();
|
||||
assertEquals( 1, cars.size() );
|
||||
for ( Model car : cars ) {
|
||||
Assertions.assertNotNull( car.getManufacturer() );
|
||||
s.remove( manufacturer );
|
||||
s.remove( car );
|
||||
}
|
||||
|
||||
s.getTransaction().rollback();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXMLEntityHandled(SessionFactoryScope scope) {
|
||||
scope.inSession( (s) -> {
|
||||
s.getTransaction().begin();
|
||||
Lighter l = new Lighter();
|
||||
l.name = "Blue";
|
||||
l.power = "400F";
|
||||
s.persist( l );
|
||||
s.flush();
|
||||
s.getTransaction().rollback();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlDefaultOverriding(SessionFactoryScope scope) {
|
||||
scope.inSession( (s) -> {
|
||||
Transaction tx = s.beginTransaction();
|
||||
Manufacturer manufacturer = new Manufacturer();
|
||||
s.persist( manufacturer );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
assertEquals( 1, s.getNamedQuery( "manufacturer.findAll" ).list().size() );
|
||||
|
||||
tx.rollback();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMapXMLSupport(SessionFactoryScope scope) {
|
||||
scope.inSession( (s) -> {
|
||||
SessionFactoryImplementor sf = s.getSessionFactory();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
// Verify that we can persist an object with a couple Map mappings
|
||||
VicePresident vpSales = new VicePresident();
|
||||
vpSales.name = "Dwight";
|
||||
Company company = new Company();
|
||||
company.conferenceRoomExtensions.put( "8932", "x1234" );
|
||||
company.organization.put( "sales", vpSales );
|
||||
s.persist( company );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
// For the element-collection, check that the orm.xml entries are honored.
|
||||
// This includes: map-key-column/column/collection-table/join-column
|
||||
BasicCollectionPersister confRoomMeta = (BasicCollectionPersister) sf
|
||||
.unwrap( SessionFactoryImplementor.class )
|
||||
.getMappingMetamodel()
|
||||
.getCollectionDescriptor( Company.class.getName() + ".conferenceRoomExtensions" );
|
||||
assertEquals( "company_id", confRoomMeta.getKeyColumnNames()[0] );
|
||||
assertEquals( "phone_extension", confRoomMeta.getElementColumnNames()[0] );
|
||||
assertEquals( "room_number", confRoomMeta.getIndexColumnNames()[0] );
|
||||
assertEquals( "phone_extension_lookup", confRoomMeta.getTableName() );
|
||||
tx.rollback();
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
Loading…
Reference in New Issue