Re-enabled additional tests and fix issues with IdClass
This commit is contained in:
parent
52ba3d9c5a
commit
e3947b3b1c
|
@ -7,17 +7,12 @@
|
|||
package org.hibernate.userguide.pc;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.Target;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.test.annotations.id.entities.Shoe;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
|
|
|
@ -153,10 +153,10 @@ public class MappingModelCreationHelper {
|
|||
PersistentClass bootEntityDescriptor,
|
||||
BiConsumer<String,SingularAttributeMapping> idSubAttributeConsumer,
|
||||
MappingModelCreationProcess creationProcess) {
|
||||
final Component bootCompositeDescriptor = (Component) bootEntityDescriptor.getIdentifier();
|
||||
final Component bootIdClassComponent = (Component) bootEntityDescriptor.getIdentifier();
|
||||
|
||||
final EmbeddableMappingType embeddableMappingType = EmbeddableMappingType.from(
|
||||
bootCompositeDescriptor,
|
||||
bootIdClassComponent,
|
||||
cidType,
|
||||
attributeMappingType -> {
|
||||
final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory();
|
||||
|
@ -167,15 +167,19 @@ public class MappingModelCreationHelper {
|
|||
final StateArrayContributorMetadataAccess attributeMetadataAccess = getStateArrayContributorMetadataAccess(
|
||||
propertyAccess
|
||||
);
|
||||
final Component idClass = bootEntityDescriptor.getIdentifierMapper();
|
||||
Component bootIdDescriptor = bootEntityDescriptor.getDeclaredIdentifierMapper();
|
||||
if ( bootIdDescriptor == null ) {
|
||||
bootIdDescriptor = (Component) bootEntityDescriptor.getIdentifier();
|
||||
}
|
||||
final List<SingularAttributeMapping> idAttributeMappings = new ArrayList<>( bootIdDescriptor.getPropertySpan() );
|
||||
Component bootComponentDescriptor = bootEntityDescriptor.getIdentifierMapper();
|
||||
final List<SingularAttributeMapping> idAttributeMappings;
|
||||
final Iterator<Property> bootIdSubPropertyItr;
|
||||
if ( bootComponentDescriptor == null ) {
|
||||
idAttributeMappings = new ArrayList<>( bootIdClassComponent.getPropertySpan() );
|
||||
bootIdSubPropertyItr = bootIdClassComponent.getPropertyIterator();
|
||||
|
||||
}
|
||||
else {
|
||||
idAttributeMappings = new ArrayList<>( bootComponentDescriptor.getPropertySpan() );
|
||||
bootIdSubPropertyItr = bootComponentDescriptor.getPropertyIterator();
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
final Iterator<Property> bootIdSubPropertyItr = bootIdDescriptor.getPropertyIterator();
|
||||
int columnsConsumedSoFar = 0;
|
||||
|
||||
while ( bootIdSubPropertyItr.hasNext() ) {
|
||||
|
@ -245,7 +249,7 @@ public class MappingModelCreationHelper {
|
|||
}
|
||||
|
||||
idAttributeMappings.add( idSubAttribute );
|
||||
if ( idClass == null ) {
|
||||
if ( bootComponentDescriptor == null ) {
|
||||
idSubAttributeConsumer.accept( idSubAttribute.getAttributeName(), idSubAttribute );
|
||||
}
|
||||
}
|
||||
|
@ -257,8 +261,8 @@ public class MappingModelCreationHelper {
|
|||
attributeMetadataAccess,
|
||||
rootTableName,
|
||||
rootTableKeyColumnNames,
|
||||
bootIdDescriptor,
|
||||
bootCompositeDescriptor,
|
||||
bootIdClassComponent,
|
||||
bootComponentDescriptor,
|
||||
creationProcess
|
||||
);
|
||||
},
|
||||
|
|
|
@ -48,8 +48,8 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif
|
|||
StateArrayContributorMetadataAccess attributeMetadataAccess,
|
||||
String rootTableName,
|
||||
String[] rootTableKeyColumnNames,
|
||||
Component bootCidDescriptor,
|
||||
Component bootIdClassDescriptor,
|
||||
Component bootCidDescriptor,
|
||||
MappingModelCreationProcess creationProcess) {
|
||||
// todo (6.0) : handle MapsId
|
||||
super(
|
||||
|
@ -78,9 +78,6 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif
|
|||
|
||||
@Override
|
||||
public Object getIdentifier(Object entity, SharedSessionContractImplementor session) {
|
||||
if ( entity instanceof HibernateProxy ) {
|
||||
return ( (HibernateProxy) entity ).getHibernateLazyInitializer().getIdentifier();
|
||||
}
|
||||
final Serializable disassemble = bootCidDescriptor.getType().disassemble( entity, session, null );
|
||||
return bootIdClassDescriptor.getType().assemble( disassemble, session, null );
|
||||
}
|
||||
|
|
|
@ -346,6 +346,11 @@ public abstract class AbstractIdentifiableType<J>
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyIdClassAttributes(Set idClassAttributes) {
|
||||
applyNonAggregatedIdAttributes( idClassAttributes );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void applyVersionAttribute(SingularPersistentAttribute versionAttribute) {
|
||||
|
|
|
@ -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.test.annotations.id;
|
||||
package org.hibernate.orm.test.annotations.id;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
@ -15,30 +15,33 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
|
|||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.CannotForceNonNullableException;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.junit5.BaseUnitTest;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Originally developed for HHH-9807 - better error message on combination of {@code @Id} + {@code @Formula}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class AndFormulaTest extends BaseUnitTestCase {
|
||||
@ServiceRegistry
|
||||
public class AndFormulaTest extends BaseUnitTest {
|
||||
private static StandardServiceRegistry ssr;
|
||||
|
||||
@BeforeClass
|
||||
public static void prepareServiceRegistry() {
|
||||
@BeforeEach
|
||||
public void prepareServiceRegistry() {
|
||||
ssr = new StandardServiceRegistryBuilder().build();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void releaseServiceRegistry() {
|
||||
@AfterEach
|
||||
public void releaseServiceRegistry() {
|
||||
if ( ssr != null ) {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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.annotations.id;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Planet;
|
||||
import org.hibernate.orm.test.annotations.id.entities.PlanetCheatSheet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for enum type as id.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@TestForIssue(jiraKey = "ANN-744")
|
||||
@DomainModel(
|
||||
annotatedClasses = PlanetCheatSheet.class
|
||||
)
|
||||
@SessionFactory
|
||||
public class EnumIdTest {
|
||||
|
||||
@Test
|
||||
public void testEnumAsId(SessionFactoryScope scope) {
|
||||
PlanetCheatSheet mercury = new PlanetCheatSheet();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
mercury.setPlanet( Planet.MERCURY );
|
||||
mercury.setMass( 3.303e+23 );
|
||||
mercury.setRadius( 2.4397e6 );
|
||||
mercury.setNumberOfInhabitants( 0 );
|
||||
session.persist( mercury );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
PlanetCheatSheet mercuryFromDb = session.get( PlanetCheatSheet.class, mercury.getPlanet() );
|
||||
assertNotNull( mercuryFromDb );
|
||||
session.delete( mercuryFromDb );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
PlanetCheatSheet mercuryFromDb = session.get(
|
||||
PlanetCheatSheet.class,
|
||||
Planet.MERCURY
|
||||
);
|
||||
assertNull( mercuryFromDb );
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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.annotations.id;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Location;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Tower;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = Tower.class
|
||||
)
|
||||
@SessionFactory
|
||||
public class IdClassTest {
|
||||
|
||||
@Test
|
||||
public void testIdClassInSuperclass(SessionFactoryScope scope) {
|
||||
Tower tower = new Tower();
|
||||
tower.latitude = 10.3;
|
||||
tower.longitude = 45.4;
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( tower );
|
||||
session.flush();
|
||||
session.clear();
|
||||
Location loc = new Location();
|
||||
loc.latitude = tower.latitude;
|
||||
loc.longitude = tower.longitude;
|
||||
assertNotNull( session.get( Tower.class, loc ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,353 @@
|
|||
/*
|
||||
* 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.annotations.id;
|
||||
|
||||
import org.hibernate.mapping.Column;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Ball;
|
||||
import org.hibernate.orm.test.annotations.id.entities.BreakDance;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Computer;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Department;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Dog;
|
||||
import org.hibernate.orm.test.annotations.id.entities.FirTree;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Footballer;
|
||||
import org.hibernate.orm.test.annotations.id.entities.FootballerPk;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Furniture;
|
||||
import org.hibernate.orm.test.annotations.id.entities.GoalKeeper;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Home;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Hotel;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Monkey;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Phone;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Shoe;
|
||||
import org.hibernate.orm.test.annotations.id.entities.SoundSystem;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Store;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Tree;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Ball.class, Shoe.class, Store.class,
|
||||
Department.class, Dog.class, Computer.class, Home.class,
|
||||
Phone.class, Tree.class, FirTree.class, Footballer.class,
|
||||
SoundSystem.class, Furniture.class, GoalKeeper.class,
|
||||
BreakDance.class, Monkey.class, Hotel.class
|
||||
},
|
||||
annotatedPackageNames = {
|
||||
"org.hibernate.orm.test.annotations",
|
||||
"org.hibernate.orm.test.annotations.id"
|
||||
},
|
||||
xmlMappings = "org/hibernate/test/annotations/orm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class IdTest {
|
||||
|
||||
@Test
|
||||
public void testNoGenerator(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Hotel hotel = new Hotel();
|
||||
hotel.setId( 12L );
|
||||
hotel.setName( "California" );
|
||||
session.saveOrUpdate( hotel );
|
||||
}
|
||||
);
|
||||
|
||||
Hotel savedHotel = scope.fromTransaction(
|
||||
session -> {
|
||||
Hotel hotel = session.get( Hotel.class, 12L );
|
||||
assertNotNull( hotel );
|
||||
assertEquals( "California", hotel.getName() );
|
||||
assertNull( session.get( Hotel.class, 13L ) );
|
||||
return hotel;
|
||||
}
|
||||
);
|
||||
|
||||
//savedHotel is now detached
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
savedHotel.setName( "Hotel du nord" );
|
||||
session.saveOrUpdate( savedHotel );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Hotel hotel = session.get( Hotel.class, 12L );
|
||||
assertNotNull( hotel );
|
||||
assertEquals( "Hotel du nord", hotel.getName() );
|
||||
session.delete( hotel );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericGenerator(SessionFactoryScope scope) {
|
||||
SoundSystem system = new SoundSystem();
|
||||
Furniture fur = new Furniture();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
system.setBrand( "Genelec" );
|
||||
system.setModel( "T234" );
|
||||
session.persist( system );
|
||||
session.persist( fur );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
SoundSystem systemFromDb = session.get( SoundSystem.class, system.getId() );
|
||||
Furniture furFromDb = session.get( Furniture.class, fur.getId() );
|
||||
assertNotNull( systemFromDb );
|
||||
assertNotNull( furFromDb );
|
||||
session.delete( systemFromDb );
|
||||
session.delete( furFromDb );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensures that GenericGenerator annotations wrapped inside a
|
||||
* GenericGenerators holder are bound correctly
|
||||
*/
|
||||
@Test
|
||||
public void testGenericGenerators(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Monkey monkey = new Monkey();
|
||||
session.persist( monkey );
|
||||
session.flush();
|
||||
assertNotNull( monkey.getId() );
|
||||
session.delete( monkey );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableGenerator(SessionFactoryScope scope) {
|
||||
|
||||
Ball b = new Ball();
|
||||
Dog d = new Dog();
|
||||
Computer c = new Computer();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( b );
|
||||
session.persist( d );
|
||||
session.persist( c );
|
||||
}
|
||||
);
|
||||
|
||||
assertEquals( new Integer( 1 ), b.getId(), "table id not generated" );
|
||||
assertEquals( new Integer( 1 ), d.getId(), "generator should not be shared" );
|
||||
assertEquals( new Long( 1 ), c.getId(), "default value should work" );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.delete( session.get( Ball.class, 1 ) );
|
||||
session.delete( session.get( Dog.class, 1 ) );
|
||||
session.delete( session.get( Computer.class, 1L ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceGenerator(SessionFactoryScope scope) {
|
||||
Shoe b = new Shoe();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( b )
|
||||
);
|
||||
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( session.get( Shoe.class, b.getId() ) )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassLevelGenerator(SessionFactoryScope scope) {
|
||||
Store b = new Store();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( b )
|
||||
);
|
||||
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( session.get( Store.class, b.getId() ) )
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodLevelGenerator(SessionFactoryScope scope) {
|
||||
Department b = new Department();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( b )
|
||||
);
|
||||
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( session.get( Department.class, b.getId() ) )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSequence(SessionFactoryScope scope) {
|
||||
Home h = new Home();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( h )
|
||||
);
|
||||
|
||||
assertNotNull( h.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Home reloadedHome = session.get( Home.class, h.getId() );
|
||||
assertEquals( h.getId(), reloadedHome.getId() );
|
||||
session.delete( reloadedHome );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizedAuto(SessionFactoryScope scope) {
|
||||
Home h = new Home();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( h )
|
||||
);
|
||||
|
||||
assertNotNull( h.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Home reloadedHome = session.get( Home.class, h.getId() );
|
||||
assertEquals( h.getId(), reloadedHome.getId() );
|
||||
session.delete( reloadedHome );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdInEmbeddableSuperclass(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
FirTree christmasTree = new FirTree();
|
||||
session.persist( christmasTree );
|
||||
session.getTransaction().commit();
|
||||
session.clear();
|
||||
session.beginTransaction();
|
||||
christmasTree = session.get( FirTree.class, christmasTree.getId() );
|
||||
assertNotNull( christmasTree );
|
||||
session.delete( christmasTree );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Footballer fb = new Footballer( "David", "Beckam", "Arsenal" );
|
||||
GoalKeeper keeper = new GoalKeeper( "Fabien", "Bartez", "OM" );
|
||||
session.persist( fb );
|
||||
session.persist( keeper );
|
||||
session.getTransaction().commit();
|
||||
session.clear();
|
||||
|
||||
// lookup by id
|
||||
session.beginTransaction();
|
||||
FootballerPk fpk = new FootballerPk( "David", "Beckam" );
|
||||
fb = session.get( Footballer.class, fpk );
|
||||
FootballerPk fpk2 = new FootballerPk( "Fabien", "Bartez" );
|
||||
keeper = session.get( GoalKeeper.class, fpk2 );
|
||||
assertNotNull( fb );
|
||||
assertNotNull( keeper );
|
||||
assertEquals( "Beckam", fb.getLastname() );
|
||||
assertEquals( "Arsenal", fb.getClub() );
|
||||
assertEquals( 1, session.createQuery(
|
||||
"from Footballer f where f.firstname = 'David'" ).list().size() );
|
||||
session.getTransaction().commit();
|
||||
|
||||
// reattach by merge
|
||||
session.beginTransaction();
|
||||
fb.setClub( "Bimbo FC" );
|
||||
session.merge( fb );
|
||||
session.getTransaction().commit();
|
||||
|
||||
// reattach by saveOrUpdate
|
||||
session.beginTransaction();
|
||||
fb.setClub( "Bimbo FC SA" );
|
||||
session.saveOrUpdate( fb );
|
||||
session.getTransaction().commit();
|
||||
|
||||
// clean up
|
||||
session.clear();
|
||||
session.beginTransaction();
|
||||
fpk = new FootballerPk( "David", "Beckam" );
|
||||
fb = session.get( Footballer.class, fpk );
|
||||
assertEquals( "Bimbo FC SA", fb.getClub() );
|
||||
session.delete( fb );
|
||||
session.delete( keeper );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnDefinition(SessionFactoryScope scope) {
|
||||
Column idCol = (Column) scope.getMetadataImplementor().getEntityBinding( Ball.class.getName() )
|
||||
.getIdentifierProperty()
|
||||
.getValue()
|
||||
.getColumnIterator()
|
||||
.next();
|
||||
assertEquals( "ball_id", idCol.getName() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowAllocationSize(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
int size = 4;
|
||||
BreakDance[] bds = new BreakDance[size];
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
bds[i] = new BreakDance();
|
||||
session.persist( bds[i] );
|
||||
}
|
||||
session.flush();
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
assertEquals( i + 1, bds[i].id.intValue() );
|
||||
}
|
||||
}
|
||||
);
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from BreakDance" ).executeUpdate()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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.test.annotations.id;
|
||||
package org.hibernate.orm.test.annotations.id;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,15 +16,13 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.test.annotations.id.entities.Bunny;
|
||||
import org.hibernate.test.annotations.id.entities.PointyTooth;
|
||||
import org.hibernate.test.annotations.id.entities.TwinkleToes;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.junit5.BaseUnitTest;
|
||||
import org.hibernate.orm.test.annotations.id.entities.Bunny;
|
||||
import org.hibernate.orm.test.annotations.id.entities.PointyTooth;
|
||||
import org.hibernate.orm.test.annotations.id.entities.TwinkleToes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for JIRA issue ANN-748.
|
||||
|
@ -32,7 +30,7 @@ import static org.junit.Assert.assertTrue;
|
|||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class JoinColumnOverrideTest extends BaseUnitTestCase {
|
||||
public class JoinColumnOverrideTest extends BaseUnitTest {
|
||||
|
||||
private static final String expectedSqlPointyTooth = "create table PointyTooth (id numeric(128,0) not null, " +
|
||||
"bunny_id numeric(128,0), primary key (id))";
|
||||
|
@ -40,8 +38,8 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase {
|
|||
"bunny_id numeric(128,0), primary key (id))";
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "ANN-748" )
|
||||
public void testBlownPrecision() throws Exception {
|
||||
@TestForIssue(jiraKey = "ANN-748")
|
||||
public void testBlownPrecision() {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, "SQLServer" )
|
||||
.build();
|
||||
|
@ -58,7 +56,6 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase {
|
|||
|
||||
List<String> commands = new SchemaCreatorImpl( ssr ).generateCreationCommands( metadata, false );
|
||||
for ( String command : commands ) {
|
||||
log.debug( command );
|
||||
|
||||
if ( expectedSqlPointyTooth.equals( command ) ) {
|
||||
foundPointyToothCreate = true;
|
||||
|
@ -68,8 +65,8 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
assertTrue( "Expected create table command for PointyTooth entity not found", foundPointyToothCreate );
|
||||
assertTrue( "Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate );
|
||||
assertTrue( foundPointyToothCreate, "Expected create table command for PointyTooth entity not found" );
|
||||
assertTrue( foundTwinkleToesCreate, "Expected create table command for TwinkleToes entity not found" );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
|
@ -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.test.annotations.id;
|
||||
package org.hibernate.orm.test.annotations.id;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.UUID;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -6,10 +6,9 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
|
@ -32,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator;
|
|||
public class Bunny implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator")
|
||||
@Column(name = "id", precision = 128, scale = 0)
|
||||
private BigDecimal id;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -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.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.MappedSuperclass;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
// $Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
|
||||
|
||||
public enum Planet {
|
|
@ -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.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import javax.persistence.Column;
|
||||
|
@ -31,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator;
|
|||
public class PointyTooth implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator")
|
||||
@Column(name = "id", precision = 128, scale = 0)
|
||||
private BigDecimal id;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
|
@ -6,10 +6,9 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.entities;
|
||||
package org.hibernate.orm.test.annotations.id.entities;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
@ -32,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator;
|
|||
public class TwinkleToes implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator")
|
||||
@Column(name = "id", precision = 128, scale = 0)
|
||||
private BigDecimal id;
|
||||
|
|
@ -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.test.annotations.id.generationmappings;
|
||||
package org.hibernate.orm.test.annotations.id.generationmappings;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -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.test.annotations.id.generationmappings;
|
||||
package org.hibernate.orm.test.annotations.id.generationmappings;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -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.test.annotations.id.generationmappings;
|
||||
package org.hibernate.orm.test.annotations.id.generationmappings;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
|
@ -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.test.annotations.id.generationmappings;
|
||||
package org.hibernate.orm.test.annotations.id.generationmappings;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
|
@ -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.test.annotations.id.generationmappings;
|
||||
package org.hibernate.orm.test.annotations.id.generationmappings;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -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.test.annotations.id.generationmappings;
|
||||
package org.hibernate.orm.test.annotations.id.generationmappings;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -4,11 +4,8 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.annotations.id.generationmappings;
|
||||
package org.hibernate.orm.test.annotations.id.generationmappings;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.enhanced.NoopOptimizer;
|
||||
|
@ -18,11 +15,15 @@ import org.hibernate.id.enhanced.TableGenerator;
|
|||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Test mapping the {@link javax.persistence.GenerationType GenerationTypes} to the corresponding
|
||||
|
@ -31,38 +32,29 @@ import static org.junit.Assert.assertTrue;
|
|||
* @author Steve Ebersole
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
MinimalSequenceEntity.class,
|
||||
CompleteSequenceEntity.class,
|
||||
AutoEntity.class,
|
||||
MinimalTableEntity.class,
|
||||
DedicatedSequenceEntity1.class,
|
||||
DedicatedSequenceEntity2.class
|
||||
};
|
||||
}
|
||||
},
|
||||
annotatedPackageNames = {
|
||||
"org.hibernate.orm.test.annotations.id.generationmappings"
|
||||
}
|
||||
)
|
||||
@SessionFactory(
|
||||
exportSchema = false
|
||||
)
|
||||
@ServiceRegistry(settings = @ServiceRegistry.Setting(name =Environment.HBM2DDL_AUTO, value = ""))
|
||||
public class NewGeneratorMappingsTest {
|
||||
|
||||
@Override
|
||||
protected String[] getAnnotatedPackages() {
|
||||
return new String[] { this.getClass().getPackage().getName() };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean createSchema() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalSequenceEntity() {
|
||||
final EntityPersister persister = sessionFactory().getEntityPersister( MinimalSequenceEntity.class.getName() );
|
||||
public void testMinimalSequenceEntity(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( MinimalSequenceEntity.class.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
|
@ -75,8 +67,8 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteSequenceEntity() {
|
||||
final EntityPersister persister = sessionFactory().getEntityPersister( CompleteSequenceEntity.class.getName() );
|
||||
public void testCompleteSequenceEntity(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( CompleteSequenceEntity.class.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
|
@ -86,8 +78,8 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAutoEntity() {
|
||||
final EntityPersister persister = sessionFactory().getEntityPersister( AutoEntity.class.getName() );
|
||||
public void testAutoEntity(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( AutoEntity.class.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
|
@ -97,8 +89,8 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalTableEntity() {
|
||||
final EntityPersister persister = sessionFactory().getEntityPersister( MinimalTableEntity.class.getName() );
|
||||
public void testMinimalTableEntity(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( MinimalTableEntity.class.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
assertTrue( TableGenerator.class.isInstance( generator ) );
|
||||
TableGenerator tabGenerator = (TableGenerator) generator;
|
||||
|
@ -115,9 +107,9 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-6790")
|
||||
public void testSequencePerEntity() {
|
||||
public void testSequencePerEntity(SessionFactoryScope scope) {
|
||||
// Checking first entity.
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( DedicatedSequenceEntity1.class.getName() );
|
||||
EntityPersister persister = scope.getSessionFactory().getEntityPersister( DedicatedSequenceEntity1.class.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
|
@ -127,7 +119,7 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase {
|
|||
);
|
||||
|
||||
// Checking second entity.
|
||||
persister = sessionFactory().getEntityPersister( DedicatedSequenceEntity2.class.getName() );
|
||||
persister = scope.getSessionFactory().getEntityPersister( DedicatedSequenceEntity2.class.getName() );
|
||||
generator = persister.getIdentifierGenerator();
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
seqGenerator = (SequenceStyleGenerator) generator;
|
|
@ -12,7 +12,7 @@
|
|||
}
|
||||
|
||||
)
|
||||
package org.hibernate.test.annotations.id.generationmappings;
|
||||
package org.hibernate.orm.test.annotations.id.generationmappings;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
|
@ -14,6 +14,6 @@
|
|||
@org.hibernate.annotations.GenericGenerators(
|
||||
@org.hibernate.annotations.GenericGenerator(name = "system-uuid-2", strategy = "uuid")
|
||||
)
|
||||
package org.hibernate.test.annotations.id;
|
||||
package org.hibernate.orm.test.annotations.id;
|
||||
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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.annotations.id.sequences;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Planet;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.PlanetCheatSheet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* Tests for enum type as id.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@TestForIssue(jiraKey = "ANN-744")
|
||||
@DomainModel(
|
||||
annotatedClasses = PlanetCheatSheet.class
|
||||
)
|
||||
@SessionFactory
|
||||
public class EnumIdTest {
|
||||
|
||||
@Test
|
||||
public void testEnumAsId(SessionFactoryScope scope) {
|
||||
PlanetCheatSheet mercury = new PlanetCheatSheet();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
mercury.setPlanet( Planet.MERCURY );
|
||||
mercury.setMass( 3.303e+23 );
|
||||
mercury.setRadius( 2.4397e6 );
|
||||
mercury.setNumberOfInhabitants( 0 );
|
||||
session.persist( mercury );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
PlanetCheatSheet mercuryFromDb = session.get(
|
||||
PlanetCheatSheet.class,
|
||||
mercury.getPlanet()
|
||||
);
|
||||
assertNotNull( mercuryFromDb );
|
||||
session.delete( mercuryFromDb );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
PlanetCheatSheet mercuryFromDb = session.get( PlanetCheatSheet.class, Planet.MERCURY );
|
||||
assertNull( mercuryFromDb );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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.annotations.id.sequences;
|
||||
|
||||
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
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.orm.test.annotations.id.sequences.entities.HibernateSequenceEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-6068")
|
||||
@RequiresDialect(value = H2Dialect.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = HibernateSequenceEntity.class,
|
||||
xmlMappings = "org/hibernate/orm/test/annotations/id/sequences/orm.xml"
|
||||
)
|
||||
@SessionFactory(createSecondarySchemas = true)
|
||||
public class HibernateSequenceTest {
|
||||
private static final String SCHEMA_NAME = "OTHER_SCHEMA";
|
||||
|
||||
@Test
|
||||
public void testHibernateSequenceSchema(SessionFactoryScope scope) {
|
||||
EntityPersister persister = scope.getSessionFactory()
|
||||
.getEntityPersister( HibernateSequenceEntity.class.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
assertEquals(
|
||||
Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ),
|
||||
seqGenerator.getDatabaseStructure().getName()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHibernateSequenceNextVal(SessionFactoryScope scope) {
|
||||
HibernateSequenceEntity entity = new HibernateSequenceEntity();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
entity.setText( "sample text" );
|
||||
session.save( entity );
|
||||
}
|
||||
);
|
||||
|
||||
assertNotNull( entity.getId() );
|
||||
}
|
||||
}
|
|
@ -4,13 +4,13 @@
|
|||
* 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.test.annotations.id.sequences;
|
||||
package org.hibernate.orm.test.annotations.id.sequences;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Location;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Tower;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Location;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Tower;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -0,0 +1,344 @@
|
|||
/*
|
||||
* 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.annotations.id.sequences;
|
||||
|
||||
import org.hibernate.mapping.Column;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.orm.test.annotations.id.generationmappings.DedicatedSequenceEntity1;
|
||||
import org.hibernate.orm.test.annotations.id.generationmappings.DedicatedSequenceEntity2;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Ball;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.BreakDance;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Computer;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Department;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Dog;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.FirTree;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Footballer;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.FootballerPk;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Furniture;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.GoalKeeper;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Home;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Monkey;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Phone;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Shoe;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.SoundSystem;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Store;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Tree;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Ball.class, Shoe.class, Store.class,
|
||||
Department.class, Dog.class, Computer.class, Home.class,
|
||||
Phone.class, Tree.class, FirTree.class, Footballer.class,
|
||||
SoundSystem.class, Furniture.class, GoalKeeper.class,
|
||||
BreakDance.class, Monkey.class, DedicatedSequenceEntity1.class,
|
||||
DedicatedSequenceEntity2.class
|
||||
},
|
||||
annotatedPackageNames = {
|
||||
"org.hibernate.orm.test.annotations",
|
||||
"org.hibernate.orm.test.annotations.id",
|
||||
"org.hibernate.orm.test.annotations.id.generationmappings"
|
||||
},
|
||||
xmlMappings = "org/hibernate/test/annotations/orm.xml"
|
||||
|
||||
)
|
||||
@SessionFactory
|
||||
public class IdTest {
|
||||
|
||||
@Test
|
||||
public void testGenericGenerator(SessionFactoryScope scope) {
|
||||
SoundSystem system = new SoundSystem();
|
||||
Furniture fur = new Furniture();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
system.setBrand( "Genelec" );
|
||||
system.setModel( "T234" );
|
||||
session.persist( system );
|
||||
session.persist( fur );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
SoundSystem systemfromDb = session.get( SoundSystem.class, system.getId() );
|
||||
Furniture furFromDb = session.get( Furniture.class, fur.getId() );
|
||||
assertNotNull( systemfromDb );
|
||||
assertNotNull( furFromDb );
|
||||
session.delete( systemfromDb );
|
||||
session.delete( furFromDb );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericGenerators(SessionFactoryScope scope) {
|
||||
// Ensures that GenericGenerator annotations wrapped inside a GenericGenerators holder are bound correctly
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Monkey monkey = new Monkey();
|
||||
session.persist( monkey );
|
||||
session.flush();
|
||||
assertNotNull( monkey.getId() );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from Monkey" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableGenerator(SessionFactoryScope scope) {
|
||||
Ball b = new Ball();
|
||||
Dog d = new Dog();
|
||||
Computer c = new Computer();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( b );
|
||||
session.persist( d );
|
||||
session.persist( c );
|
||||
}
|
||||
);
|
||||
|
||||
assertEquals( new Integer( 1 ), b.getId(), "table id not generated" );
|
||||
assertEquals( new Integer( 1 ), d.getId(), "generator should not be shared" );
|
||||
assertEquals( new Long( 1 ), c.getId(), "default value should work" );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.delete( session.get( Ball.class, 1 ) );
|
||||
session.delete( session.get( Dog.class, 1 ) );
|
||||
session.delete( session.get( Computer.class, 1L ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceGenerator(SessionFactoryScope scope) {
|
||||
Shoe b = new Shoe();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( b )
|
||||
);
|
||||
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( session.get( Shoe.class, b.getId() ) )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassLevelGenerator(SessionFactoryScope scope) {
|
||||
Store b = new Store();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( b )
|
||||
);
|
||||
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( session.get( Store.class, b.getId() ) )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodLevelGenerator(SessionFactoryScope scope) {
|
||||
Department b = new Department();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( b )
|
||||
);
|
||||
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( session.get( Department.class, b.getId() ) )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSequence(SessionFactoryScope scope) {
|
||||
Home h = new Home();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( h )
|
||||
);
|
||||
|
||||
assertNotNull( h.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Home reloadedHome = session.get( Home.class, h.getId() );
|
||||
assertEquals( h.getId(), reloadedHome.getId() );
|
||||
session.delete( reloadedHome );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizedAuto(SessionFactoryScope scope) {
|
||||
Home h = new Home();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( h )
|
||||
);
|
||||
|
||||
assertNotNull( h.getId() );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Home reloadedHome = session.get( Home.class, h.getId() );
|
||||
assertEquals( h.getId(), reloadedHome.getId() );
|
||||
session.delete( reloadedHome );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdInEmbeddableSuperclass(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
FirTree christmasTree = new FirTree();
|
||||
session.persist( christmasTree );
|
||||
session.getTransaction().commit();
|
||||
session.clear();
|
||||
|
||||
session.beginTransaction();
|
||||
|
||||
christmasTree = session.get( FirTree.class, christmasTree.getId() );
|
||||
assertNotNull( christmasTree );
|
||||
session.delete( christmasTree );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Footballer fb = new Footballer( "David", "Beckam", "Arsenal" );
|
||||
GoalKeeper keeper = new GoalKeeper( "Fabien", "Bartez", "OM" );
|
||||
session.persist( fb );
|
||||
session.persist( keeper );
|
||||
session.getTransaction().commit();
|
||||
session.clear();
|
||||
|
||||
// lookup by id
|
||||
session.beginTransaction();
|
||||
FootballerPk fpk = new FootballerPk( "David", "Beckam" );
|
||||
fb = session.get( Footballer.class, fpk );
|
||||
FootballerPk fpk2 = new FootballerPk( "Fabien", "Bartez" );
|
||||
keeper = session.get( GoalKeeper.class, fpk2 );
|
||||
assertNotNull( fb );
|
||||
assertNotNull( keeper );
|
||||
assertEquals( "Beckam", fb.getLastname() );
|
||||
assertEquals( "Arsenal", fb.getClub() );
|
||||
assertEquals(
|
||||
1,
|
||||
session.createQuery( "from Footballer f where f.firstname = 'David'" )
|
||||
.list().size()
|
||||
);
|
||||
session.getTransaction().commit();
|
||||
|
||||
// reattach by merge
|
||||
session.beginTransaction();
|
||||
fb.setClub( "Bimbo FC" );
|
||||
session.merge( fb );
|
||||
session.getTransaction().commit();
|
||||
|
||||
// reattach by saveOrUpdate
|
||||
session.beginTransaction();
|
||||
fb.setClub( "Bimbo FC SA" );
|
||||
session.saveOrUpdate( fb );
|
||||
session.getTransaction().commit();
|
||||
|
||||
// clean up
|
||||
session.clear();
|
||||
session.beginTransaction();
|
||||
fpk = new FootballerPk( "David", "Beckam" );
|
||||
fb = session.get( Footballer.class, fpk );
|
||||
assertEquals( "Bimbo FC SA", fb.getClub() );
|
||||
session.delete( fb );
|
||||
session.delete( keeper );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-6790")
|
||||
public void testSequencePerEntity(SessionFactoryScope scope) {
|
||||
DedicatedSequenceEntity1 entity1 = new DedicatedSequenceEntity1();
|
||||
DedicatedSequenceEntity2 entity2 = new DedicatedSequenceEntity2();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( entity1 );
|
||||
session.persist( entity2 );
|
||||
}
|
||||
);
|
||||
|
||||
assertEquals( 1, entity1.getId().intValue() );
|
||||
assertEquals( 1, entity2.getId().intValue() );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from DedicatedSequenceEntity1" ).executeUpdate();
|
||||
session.createQuery( "delete from " + DedicatedSequenceEntity2.ENTITY_NAME ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnDefinition(SessionFactoryScope scope) {
|
||||
Column idCol = (Column) scope.getMetadataImplementor().getEntityBinding( Ball.class.getName() )
|
||||
.getIdentifierProperty().getValue().getColumnIterator().next();
|
||||
assertEquals( "ball_id", idCol.getName() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowAllocationSize(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
int size = 4;
|
||||
BreakDance[] bds = new BreakDance[size];
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
bds[i] = new BreakDance();
|
||||
session.persist( bds[i] );
|
||||
}
|
||||
session.flush();
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
assertEquals( i + 1, bds[i].id.intValue() );
|
||||
}
|
||||
}
|
||||
);
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from BreakDance" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.id.sequences;
|
||||
package org.hibernate.orm.test.annotations.id.sequences;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -18,23 +18,21 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Bunny;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.PointyTooth;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.TwinkleToes;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.junit5.BaseUnitTest;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.Bunny;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.PointyTooth;
|
||||
import org.hibernate.orm.test.annotations.id.sequences.entities.TwinkleToes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for JIRA issue ANN-748.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class JoinColumnOverrideTest extends BaseUnitTestCase {
|
||||
public class JoinColumnOverrideTest extends BaseUnitTest {
|
||||
|
||||
private static final String expectedSqlPointyTooth = "create table PointyTooth (id numeric(128,0) not null, " +
|
||||
"bunny_id numeric(128,0), primary key (id))";
|
||||
|
@ -42,8 +40,8 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase {
|
|||
"bunny_id numeric(128,0), primary key (id))";
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "ANN-748" )
|
||||
public void testBlownPrecision() throws Exception {
|
||||
@TestForIssue(jiraKey = "ANN-748")
|
||||
public void testBlownPrecision() {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, "SQLServer" )
|
||||
.build();
|
||||
|
@ -59,7 +57,6 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase {
|
|||
|
||||
List<String> commands = new SchemaCreatorImpl( ssr ).generateCreationCommands( metadata, false );
|
||||
for ( String command : commands ) {
|
||||
log.debug( command );
|
||||
|
||||
if ( expectedSqlPointyTooth.equals( command ) ) {
|
||||
foundPointyToothCreate = true;
|
||||
|
@ -69,8 +66,8 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
assertTrue( "Expected create table command for PointyTooth entity not found", foundPointyToothCreate );
|
||||
assertTrue( "Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate );
|
||||
assertTrue( foundPointyToothCreate, "Expected create table command for PointyTooth entity not found" );
|
||||
assertTrue( foundTwinkleToesCreate, "Expected create table command for TwinkleToes entity not found" );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
|
@ -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.test.annotations.id.sequences;
|
||||
package org.hibernate.orm.test.annotations.id.sequences;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.UUID;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Ball.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: BreakDance.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Bunny.java 14761 2008-06-11 13:51:06Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Set;
|
||||
|
@ -31,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator;
|
|||
public class Bunny implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator")
|
||||
@Column(name = "id", precision = 128, scale = 0)
|
||||
private BigDecimal id;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Computer.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Department.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Dog.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: FirTree.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Footballer.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: FootballerPk.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Furniture.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: GoalKeeper.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -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.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Home.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Location.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: MilitaryBuilding.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.MappedSuperclass;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Phone.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
// $Id: Planet.java 14785 2008-06-19 10:44:33Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
|
||||
|
||||
public enum Planet {
|
|
@ -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.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: PointyTooth.java 14761 2008-06-11 13:51:06Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import javax.persistence.Column;
|
||||
|
@ -31,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator;
|
|||
public class PointyTooth implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator")
|
||||
@Column(name = "id", precision = 128, scale = 0)
|
||||
private BigDecimal id;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Shoe.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: SoundSystem.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Store.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Tower.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Tree.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: TwinkleToes.java 14761 2008-06-11 13:51:06Z hardy.ferentschik $
|
||||
package org.hibernate.test.annotations.id.sequences.entities;
|
||||
package org.hibernate.orm.test.annotations.id.sequences.entities;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import javax.persistence.Column;
|
||||
|
@ -31,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator;
|
|||
public class TwinkleToes implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator")
|
||||
@GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator")
|
||||
@Column(name = "id", precision = 128, scale = 0)
|
||||
private BigDecimal id;
|
||||
|
|
@ -14,6 +14,6 @@
|
|||
@org.hibernate.annotations.GenericGenerators(
|
||||
@org.hibernate.annotations.GenericGenerator(name = "system-uuid-2", strategy = "uuid")
|
||||
)
|
||||
package org.hibernate.test.annotations.id.sequences;
|
||||
package org.hibernate.orm.test.annotations.id.sequences;
|
||||
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// $Id$
|
||||
|
||||
package org.hibernate.test.annotations.idclass;
|
||||
package org.hibernate.orm.test.annotations.idclass;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
@ -27,7 +27,7 @@ import javax.persistence.Table;
|
|||
@IdClass(DomainAdminId.class)
|
||||
@NamedNativeQuery(name = "DomainAdmin.testQuery",
|
||||
query = "select * from domainadmin da where da.domain_name = 'org'",
|
||||
resultClass = org.hibernate.test.annotations.idclass.DomainAdmin.class)
|
||||
resultClass = org.hibernate.orm.test.annotations.idclass.DomainAdmin.class)
|
||||
public class DomainAdmin implements Serializable {
|
||||
|
||||
@Id
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// $Id$
|
||||
|
||||
package org.hibernate.test.annotations.idclass;
|
||||
package org.hibernate.orm.test.annotations.idclass;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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.annotations.idclass;
|
||||
|
||||
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:stale.pedersen@jboss.org">Stale W. Pedersen</a>
|
||||
*/
|
||||
@DomainModel(annotatedClasses = DomainAdmin.class)
|
||||
@SessionFactory
|
||||
public class IdClassCompositePKTest {
|
||||
|
||||
@Test
|
||||
public void testEntityMappningPropertiesAreNotIgnored(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
DomainAdmin da = new DomainAdmin();
|
||||
da.setAdminUser( "admin" );
|
||||
da.setDomainName( "org" );
|
||||
|
||||
session.persist( da );
|
||||
Query q = session.getNamedQuery( "DomainAdmin.testQuery" );
|
||||
assertEquals( 1, q.list().size() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,67 +4,58 @@
|
|||
* 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.test.annotations.idclass;
|
||||
package org.hibernate.orm.test.annotations.idclass;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-9114")
|
||||
public class IdClassMappedSuperclassTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { Simple.class };
|
||||
}
|
||||
@DomainModel(annotatedClasses = IdClassMappedSuperclassTest.Simple.class)
|
||||
@SessionFactory
|
||||
public class IdClassMappedSuperclassTest {
|
||||
|
||||
@Test
|
||||
public void testIdClassWithMappedSuperclassAndId() throws Exception {
|
||||
Session session = openSession();
|
||||
try {
|
||||
// Persist the entity
|
||||
Simple simple = new Simple();
|
||||
simple.setSimpleId( "1" );
|
||||
simple.setCategoryId( "2" );
|
||||
session.getTransaction().begin();
|
||||
session.save( simple );
|
||||
session.getTransaction().commit();
|
||||
session.clear();
|
||||
public void testIdClassWithMappedSuperclassAndId(SessionFactoryScope scope) {
|
||||
Simple sim = scope.fromTransaction(
|
||||
session -> {
|
||||
// Persist the entity
|
||||
Simple simple = new Simple();
|
||||
simple.setSimpleId( "1" );
|
||||
simple.setCategoryId( "2" );
|
||||
session.save( simple );
|
||||
|
||||
// Query the entity.
|
||||
session.getTransaction().begin();
|
||||
simple = session.createQuery( "FROM Simple", Simple.class ).getSingleResult();
|
||||
session.getTransaction().commit();
|
||||
session.getTransaction().commit();
|
||||
|
||||
// tests.
|
||||
assertNotNull( simple );
|
||||
assertEquals( "1", simple.getSimpleId() );
|
||||
assertEquals( "2", simple.getCategoryId() );
|
||||
session.clear();
|
||||
|
||||
session.getTransaction().begin();
|
||||
|
||||
// Query the entity.
|
||||
simple = session.createQuery( "FROM Simple", Simple.class ).getSingleResult();
|
||||
return simple;
|
||||
}
|
||||
);
|
||||
|
||||
assertNotNull( sim );
|
||||
assertEquals( "1", sim.getSimpleId() );
|
||||
assertEquals( "2", sim.getCategoryId() );
|
||||
|
||||
}
|
||||
catch ( Throwable t ) {
|
||||
if ( session.getTransaction().isActive() ) {
|
||||
session.getTransaction().rollback();
|
||||
}
|
||||
throw t;
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
@MappedSuperclass
|
||||
|
@ -136,10 +127,14 @@ public class IdClassMappedSuperclassTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
SimpleId simpleId1 = (SimpleId) o;
|
||||
|
||||
if ( getSimpleId() != null ? !getSimpleId().equals( simpleId1.getSimpleId() ) : simpleId1.getSimpleId() != null ) {
|
||||
if ( getSimpleId() != null ?
|
||||
!getSimpleId().equals( simpleId1.getSimpleId() ) :
|
||||
simpleId1.getSimpleId() != null ) {
|
||||
return false;
|
||||
}
|
||||
return getCategoryId() != null ? getCategoryId().equals( simpleId1.getCategoryId() ) : simpleId1.getCategoryId() == null;
|
||||
return getCategoryId() != null ?
|
||||
getCategoryId().equals( simpleId1.getCategoryId() ) :
|
||||
simpleId1.getCategoryId() == null;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// $Id: $
|
||||
|
||||
package org.hibernate.test.annotations.idclass.xml;
|
||||
package org.hibernate.orm.test.annotations.idclass.xml;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.orm.test.annotations.idclass.xml;
|
||||
|
||||
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* A test for HHH-4282
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@FailureExpected( jiraKey = "HHH-4282" )
|
||||
@DomainModel(
|
||||
annotatedClasses = HabitatSpeciesLink.class,
|
||||
xmlMappings = "org/hibernate/orm/test/annotations/idclass/xml/HabitatSpeciesLink.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class IdClassXmlTest {
|
||||
@Test
|
||||
public void testEntityMappingPropertiesAreNotIgnored(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
HabitatSpeciesLink link = new HabitatSpeciesLink();
|
||||
link.setHabitatId( 1l );
|
||||
link.setSpeciesId( 1l );
|
||||
session.persist( link );
|
||||
|
||||
Query q = session.getNamedQuery( "testQuery" );
|
||||
assertEquals( 1, q.list().size() );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,66 +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.test.annotations.id;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.test.annotations.id.entities.Planet;
|
||||
import org.hibernate.test.annotations.id.entities.PlanetCheatSheet;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Tests for enum type as id.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@TestForIssue( jiraKey = "ANN-744" )
|
||||
public class EnumIdTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Test
|
||||
public void testEnumAsId() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
PlanetCheatSheet mercury = new PlanetCheatSheet();
|
||||
mercury.setPlanet(Planet.MERCURY);
|
||||
mercury.setMass(3.303e+23);
|
||||
mercury.setRadius(2.4397e6);
|
||||
mercury.setNumberOfInhabitants(0);
|
||||
s.persist(mercury);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
PlanetCheatSheet mercuryFromDb = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, mercury.getPlanet());
|
||||
assertNotNull(mercuryFromDb);
|
||||
log.debug(mercuryFromDb.toString());
|
||||
s.delete(mercuryFromDb);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
mercury = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, Planet.MERCURY);
|
||||
assertNull(mercury);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] { PlanetCheatSheet.class };
|
||||
}
|
||||
}
|
|
@ -1,48 +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.test.annotations.id;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.test.annotations.id.entities.Location;
|
||||
import org.hibernate.test.annotations.id.entities.Tower;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class IdClassTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testIdClassInSuperclass() throws Exception {
|
||||
Tower tower = new Tower();
|
||||
tower.latitude = 10.3;
|
||||
tower.longitude = 45.4;
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
s.persist( tower );
|
||||
s.flush();
|
||||
s.clear();
|
||||
Location loc = new Location();
|
||||
loc.latitude = tower.latitude;
|
||||
loc.longitude = tower.longitude;
|
||||
assertNotNull( s.get( Tower.class, loc ) );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Tower.class
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,360 +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.test.annotations.id;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.mapping.Column;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.annotations.id.entities.Ball;
|
||||
import org.hibernate.test.annotations.id.entities.BreakDance;
|
||||
import org.hibernate.test.annotations.id.entities.Computer;
|
||||
import org.hibernate.test.annotations.id.entities.Department;
|
||||
import org.hibernate.test.annotations.id.entities.Dog;
|
||||
import org.hibernate.test.annotations.id.entities.FirTree;
|
||||
import org.hibernate.test.annotations.id.entities.Footballer;
|
||||
import org.hibernate.test.annotations.id.entities.FootballerPk;
|
||||
import org.hibernate.test.annotations.id.entities.Furniture;
|
||||
import org.hibernate.test.annotations.id.entities.GoalKeeper;
|
||||
import org.hibernate.test.annotations.id.entities.Home;
|
||||
import org.hibernate.test.annotations.id.entities.Hotel;
|
||||
import org.hibernate.test.annotations.id.entities.Monkey;
|
||||
import org.hibernate.test.annotations.id.entities.Phone;
|
||||
import org.hibernate.test.annotations.id.entities.Shoe;
|
||||
import org.hibernate.test.annotations.id.entities.SoundSystem;
|
||||
import org.hibernate.test.annotations.id.entities.Store;
|
||||
import org.hibernate.test.annotations.id.entities.Tree;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class IdTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Test
|
||||
public void testNoGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Hotel hotel = new Hotel();
|
||||
hotel.setId( 12l );
|
||||
hotel.setName("California");
|
||||
s.saveOrUpdate(hotel);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
hotel = (Hotel) s.get(Hotel.class, 12l);
|
||||
assertNotNull(hotel);
|
||||
assertEquals("California", hotel.getName());
|
||||
assertNull(s.get(Hotel.class, 13l));
|
||||
tx.commit();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
//hotel is now detached
|
||||
hotel.setName("Hotel du nord");
|
||||
s.saveOrUpdate(hotel);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
hotel = (Hotel) s.get(Hotel.class, 12l);
|
||||
assertNotNull(hotel);
|
||||
assertEquals("Hotel du nord", hotel.getName());
|
||||
s.delete(hotel);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
SoundSystem system = new SoundSystem();
|
||||
system.setBrand("Genelec");
|
||||
system.setModel("T234");
|
||||
Furniture fur = new Furniture();
|
||||
s.persist(system);
|
||||
s.persist(fur);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
system = (SoundSystem) s.get(SoundSystem.class, system.getId());
|
||||
fur = (Furniture) s.get(Furniture.class, fur.getId());
|
||||
assertNotNull(system);
|
||||
assertNotNull(fur);
|
||||
s.delete(system);
|
||||
s.delete(fur);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensures that GenericGenerator annotations wrapped inside a
|
||||
* GenericGenerators holder are bound correctly
|
||||
*/
|
||||
@Test
|
||||
public void testGenericGenerators() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Monkey monkey = new Monkey();
|
||||
s.persist(monkey);
|
||||
s.flush();
|
||||
assertNotNull(monkey.getId());
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Ball b = new Ball();
|
||||
Dog d = new Dog();
|
||||
Computer c = new Computer();
|
||||
s.persist( b );
|
||||
s.persist( d );
|
||||
s.persist(c);
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertEquals("table id not generated", new Integer(1), b.getId());
|
||||
assertEquals("generator should not be shared", new Integer(1), d
|
||||
.getId());
|
||||
assertEquals("default value should work", new Long(1), c.getId());
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.delete(s.get(Ball.class, new Integer(1)));
|
||||
s.delete(s.get(Dog.class, new Integer(1)));
|
||||
s.delete(s.get(Computer.class, new Long(1)));
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Shoe b = new Shoe();
|
||||
s.persist(b);
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull(b.getId());
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.delete(s.get(Shoe.class, b.getId()));
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassLevelGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Store b = new Store();
|
||||
s.persist(b);
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull(b.getId());
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.delete(s.get(Store.class, b.getId()));
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodLevelGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Department b = new Department();
|
||||
s.persist(b);
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.delete(s.get(Department.class, b.getId()));
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSequence() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Home h = new Home();
|
||||
s.persist(h);
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull(h.getId());
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Home reloadedHome = (Home) s.get(Home.class, h.getId());
|
||||
assertEquals(h.getId(), reloadedHome.getId());
|
||||
s.delete(reloadedHome);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizedAuto() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Home h = new Home();
|
||||
s.persist(h);
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull(h.getId());
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Home reloadedHome = (Home) s.get(Home.class, h.getId());
|
||||
assertEquals( h.getId(), reloadedHome.getId() );
|
||||
s.delete(reloadedHome);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdInEmbeddableSuperclass() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
FirTree chrismasTree = new FirTree();
|
||||
s.persist(chrismasTree);
|
||||
tx.commit();
|
||||
s.clear();
|
||||
tx = s.beginTransaction();
|
||||
chrismasTree = (FirTree) s.get(FirTree.class, chrismasTree.getId());
|
||||
assertNotNull(chrismasTree);
|
||||
s.delete(chrismasTree);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdClass() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Footballer fb = new Footballer("David", "Beckam", "Arsenal");
|
||||
GoalKeeper keeper = new GoalKeeper("Fabien", "Bartez", "OM");
|
||||
s.persist(fb);
|
||||
s.persist(keeper);
|
||||
tx.commit();
|
||||
s.clear();
|
||||
|
||||
// lookup by id
|
||||
tx = s.beginTransaction();
|
||||
FootballerPk fpk = new FootballerPk("David", "Beckam");
|
||||
fb = (Footballer) s.get(Footballer.class, fpk);
|
||||
FootballerPk fpk2 = new FootballerPk("Fabien", "Bartez");
|
||||
keeper = (GoalKeeper) s.get(GoalKeeper.class, fpk2);
|
||||
assertNotNull(fb);
|
||||
assertNotNull(keeper);
|
||||
assertEquals("Beckam", fb.getLastname());
|
||||
assertEquals("Arsenal", fb.getClub());
|
||||
assertEquals(1, s.createQuery(
|
||||
"from Footballer f where f.firstname = 'David'").list().size());
|
||||
tx.commit();
|
||||
|
||||
// reattach by merge
|
||||
tx = s.beginTransaction();
|
||||
fb.setClub("Bimbo FC");
|
||||
s.merge(fb);
|
||||
tx.commit();
|
||||
|
||||
// reattach by saveOrUpdate
|
||||
tx = s.beginTransaction();
|
||||
fb.setClub("Bimbo FC SA");
|
||||
s.saveOrUpdate(fb);
|
||||
tx.commit();
|
||||
|
||||
// clean up
|
||||
s.clear();
|
||||
tx = s.beginTransaction();
|
||||
fpk = new FootballerPk("David", "Beckam");
|
||||
fb = (Footballer) s.get(Footballer.class, fpk);
|
||||
assertEquals("Bimbo FC SA", fb.getClub());
|
||||
s.delete(fb);
|
||||
s.delete(keeper);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnDefinition() {
|
||||
Column idCol = (Column) metadata().getEntityBinding( Ball.class.getName() )
|
||||
.getIdentifierProperty()
|
||||
.getValue()
|
||||
.getColumnIterator()
|
||||
.next();
|
||||
assertEquals( "ball_id", idCol.getName() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowAllocationSize() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
int size = 4;
|
||||
BreakDance[] bds = new BreakDance[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
bds[i] = new BreakDance();
|
||||
s.persist(bds[i]);
|
||||
}
|
||||
s.flush();
|
||||
for (int i = 0; i < size; i++) {
|
||||
assertEquals(i + 1, bds[i].id.intValue());
|
||||
}
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] { Ball.class, Shoe.class, Store.class,
|
||||
Department.class, Dog.class, Computer.class, Home.class,
|
||||
Phone.class, Tree.class, FirTree.class, Footballer.class,
|
||||
SoundSystem.class, Furniture.class, GoalKeeper.class,
|
||||
BreakDance.class, Monkey.class, Hotel.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getAnnotatedPackages() {
|
||||
return new String[] { "org.hibernate.test.annotations",
|
||||
"org.hibernate.test.annotations.id" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getXmlFiles() {
|
||||
return new String[] { "org/hibernate/test/annotations/orm.xml" };
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.annotations.id.sequences;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Planet;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.PlanetCheatSheet;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Tests for enum type as id.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@TestForIssue( jiraKey = "ANN-744" )
|
||||
public class EnumIdTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Test
|
||||
public void testEnumAsId() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
PlanetCheatSheet mercury = new PlanetCheatSheet();
|
||||
mercury.setPlanet(Planet.MERCURY);
|
||||
mercury.setMass(3.303e+23);
|
||||
mercury.setRadius(2.4397e6);
|
||||
mercury.setNumberOfInhabitants(0);
|
||||
s.persist(mercury);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
PlanetCheatSheet mercuryFromDb = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, mercury.getPlanet());
|
||||
assertNotNull(mercuryFromDb);
|
||||
log.debug(mercuryFromDb.toString());
|
||||
s.delete(mercuryFromDb);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
mercury = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, Planet.MERCURY);
|
||||
assertNull(mercury);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] { PlanetCheatSheet.class };
|
||||
}
|
||||
}
|
|
@ -1,75 +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.test.annotations.id.sequences;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.HibernateSequenceEntity;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-6068")
|
||||
@RequiresDialect( value = H2Dialect.class)
|
||||
public class HibernateSequenceTest extends BaseCoreFunctionalTestCase {
|
||||
private static final String SCHEMA_NAME = "OTHER_SCHEMA";
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
HibernateSequenceEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.addResource( "org/hibernate/test/annotations/id/sequences/orm.xml" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createSecondSchema() {
|
||||
return SCHEMA_NAME;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHibernateSequenceSchema() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( HibernateSequenceEntity.class.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
Assert.assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
Assert.assertEquals(
|
||||
Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ),
|
||||
seqGenerator.getDatabaseStructure().getName()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHibernateSequenceNextVal() {
|
||||
Session session = openSession();
|
||||
Transaction txn = session.beginTransaction();
|
||||
HibernateSequenceEntity entity = new HibernateSequenceEntity();
|
||||
entity.setText( "sample text" );
|
||||
session.save( entity );
|
||||
txn.commit();
|
||||
session.close();
|
||||
Assert.assertNotNull( entity.getId() );
|
||||
}
|
||||
}
|
|
@ -1,350 +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.test.annotations.id.sequences;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.mapping.Column;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.annotations.id.generationmappings.DedicatedSequenceEntity1;
|
||||
import org.hibernate.test.annotations.id.generationmappings.DedicatedSequenceEntity2;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Ball;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.BreakDance;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Computer;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Department;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Dog;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.FirTree;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Footballer;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.FootballerPk;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Furniture;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.GoalKeeper;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Home;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Monkey;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Phone;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Shoe;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.SoundSystem;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Store;
|
||||
import org.hibernate.test.annotations.id.sequences.entities.Tree;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
|
||||
public class IdTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testGenericGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
SoundSystem system = new SoundSystem();
|
||||
system.setBrand( "Genelec" );
|
||||
system.setModel( "T234" );
|
||||
Furniture fur = new Furniture();
|
||||
s.persist( system );
|
||||
s.persist( fur );
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
system = ( SoundSystem ) s.get( SoundSystem.class, system.getId() );
|
||||
fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
|
||||
assertNotNull( system );
|
||||
assertNotNull( fur );
|
||||
s.delete( system );
|
||||
s.delete( fur );
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericGenerators() throws Exception {
|
||||
// Ensures that GenericGenerator annotations wrapped inside a GenericGenerators holder are bound correctly
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Monkey monkey = new Monkey();
|
||||
s.persist( monkey );
|
||||
s.flush();
|
||||
assertNotNull( monkey.getId() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Ball b = new Ball();
|
||||
Dog d = new Dog();
|
||||
Computer c = new Computer();
|
||||
s.persist( b );
|
||||
s.persist( d );
|
||||
s.persist( c );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertEquals( "table id not generated", new Integer( 1 ), b.getId() );
|
||||
assertEquals(
|
||||
"generator should not be shared", new Integer( 1 ), d
|
||||
.getId()
|
||||
);
|
||||
assertEquals( "default value should work", new Long( 1 ), c.getId() );
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.delete( s.get( Ball.class, new Integer( 1 ) ) );
|
||||
s.delete( s.get( Dog.class, new Integer( 1 ) ) );
|
||||
s.delete( s.get( Computer.class, new Long( 1 ) ) );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Shoe b = new Shoe();
|
||||
s.persist( b );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.delete( s.get( Shoe.class, b.getId() ) );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassLevelGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Store b = new Store();
|
||||
s.persist( b );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.delete( s.get( Store.class, b.getId() ) );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodLevelGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Department b = new Department();
|
||||
s.persist( b );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull( b.getId() );
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.delete( s.get( Department.class, b.getId() ) );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSequence() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Home h = new Home();
|
||||
s.persist( h );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull( h.getId() );
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Home reloadedHome = ( Home ) s.get( Home.class, h.getId() );
|
||||
assertEquals( h.getId(), reloadedHome.getId() );
|
||||
s.delete( reloadedHome );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizedAuto() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Home h = new Home();
|
||||
s.persist( h );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertNotNull( h.getId() );
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Home reloadedHome = ( Home ) s.get( Home.class, h.getId() );
|
||||
assertEquals( h.getId(), reloadedHome.getId() );
|
||||
s.delete( reloadedHome );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdInEmbeddableSuperclass() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
FirTree chrismasTree = new FirTree();
|
||||
s.persist( chrismasTree );
|
||||
tx.commit();
|
||||
s.clear();
|
||||
tx = s.beginTransaction();
|
||||
chrismasTree = ( FirTree ) s.get( FirTree.class, chrismasTree.getId() );
|
||||
assertNotNull( chrismasTree );
|
||||
s.delete( chrismasTree );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdClass() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Footballer fb = new Footballer( "David", "Beckam", "Arsenal" );
|
||||
GoalKeeper keeper = new GoalKeeper( "Fabien", "Bartez", "OM" );
|
||||
s.persist( fb );
|
||||
s.persist( keeper );
|
||||
tx.commit();
|
||||
s.clear();
|
||||
|
||||
// lookup by id
|
||||
tx = s.beginTransaction();
|
||||
FootballerPk fpk = new FootballerPk( "David", "Beckam" );
|
||||
fb = ( Footballer ) s.get( Footballer.class, fpk );
|
||||
FootballerPk fpk2 = new FootballerPk( "Fabien", "Bartez" );
|
||||
keeper = ( GoalKeeper ) s.get( GoalKeeper.class, fpk2 );
|
||||
assertNotNull( fb );
|
||||
assertNotNull( keeper );
|
||||
assertEquals( "Beckam", fb.getLastname() );
|
||||
assertEquals( "Arsenal", fb.getClub() );
|
||||
assertEquals(
|
||||
1, s.createQuery(
|
||||
"from Footballer f where f.firstname = 'David'"
|
||||
).list().size()
|
||||
);
|
||||
tx.commit();
|
||||
|
||||
// reattach by merge
|
||||
tx = s.beginTransaction();
|
||||
fb.setClub( "Bimbo FC" );
|
||||
s.merge( fb );
|
||||
tx.commit();
|
||||
|
||||
// reattach by saveOrUpdate
|
||||
tx = s.beginTransaction();
|
||||
fb.setClub( "Bimbo FC SA" );
|
||||
s.saveOrUpdate( fb );
|
||||
tx.commit();
|
||||
|
||||
// clean up
|
||||
s.clear();
|
||||
tx = s.beginTransaction();
|
||||
fpk = new FootballerPk( "David", "Beckam" );
|
||||
fb = ( Footballer ) s.get( Footballer.class, fpk );
|
||||
assertEquals( "Bimbo FC SA", fb.getClub() );
|
||||
s.delete( fb );
|
||||
s.delete( keeper );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-6790")
|
||||
public void testSequencePerEntity() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
DedicatedSequenceEntity1 entity1 = new DedicatedSequenceEntity1();
|
||||
DedicatedSequenceEntity2 entity2 = new DedicatedSequenceEntity2();
|
||||
session.persist( entity1 );
|
||||
session.persist( entity2 );
|
||||
session.getTransaction().commit();
|
||||
|
||||
assertEquals( 1, entity1.getId().intValue() );
|
||||
assertEquals( 1, entity2.getId().intValue() );
|
||||
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnDefinition() {
|
||||
Column idCol = ( Column ) metadata().getEntityBinding( Ball.class.getName() )
|
||||
.getIdentifierProperty().getValue().getColumnIterator().next();
|
||||
assertEquals( "ball_id", idCol.getName() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowAllocationSize() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
int size = 4;
|
||||
BreakDance[] bds = new BreakDance[size];
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
bds[i] = new BreakDance();
|
||||
s.persist( bds[i] );
|
||||
}
|
||||
s.flush();
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
assertEquals( i + 1, bds[i].id.intValue() );
|
||||
}
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Ball.class, Shoe.class, Store.class,
|
||||
Department.class, Dog.class, Computer.class, Home.class,
|
||||
Phone.class, Tree.class, FirTree.class, Footballer.class,
|
||||
SoundSystem.class, Furniture.class, GoalKeeper.class,
|
||||
BreakDance.class, Monkey.class, DedicatedSequenceEntity1.class,
|
||||
DedicatedSequenceEntity2.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getAnnotatedPackages() {
|
||||
return new String[] {
|
||||
"org.hibernate.test.annotations",
|
||||
"org.hibernate.test.annotations.id",
|
||||
"org.hibernate.test.annotations.id.generationmappings"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getXmlFiles() {
|
||||
return new String[] { "org/hibernate/test/annotations/orm.xml" };
|
||||
}
|
||||
}
|
|
@ -1,45 +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.test.annotations.idclass;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:stale.pedersen@jboss.org">Stale W. Pedersen</a>
|
||||
*/
|
||||
public class IdClassCompositePKTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testEntityMappningPropertiesAreNotIgnored() {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
DomainAdmin da = new DomainAdmin();
|
||||
da.setAdminUser( "admin" );
|
||||
da.setDomainName( "org" );
|
||||
|
||||
s.persist( da );
|
||||
Query q = s.getNamedQuery( "DomainAdmin.testQuery" );
|
||||
assertEquals( 1, q.list().size() );
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] { DomainAdmin.class };
|
||||
}
|
||||
}
|
|
@ -1,52 +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.test.annotations.idclass.xml;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* A test for HHH-4282
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@FailureExpected( jiraKey = "HHH-4282" )
|
||||
public class IdClassXmlTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testEntityMappingPropertiesAreNotIgnored() {
|
||||
throw new RuntimeException();
|
||||
// Session s = openSession();
|
||||
// Transaction tx = s.beginTransaction();
|
||||
//
|
||||
// HabitatSpeciesLink link = new HabitatSpeciesLink();
|
||||
// link.setHabitatId( 1l );
|
||||
// link.setSpeciesId( 1l );
|
||||
// s.persist( link );
|
||||
//
|
||||
// Query q = s.getNamedQuery( "testQuery" );
|
||||
// assertEquals( 1, q.list().size() );
|
||||
//
|
||||
// tx.rollback();
|
||||
// s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
HabitatSpeciesLink.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getOrmXmlFiles() {
|
||||
return new String[] {
|
||||
"org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml"
|
||||
};
|
||||
}
|
||||
}
|
|
@ -9,12 +9,12 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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.test.annotations.idclass.xml.HabitatSpeciesLink" access="FIELD">
|
||||
<entity class="org.hibernate.orm.test.annotations.idclass.xml.HabitatSpeciesLink" access="FIELD">
|
||||
<table name="HABITAT_SPECIES_LINK"/>
|
||||
<id-class
|
||||
class="org.hibernate.test.annotations.idclass.xml.HabitatSpeciesLink$HabitatSpeciesLinkId"/>
|
||||
class="org.hibernate.orm.test.annotations.idclass.xml.HabitatSpeciesLink$HabitatSpeciesLinkId"/>
|
||||
<named-native-query name="testQuery"
|
||||
result-class="org.hibernate.test.annotations.idclass.xml.HabitatSpeciesLink">
|
||||
result-class="org.hibernate.orm.test.annotations.idclass.xml.HabitatSpeciesLink">
|
||||
<query>select * from HABITAT_SPECIES_LINK link where link.HABITAT_LINK = 1</query>
|
||||
</named-native-query>
|
||||
<attributes>
|
|
@ -90,7 +90,7 @@ public class DomainModelExtension
|
|||
final MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||
|
||||
for ( String annotatedPackageName : domainModelAnnotation.annotatedPackageNames() ) {
|
||||
metadataSources.addPackage( JavaHelper.getPackageFor( annotatedPackageName ) );
|
||||
metadataSources.addPackage( annotatedPackageName );
|
||||
}
|
||||
|
||||
for ( StandardDomainModel standardDomainModel : domainModelAnnotation.standardModels() ) {
|
||||
|
|
|
@ -44,6 +44,8 @@ public @interface SessionFactory {
|
|||
boolean generateStatistics() default false;
|
||||
boolean exportSchema() default true;
|
||||
|
||||
boolean createSecondarySchemas() default false;
|
||||
|
||||
Class<? extends Interceptor> interceptorClass() default Interceptor.class;
|
||||
|
||||
Class<? extends StatementInspector> statementInspectorClass() default StatementInspector.class;
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.hibernate.boot.SessionFactoryBuilder;
|
|||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
@ -29,6 +30,7 @@ import org.hibernate.tool.schema.Action;
|
|||
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
|
||||
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.ActionGrouping;
|
||||
|
||||
import org.hibernate.testing.junit4.Helper;
|
||||
import org.junit.jupiter.api.extension.AfterAllCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
|
||||
|
@ -108,7 +110,7 @@ public class SessionFactoryExtension
|
|||
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) sessionFactoryBuilder.build();
|
||||
|
||||
if ( sessionFactoryConfig.exportSchema() ) {
|
||||
prepareSchemaExport( sessionFactory, model );
|
||||
prepareSchemaExport( sessionFactory, model, sessionFactoryConfig.createSecondarySchemas() );
|
||||
}
|
||||
|
||||
return sessionFactory;
|
||||
|
@ -140,7 +142,8 @@ public class SessionFactoryExtension
|
|||
|
||||
private static void prepareSchemaExport(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
MetadataImplementor model) {
|
||||
MetadataImplementor model,
|
||||
boolean createSecondarySchemas) {
|
||||
final Map<String, Object> baseProperties = sessionFactory.getProperties();
|
||||
|
||||
final ActionGrouping actions = ActionGrouping.interpret( baseProperties );
|
||||
|
@ -154,10 +157,15 @@ public class SessionFactoryExtension
|
|||
final HashMap settings = new HashMap<>( baseProperties );
|
||||
//noinspection unchecked
|
||||
settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE_DROP );
|
||||
|
||||
if ( createSecondarySchemas ) {
|
||||
if ( !( model.getDatabase().getDialect().canCreateSchema() ) ) {
|
||||
throw new UnsupportedOperationException(
|
||||
model.getDatabase().getDialect() + " does not support schema creation" );
|
||||
}
|
||||
settings.put( AvailableSettings.HBM2DDL_CREATE_SCHEMAS, true );
|
||||
}
|
||||
final StandardServiceRegistry serviceRegistry = model.getMetadataBuildingOptions().getServiceRegistry();
|
||||
|
||||
|
||||
SchemaManagementToolCoordinator.process(
|
||||
model,
|
||||
serviceRegistry,
|
||||
|
@ -171,6 +179,8 @@ public class SessionFactoryExtension
|
|||
}
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue