Re-enabled few more tests

This commit is contained in:
Andrea Boriero 2020-02-12 15:32:44 +00:00 committed by Steve Ebersole
parent a1b38ad58f
commit 08b08c0d81
60 changed files with 569 additions and 522 deletions

View File

@ -1,41 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.sql.results.graph.collection.internal;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.sql.results.graph.collection.CollectionInitializer;
import org.hibernate.sql.results.graph.DomainResultAssembler;
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions;
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* @author Steve Ebersole
*/
public class PluralAttributeAssemblerImpl implements DomainResultAssembler {
private final CollectionInitializer initializer;
public PluralAttributeAssemblerImpl(CollectionInitializer initializer) {
this.initializer = initializer;
}
@Override
public Object assemble(
RowProcessingState rowProcessingState,
JdbcValuesSourceProcessingOptions options) {
PersistentCollection collectionInstance = initializer.getCollectionInstance();
if ( collectionInstance == null ) {
return null;
}
return collectionInstance.getValue();
}
@Override
public JavaTypeDescriptor getAssembledJavaTypeDescriptor() {
return initializer.getInitializedPart().getJavaTypeDescriptor();
}
}

View File

@ -0,0 +1,177 @@
/*
* 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.access;
import org.hibernate.Transaction;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* @author Emmanuel Bernard
*/
@DomainModel(
annotatedClasses = {
Bed.class,
Chair.class,
Furniture.class,
BigBed.class,
Gardenshed.class,
}
)
@ServiceRegistry
@SessionFactory
public class AccessTest {
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery( "delete from Furniture" ).executeUpdate();
session.createQuery( "delete from Chair" ).executeUpdate();
session.createQuery( "delete from BigBed" ).executeUpdate();
session.createQuery( "delete from Gardenshed" ).executeUpdate();
}
);
}
@Test
public void testSuperclassOverriding(SessionFactoryScope scope) {
Furniture fur = new Furniture();
fur.setColor( "Black" );
fur.setName( "Beech" );
fur.isAlive = true;
scope.inSession(
session -> {
Transaction tx = session.beginTransaction();
session.persist( fur );
tx.commit();
session.clear();
tx = session.beginTransaction();
Furniture retrievedFur = session.get( Furniture.class, fur.getId() );
assertFalse( retrievedFur.isAlive );
assertNotNull( retrievedFur.getColor() );
tx.commit();
}
);
}
@Test
public void testSuperclassNonOverriding(SessionFactoryScope scope) {
Furniture fur = new Furniture();
fur.setGod( "Buddha" );
scope.inSession(
session -> {
Transaction tx = session.beginTransaction();
session.persist( fur );
tx.commit();
session.clear();
tx = session.beginTransaction();
Furniture retrievedFur = session.get( Furniture.class, fur.getId() );
assertNotNull( retrievedFur.getGod() );
tx.commit();
}
);
}
@Test
public void testPropertyOverriding(SessionFactoryScope scope) {
Furniture fur = new Furniture();
fur.weight = 3;
scope.inSession(
session -> {
Transaction tx = session.beginTransaction();
session.persist( fur );
tx.commit();
session.clear();
tx = session.beginTransaction();
Furniture retrievedFur = session.get( Furniture.class, fur.getId() );
assertEquals( 5, retrievedFur.weight );
tx.commit();
}
);
}
@Test
public void testNonOverridenSubclass(SessionFactoryScope scope) {
Chair chair = new Chair();
chair.setPillow( "Blue" );
scope.inSession(
session -> {
Transaction tx = session.beginTransaction();
session.persist( chair );
tx.commit();
session.clear();
tx = session.beginTransaction();
Chair retrievedChair = ( session.get( Chair.class, chair.getId() ) );
assertNull( retrievedChair.getPillow() );
tx.commit();
}
);
}
@Test
public void testOverridenSubclass(SessionFactoryScope scope) {
BigBed bed = new BigBed();
bed.size = 5;
bed.setQuality( "good" );
scope.inSession(
session -> {
Transaction tx = session.beginTransaction();
session.persist( bed );
tx.commit();
session.clear();
tx = session.beginTransaction();
BigBed retrievedBed = session.get( BigBed.class, bed.getId() );
assertEquals( 5, retrievedBed.size );
assertNull( retrievedBed.getQuality() );
tx.commit();
}
);
}
@Test
public void testFieldsOverriding(SessionFactoryScope scope) {
Gardenshed gs = new Gardenshed();
gs.floors = 4;
scope.inSession(
session -> {
Transaction tx = session.beginTransaction();
session.persist( gs );
tx.commit();
session.clear();
tx = session.beginTransaction();
Gardenshed retrievedGs = session.get( Gardenshed.class, gs.getId() );
assertEquals( 4, retrievedGs.floors );
assertEquals( 6, retrievedGs.getFloors() );
tx.commit();
}
);
}
}

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.annotations.access;
package org.hibernate.orm.test.annotations.access;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -17,12 +17,12 @@ import org.hibernate.mapping.Property;
import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.service.ServiceRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.TestForIssue;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
@ -33,12 +33,12 @@ import static org.junit.Assert.assertEquals;
public class AttributeAccessorTest {
private ServiceRegistry serviceRegistry;
@Before
@BeforeEach
public void setUp() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
@After
@AfterEach
public void cleanUp() {
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
@ -83,7 +83,7 @@ public class AttributeAccessorTest {
this.id = id;
}
@AttributeAccessor( "org.hibernate.test.annotations.access.AttributeAccessorTest$BasicAttributeAccessor" )
@AttributeAccessor("org.hibernate.orm.test.annotations.access.AttributeAccessorTest$BasicAttributeAccessor")
public String getName() {
return name;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@
// $Id$
package org.hibernate.test.annotations.access;
package org.hibernate.orm.test.annotations.access;
import javax.persistence.Embeddable;
/**

View File

@ -7,7 +7,7 @@
// $Id$
package org.hibernate.test.annotations.access;
package org.hibernate.orm.test.annotations.access;
import javax.persistence.Entity;

View File

@ -6,11 +6,8 @@
*/
//$Id$
package org.hibernate.test.annotations.access;
package org.hibernate.orm.test.annotations.access;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import org.hibernate.annotations.AccessType;

View File

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

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.access;
package org.hibernate.orm.test.annotations.access;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.access;
package org.hibernate.orm.test.annotations.access;
import javax.persistence.MappedSuperclass;
import org.hibernate.annotations.AccessType;

View File

@ -0,0 +1,270 @@
/*
* 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.access.jpa;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Transaction;
import org.hibernate.orm.test.annotations.access.Closet;
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.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
@DomainModel(
annotatedClasses = {
Bed.class,
Chair.class,
Furniture.class,
BigBed.class,
Gardenshed.class,
Closet.class,
Person.class,
User.class,
Shape.class,
Circle.class,
Color.class,
Square.class,
Position.class
}
)
@SessionFactory
@ServiceRegistry
public class AccessTest {
@Test
public void testDefaultConfigurationModeIsInherited(SessionFactoryScope scope) {
User john = new User();
john.setFirstname( "John" );
john.setLastname( "Doe" );
List<User> friends = new ArrayList<>();
User friend = new User();
friend.setFirstname( "Jane" );
friend.setLastname( "Doe" );
friends.add( friend );
john.setFriends( friends );
scope.inSession(
session -> {
session.persist( john );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
User user = session.get( User.class, john.getId() );
assertEquals( 1, user.getFriends().size(), "Wrong number of friends" );
assertNull( user.firstname );
session.delete( user );
tx.commit();
}
);
}
@Test
public void testSuperclassOverriding(SessionFactoryScope scope) {
Furniture fur = new Furniture();
fur.setColor( "Black" );
fur.setName( "Beech" );
fur.isAlive = true;
scope.inSession(
session -> {
session.persist( fur );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
Furniture retrievedFurniture = session.get( Furniture.class, fur.getId() );
assertFalse( retrievedFurniture.isAlive );
assertNotNull( retrievedFurniture.getColor() );
session.delete( retrievedFurniture );
tx.commit();
}
);
}
@Test
public void testSuperclassNonOverriding(SessionFactoryScope scope) {
Furniture fur = new Furniture();
fur.setGod( "Buddha" );
scope.inSession(
session -> {
session.persist( fur );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
Furniture retrievedFurniture = session.get( Furniture.class, fur.getId() );
assertNotNull( retrievedFurniture.getGod() );
session.delete( retrievedFurniture );
tx.commit();
}
);
}
@Test
public void testPropertyOverriding(SessionFactoryScope scope) {
Furniture fur = new Furniture();
fur.weight = 3;
scope.inSession(
session -> {
session.persist( fur );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
Furniture retrievedFurniture = session.get( Furniture.class, fur.getId() );
assertEquals( 5, retrievedFurniture.weight );
session.delete( retrievedFurniture );
tx.commit();
}
);
}
@Test
public void testNonOverridenSubclass(SessionFactoryScope scope) {
Chair chair = new Chair();
chair.setPillow( "Blue" );
scope.inSession(
session -> {
session.persist( chair );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
Chair retrievedChair = session.get( Chair.class, chair.getId() );
assertNull( retrievedChair.getPillow() );
session.delete( retrievedChair );
tx.commit();
}
);
}
@Test
public void testOverridenSubclass(SessionFactoryScope scope) {
BigBed bed = new BigBed();
bed.size = 5;
bed.setQuality( "good" );
scope.inSession(
session -> {
session.persist( bed );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
BigBed retievedBed = session.get( BigBed.class, bed.getId() );
assertEquals( 5, retievedBed.size );
assertNull( retievedBed.getQuality() );
session.delete( retievedBed );
tx.commit();
}
);
}
@Test
public void testFieldsOverriding(SessionFactoryScope scope) {
Gardenshed gs = new Gardenshed();
gs.floors = 4;
scope.inSession(
session -> {
session.persist( gs );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
Gardenshed retrievedGardenshed = session.get( Gardenshed.class, gs.getId() );
assertEquals( 4, retrievedGardenshed.floors );
assertEquals( 6, retrievedGardenshed.getFloors() );
session.delete( retrievedGardenshed );
tx.commit();
}
);
}
@Test
public void testEmbeddableUsesAccessStrategyOfContainingClass(SessionFactoryScope scope) {
Circle circle = new Circle();
Color color = new Color( 5, 10, 15 );
circle.setColor( color );
scope.inSession(
session -> {
session.persist( circle );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
Circle retrievedCircle = session.get( Circle.class, circle.getId() );
assertEquals( 5, retrievedCircle.getColor().r );
try {
retrievedCircle.getColor().getR();
fail();
}
catch (RuntimeException e) {
// success
}
session.delete( retrievedCircle );
tx.commit();
}
);
}
@Test
public void testEmbeddableExplicitAccessStrategy(SessionFactoryScope scope) {
Square square = new Square();
Position pos = new Position( 10, 15 );
square.setPosition( pos );
scope.inSession(
session -> {
session.persist( square );
Transaction tx = session.beginTransaction();
tx.commit();
session.clear();
tx = session.beginTransaction();
Square retrievedsquare = session.get( Square.class, square.getId() );
assertEquals( 10, retrievedsquare.getPosition().x );
try {
retrievedsquare.getPosition().getX();
fail();
}
catch (RuntimeException e) {
// success
}
session.delete( retrievedsquare );
tx.commit();
}
);
}
}

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;

View File

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

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Entity;
import javax.persistence.Transient;

View File

@ -7,7 +7,7 @@
//$Id: Being.java 18260 2009-12-17 21:14:07Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Embedded;

View File

@ -7,7 +7,7 @@
//$Id: Being.java 18260 2009-12-17 21:14:07Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Embeddable;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.Access;
import javax.persistence.AccessType;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.Access;
import javax.persistence.AccessType;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.Access;
import javax.persistence.AccessType;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.Access;
import javax.persistence.AccessType;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.Access;
import javax.persistence.AccessType;

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Access;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Access;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -7,7 +7,7 @@
//$Id: Being.java 18260 2009-12-17 21:14:07Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Entity;

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Access;
import javax.persistence.Entity;

View File

@ -7,7 +7,7 @@
//$Id: Being.java 18260 2009-12-17 21:14:07Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Embeddable;

View File

@ -7,7 +7,7 @@
//$Id: Being.java 18260 2009-12-17 21:14:07Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -7,7 +7,7 @@
//$Id: Being.java 18260 2009-12-17 21:14:07Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -7,7 +7,7 @@
//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

View File

@ -7,7 +7,7 @@
//$Id$
package org.hibernate.test.annotations.access.jpa;
package org.hibernate.orm.test.annotations.access.jpa;
import javax.persistence.Access;
import javax.persistence.MappedSuperclass;

View File

@ -7,7 +7,7 @@
// $Id:$
package org.hibernate.test.annotations.access.xml;
package org.hibernate.orm.test.annotations.access.xml;
import java.util.Set;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -7,7 +7,7 @@
// $Id$
package org.hibernate.test.annotations.access.xml;
package org.hibernate.orm.test.annotations.access.xml;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -7,7 +7,7 @@
// $Id$
package org.hibernate.test.annotations.access.xml;
package org.hibernate.orm.test.annotations.access.xml;

View File

@ -7,7 +7,7 @@
// $Id$
package org.hibernate.test.annotations.access.xml;
package org.hibernate.orm.test.annotations.access.xml;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -7,7 +7,7 @@
// $Id: Waiter.java 18506 2010-01-11 20:23:08Z hardy.ferentschik $
package org.hibernate.test.annotations.access.xml;
package org.hibernate.orm.test.annotations.access.xml;
import javax.persistence.Embeddable;
/**

View File

@ -7,7 +7,7 @@
// $Id$
package org.hibernate.test.annotations.access.xml;
package org.hibernate.orm.test.annotations.access.xml;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -7,7 +7,7 @@
// $Id$
package org.hibernate.test.annotations.access.xml;
package org.hibernate.orm.test.annotations.access.xml;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

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

View File

@ -4,38 +4,39 @@
* 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.access.xml;
package org.hibernate.orm.test.annotations.access.xml;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.persistence.AccessType;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.GetterFieldImpl;
import org.hibernate.property.access.spi.GetterMethodImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test verifying that it is possible to configure the access type via xml configuration.
*
* @author Hardy Ferentschik
*/
public class XmlAccessTest extends BaseUnitTestCase {
public class XmlAccessTest {
@Test
public void testAccessOnBasicXmlElement() throws Exception {
public void testAccessOnBasicXmlElement() {
Class<?> classUnderTest = Tourist.class;
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Class<?>> classes = new ArrayList<>();
classes.add( classUnderTest );
List<String> configFiles = Collections.emptyList();
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
@ -44,17 +45,17 @@ public class XmlAccessTest extends BaseUnitTestCase {
assertAccessType( factory, classUnderTest, AccessType.FIELD );
factory.close();
// now with an additional xml configuration file changing the default access type for Tourist using basic
configFiles = new ArrayList<String>();
configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist.xml" );
configFiles = new ArrayList<>();
configFiles.add( "org/hibernate/orm/test/annotations/access/xml/Tourist.xml" );
factory = buildSessionFactory( classes, configFiles );
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
factory.close();
}
@Test
public void testAccessOnPersistenceUnitDefaultsXmlElement() throws Exception {
public void testAccessOnPersistenceUnitDefaultsXmlElement() {
Class<?> classUnderTest = Tourist.class;
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Class<?>> classes = new ArrayList<>();
classes.add( classUnderTest );
List<String> configFiles = Collections.emptyList();
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
@ -63,17 +64,17 @@ public class XmlAccessTest extends BaseUnitTestCase {
assertAccessType( factory, classUnderTest, AccessType.FIELD );
factory.close();
// now with an additional xml configuration file changing the default access type for Tourist using persitence unit defaults
configFiles = new ArrayList<String>();
configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist2.xml" );
configFiles = new ArrayList<>();
configFiles.add( "org/hibernate/orm/test/annotations/access/xml/Tourist2.xml" );
factory = buildSessionFactory( classes, configFiles );
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
factory.close();
}
@Test
public void testAccessOnEntityMappingsXmlElement() throws Exception {
public void testAccessOnEntityMappingsXmlElement() {
Class<?> classUnderTest = Tourist.class;
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Class<?>> classes = new ArrayList<>();
classes.add( classUnderTest );
List<String> configFiles = Collections.emptyList();
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
@ -82,17 +83,17 @@ public class XmlAccessTest extends BaseUnitTestCase {
assertAccessType( factory, classUnderTest, AccessType.FIELD );
factory.close();
// now with an additional xml configuration file changing the default access type for Tourist using default in entity-mappings
configFiles = new ArrayList<String>();
configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist3.xml" );
configFiles = new ArrayList<>();
configFiles.add( "org/hibernate/orm/test/annotations/access/xml/Tourist3.xml" );
factory = buildSessionFactory( classes, configFiles );
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
factory.close();
}
@Test
public void testAccessOnEntityXmlElement() throws Exception {
public void testAccessOnEntityXmlElement() {
Class<?> classUnderTest = Tourist.class;
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Class<?>> classes = new ArrayList<>();
classes.add( classUnderTest );
List<String> configFiles = Collections.emptyList();
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
@ -101,59 +102,59 @@ public class XmlAccessTest extends BaseUnitTestCase {
assertAccessType( factory, classUnderTest, AccessType.FIELD );
factory.close();
// now with an additional xml configuration file changing the default access type for Tourist using entity level config
configFiles = new ArrayList<String>();
configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist4.xml" );
configFiles = new ArrayList<>();
configFiles.add( "org/hibernate/orm/test/annotations/access/xml/Tourist4.xml" );
factory = buildSessionFactory( classes, configFiles );
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
factory.close();
}
@Test
public void testAccessOnMappedSuperClassXmlElement() throws Exception {
public void testAccessOnMappedSuperClassXmlElement() {
Class<?> classUnderTest = Waiter.class;
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Class<?>> classes = new ArrayList<>();
classes.add( classUnderTest );
classes.add( Crew.class );
List<String> configFiles = new ArrayList<String>();
configFiles.add( "org/hibernate/test/annotations/access/xml/Crew.xml" );
List<String> configFiles = new ArrayList<>();
configFiles.add( "org/hibernate/orm/test/annotations/access/xml/Crew.xml" );
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
assertAccessType( factory, classUnderTest, AccessType.FIELD );
factory.close();
}
@Test
public void testAccessOnAssociationXmlElement() throws Exception {
public void testAccessOnAssociationXmlElement() {
Class<?> classUnderTest = RentalCar.class;
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Class<?>> classes = new ArrayList<>();
classes.add( classUnderTest );
classes.add( Driver.class );
List<String> configFiles = new ArrayList<String>();
configFiles.add( "org/hibernate/test/annotations/access/xml/RentalCar.xml" );
List<String> configFiles = new ArrayList<>();
configFiles.add( "org/hibernate/orm/test/annotations/access/xml/RentalCar.xml" );
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
factory.close();
}
@Test
public void testAccessOnEmbeddedXmlElement() throws Exception {
public void testAccessOnEmbeddedXmlElement() {
Class<?> classUnderTest = Cook.class;
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Class<?>> classes = new ArrayList<>();
classes.add( classUnderTest );
classes.add( Knive.class );
List<String> configFiles = new ArrayList<String>();
configFiles.add( "org/hibernate/test/annotations/access/xml/Cook.xml" );
List<String> configFiles = new ArrayList<>();
configFiles.add( "org/hibernate/orm/test/annotations/access/xml/Cook.xml" );
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
factory.close();
}
@Test
public void testAccessOnElementCollectionXmlElement() throws Exception {
public void testAccessOnElementCollectionXmlElement() {
Class<?> classUnderTest = Boy.class;
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Class<?>> classes = new ArrayList<>();
classes.add( classUnderTest );
List<String> configFiles = new ArrayList<String>();
configFiles.add( "org/hibernate/test/annotations/access/xml/Boy.xml" );
List<String> configFiles = new ArrayList<>();
configFiles.add( "org/hibernate/orm/test/annotations/access/xml/Boy.xml" );
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
factory.close();
@ -167,33 +168,36 @@ public class XmlAccessTest extends BaseUnitTestCase {
cfg.addAnnotatedClass( clazz );
}
for ( String configFile : configFiles ) {
try ( InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( configFile ) ) {
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( configFile )) {
cfg.addInputStream( is );
}
catch (IOException e) {
throw new IllegalArgumentException( e );
}
}
return ( SessionFactoryImplementor ) cfg.buildSessionFactory();
return (SessionFactoryImplementor) cfg.buildSessionFactory();
}
// uses the first getter of the tupelizer for the assertions
private void assertAccessType(SessionFactoryImplementor factory, Class<?> classUnderTest, AccessType accessType) {
final EntityPersister entityDescriptor = factory.getDomainModel().findEntityDescriptor( classUnderTest.getName() );
final SingleAttributeIdentifierMapping identifierMapping = (SingleAttributeIdentifierMapping) entityDescriptor.getIdentifierMapping();
final Getter idGetter = identifierMapping.getPropertyAccess().getGetter();
final EntityPersister entityDescriptor = factory.getDomainModel()
.findEntityDescriptor( classUnderTest.getName() );
final Collection<AttributeMapping> attributeMappings = entityDescriptor.getAttributeMappings();
final AttributeMapping attributeMapping = attributeMappings.iterator().next();
final Getter accessGetter = attributeMapping.getPropertyAccess().getGetter();
if ( AccessType.FIELD.equals( accessType ) ) {
Assert.assertTrue(
"Field access was expected.",
idGetter instanceof GetterFieldImpl
assertTrue(
accessGetter instanceof GetterFieldImpl,
"Field access was expected."
);
}
else {
Assert.assertTrue(
"Property access was expected.",
idGetter instanceof GetterMethodImpl
assertTrue(
accessGetter instanceof GetterMethodImpl,
"Property access was expected."
);
}
}

View File

@ -1,137 +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.access;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* @author Emmanuel Bernard
*/
public class AccessTest extends BaseCoreFunctionalTestCase {
@Test
public void testSuperclassOverriding() throws Exception {
Furniture fur = new Furniture();
fur.setColor( "Black" );
fur.setName( "Beech" );
fur.isAlive = true;
Session s = openSession();
s.persist( fur );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
assertFalse( fur.isAlive );
assertNotNull( fur.getColor() );
s.delete( fur );
tx.commit();
s.close();
}
@Test
public void testSuperclassNonOverriding() throws Exception {
Furniture fur = new Furniture();
fur.setGod( "Buddha" );
Session s = openSession();
s.persist( fur );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
assertNotNull( fur.getGod() );
s.delete( fur );
tx.commit();
s.close();
}
@Test
public void testPropertyOverriding() throws Exception {
Furniture fur = new Furniture();
fur.weight = 3;
Session s = openSession();
s.persist( fur );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
assertEquals( 5, fur.weight );
s.delete( fur );
tx.commit();
s.close();
}
@Test
public void testNonOverridenSubclass() throws Exception {
Chair chair = new Chair();
chair.setPillow( "Blue" );
Session s = openSession();
s.persist( chair );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
chair = ( Chair ) s.get( Chair.class, chair.getId() );
assertNull( chair.getPillow() );
s.delete( chair );
tx.commit();
s.close();
}
@Test
public void testOverridenSubclass() throws Exception {
BigBed bed = new BigBed();
bed.size = 5;
bed.setQuality( "good" );
Session s = openSession();
s.persist( bed );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
bed = ( BigBed ) s.get( BigBed.class, bed.getId() );
assertEquals( 5, bed.size );
assertNull( bed.getQuality() );
s.delete( bed );
tx.commit();
s.close();
}
@Test
public void testFieldsOverriding() throws Exception {
Gardenshed gs = new Gardenshed();
gs.floors = 4;
Session s = openSession();
s.persist( gs );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
gs = ( Gardenshed ) s.get( Gardenshed.class, gs.getId() );
assertEquals( 4, gs.floors );
assertEquals( 6, gs.getFloors() );
s.delete( gs );
tx.commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
Bed.class,
Chair.class,
Furniture.class,
BigBed.class,
Gardenshed.class,
};
}
}

View File

@ -1,232 +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.access.jpa;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.annotations.access.Closet;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
/**
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
public class AccessTest extends BaseCoreFunctionalTestCase {
@Test
public void testDefaultConfigurationModeIsInherited() throws Exception {
User john = new User();
john.setFirstname( "John" );
john.setLastname( "Doe" );
List<User> friends = new ArrayList<User>();
User friend = new User();
friend.setFirstname( "Jane" );
friend.setLastname( "Doe" );
friends.add( friend );
john.setFriends( friends );
Session s = openSession();
s.persist( john );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
john = ( User ) s.get( User.class, john.getId() );
assertEquals( "Wrong number of friends", 1, john.getFriends().size() );
assertNull( john.firstname );
s.delete( john );
tx.commit();
s.close();
}
@Test
public void testSuperclassOverriding() throws Exception {
Furniture fur = new Furniture();
fur.setColor( "Black" );
fur.setName( "Beech" );
fur.isAlive = true;
Session s = openSession();
s.persist( fur );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
assertFalse( fur.isAlive );
assertNotNull( fur.getColor() );
s.delete( fur );
tx.commit();
s.close();
}
@Test
public void testSuperclassNonOverriding() throws Exception {
Furniture fur = new Furniture();
fur.setGod( "Buddha" );
Session s = openSession();
s.persist( fur );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
assertNotNull( fur.getGod() );
s.delete( fur );
tx.commit();
s.close();
}
@Test
public void testPropertyOverriding() throws Exception {
Furniture fur = new Furniture();
fur.weight = 3;
Session s = openSession();
s.persist( fur );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
assertEquals( 5, fur.weight );
s.delete( fur );
tx.commit();
s.close();
}
@Test
public void testNonOverridenSubclass() throws Exception {
Chair chair = new Chair();
chair.setPillow( "Blue" );
Session s = openSession();
s.persist( chair );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
chair = ( Chair ) s.get( Chair.class, chair.getId() );
assertNull( chair.getPillow() );
s.delete( chair );
tx.commit();
s.close();
}
@Test
public void testOverridenSubclass() throws Exception {
BigBed bed = new BigBed();
bed.size = 5;
bed.setQuality( "good" );
Session s = openSession();
s.persist( bed );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
bed = ( BigBed ) s.get( BigBed.class, bed.getId() );
assertEquals( 5, bed.size );
assertNull( bed.getQuality() );
s.delete( bed );
tx.commit();
s.close();
}
@Test
public void testFieldsOverriding() throws Exception {
Gardenshed gs = new Gardenshed();
gs.floors = 4;
Session s = openSession();
s.persist( gs );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
gs = ( Gardenshed ) s.get( Gardenshed.class, gs.getId() );
assertEquals( 4, gs.floors );
assertEquals( 6, gs.getFloors() );
s.delete( gs );
tx.commit();
s.close();
}
@Test
public void testEmbeddableUsesAccessStrategyOfContainingClass() throws Exception {
Circle circle = new Circle();
Color color = new Color( 5, 10, 15 );
circle.setColor( color );
Session s = openSession();
s.persist( circle );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
circle = ( Circle ) s.get( Circle.class, circle.getId() );
assertEquals( 5, circle.getColor().r );
try {
circle.getColor().getR();
fail();
} catch (RuntimeException e) {
// success
}
s.delete( circle );
tx.commit();
s.close();
}
@Test
public void testEmbeddableExplicitAccessStrategy() throws Exception {
Square square = new Square();
Position pos = new Position( 10, 15 );
square.setPosition( pos );
Session s = openSession();
s.persist( square );
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
square = ( Square ) s.get( Square.class, square.getId() );
assertEquals( 10, square.getPosition().x );
try {
square.getPosition().getX();
fail();
} catch (RuntimeException e) {
// success
}
s.delete( square );
tx.commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
Bed.class,
Chair.class,
Furniture.class,
BigBed.class,
Gardenshed.class,
Closet.class,
Person.class,
User.class,
Shape.class,
Circle.class,
Color.class,
Square.class,
Position.class
};
}
}

View File

@ -8,7 +8,7 @@
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<package>org.hibernate.test.annotations.access.xml</package>
<package>org.hibernate.orm.test.annotations.access.xml</package>
<entity class="Boy" metadata-complete="false">
<attributes>
<element-collection name="nickNames" target-class="java.lang.String" access="PROPERTY"/>

View File

@ -8,7 +8,7 @@
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<package>org.hibernate.test.annotations.access.xml</package>
<package>org.hibernate.orm.test.annotations.access.xml</package>
<entity class="Cook" metadata-complete="false">
<attributes>
<embedded name="favouriteKnife" access="PROPERTY"/>

View File

@ -8,7 +8,7 @@
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<package>org.hibernate.test.annotations.access.xml</package>
<package>org.hibernate.orm.test.annotations.access.xml</package>
<mapped-superclass class="Crew" metadata-complete="false" access="FIELD">
<attributes>
<id name="id">

View File

@ -8,7 +8,7 @@
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<package>org.hibernate.test.annotations.access.xml</package>
<package>org.hibernate.orm.test.annotations.access.xml</package>
<entity class="RentalCar" metadata-complete="false">
<attributes>
<one-to-one name="driver" target-entity="Driver" access="PROPERTY"/>

View File

@ -9,7 +9,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<description>Mapping for Tourist entity</description>
<package>org.hibernate.test.annotations.access.xml</package>
<package>org.hibernate.orm.test.annotations.access.xml</package>
<entity class="Tourist" cacheable="false" metadata-complete="false">
<attributes>
<basic name="name" access="PROPERTY"/>

View File

@ -14,7 +14,7 @@
<access>PROPERTY</access>
</persistence-unit-defaults>
</persistence-unit-metadata>
<package>org.hibernate.test.annotations.access.xml</package>
<package>org.hibernate.orm.test.annotations.access.xml</package>
<entity class="Tourist" cacheable="false" metadata-complete="false">
<attributes>
<id name="id" access="FIELD"/>

View File

@ -9,7 +9,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<description>Mapping for Tourist entity</description>
<package>org.hibernate.test.annotations.access.xml</package>
<package>org.hibernate.orm.test.annotations.access.xml</package>
<access>PROPERTY</access>
<entity class="Tourist" cacheable="false" metadata-complete="false">
<attributes>

View File

@ -9,7 +9,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<description>Mapping for Tourist entity</description>
<package>org.hibernate.test.annotations.access.xml</package>
<package>org.hibernate.orm.test.annotations.access.xml</package>
<entity class="Tourist" cacheable="false" metadata-complete="false" access="PROPERTY">
<attributes>
<id name="id" access="FIELD"/>

View File

@ -93,7 +93,16 @@ public class SessionFactoryScope implements SessionFactoryAccess {
try (SessionImplementor session = (SessionImplementor) sfi.openSession()) {
log.trace( "Session opened, calling action" );
action.accept( session );
try {
action.accept( session );
}
catch (Exception e) {
Transaction transaction = session.getTransaction();
if ( transaction != null && transaction.isActive() ) {
transaction.rollback();
}
throw e;
}
log.trace( "called action" );
}
finally {