HHH-12098 - prep 5.3

This commit is contained in:
Steve Ebersole 2017-12-01 15:08:47 -06:00
parent e960f17a7b
commit 888ade0106
5 changed files with 38 additions and 46 deletions

View File

@ -904,37 +904,19 @@ public void testUpdateOnManyToOne() {
@Test @Test
public void testUpdateOnImplicitJoinFails() { public void testUpdateOnImplicitJoinFails() {
Session s = openSession(); inTransaction(
Transaction t = s.beginTransaction(); s -> {
try {
Human human = new Human(); s.createQuery( "update Human set mother.name.initial = :initial" ).setString( "initial", "F" ).executeUpdate();
human.setName( new Name( "Steve", 'E', null ) ); fail( "update allowed across implicit join" );
}
Human mother = new Human(); catch (IllegalArgumentException e) {
mother.setName( new Name( "Jane", 'E', null ) ); assertTyping( QueryException.class, e.getCause() );
human.setMother( mother ); }
catch( QueryException e ) {
s.save( human ); }
s.save( mother ); }
s.flush(); );
t.commit();
t = s.beginTransaction();
try {
s.createQuery( "update Human set mother.name.initial = :initial" ).setString( "initial", "F" ).executeUpdate();
fail( "update allowed across implicit join" );
}
catch (IllegalArgumentException e) {
assertTyping( QueryException.class, e.getCause() );
}
catch( QueryException e ) {
}
s.createQuery( "delete Human where mother is not null" ).executeUpdate();
s.createQuery( "delete Human" ).executeUpdate();
t.commit();
s.close();
} }
@Test @Test

View File

@ -94,6 +94,25 @@ public void testSimpleCaseStatementWithParamAllResults() {
.list(); .list();
} }
); );
inTransaction(
s,
session -> {
try {
s.createQuery( "select case p.name when 'Steve' then :opt1 else :opt2 end from Person p" )
.setString( "opt1", "x" )
.setString( "opt2", "y" )
.list();
fail( "was expecting an exception" );
}
catch (IllegalArgumentException e) {
assertTyping( QueryException.class, e.getCause() );
}
catch (QueryException expected) {
// expected
}
}
);
} }
} }

View File

@ -79,8 +79,8 @@ public void testInsertOrderingAvoidingForeignKeyConstraintViolation() {
@Access(AccessType.FIELD) @Access(AccessType.FIELD)
public static class MarketBid { public static class MarketBid {
@Id @Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketBid") @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE")
@TableGenerator(name = "MarketBid", pkColumnValue = "MarketBid", allocationSize = 10000) @TableGenerator(name = "ID_TABLE", pkColumnValue = "MarketBid", allocationSize = 10000)
private Long id; private Long id;
@ManyToOne(optional = false, cascade = CascadeType.PERSIST) @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
@ -99,8 +99,8 @@ public void setGroup(MarketBidGroup group) {
@Access(AccessType.FIELD) @Access(AccessType.FIELD)
public static class MarketBidGroup { public static class MarketBidGroup {
@Id @Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketBidGroup") @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE")
@TableGenerator(name = "MarketBidGroup", pkColumnValue = "MarketBidGroup", allocationSize = 10000) @TableGenerator(name = "ID_TABLE", pkColumnValue = "MarketBidGroup", allocationSize = 10000)
private Long id; private Long id;
@OneToMany(mappedBy = "group") @OneToMany(mappedBy = "group")
@ -115,8 +115,8 @@ public void addMarketBid(MarketBid marketBid) {
@Access(AccessType.FIELD) @Access(AccessType.FIELD)
public static class MarketResult { public static class MarketResult {
@Id @Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketResult") @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE")
@TableGenerator(name = "MarketResult", pkColumnValue = "MarketResult", allocationSize = 10000) @TableGenerator(name = "ID_TABLE", pkColumnValue = "MarketResult", allocationSize = 10000)
private Long id; private Long id;
@ManyToOne(optional = false) @ManyToOne(optional = false)

View File

@ -11,8 +11,6 @@
import org.hibernate.test.jpa.AbstractJPATest; import org.hibernate.test.jpa.AbstractJPATest;
import org.junit.Test; import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -21,7 +19,6 @@ public class NonSelectQueryLockMode extends AbstractJPATest {
@Test( expected = IllegalStateException.class ) @Test( expected = IllegalStateException.class )
public void testNonSelectQueryGetLockMode() { public void testNonSelectQueryGetLockMode() {
inTransaction( inTransaction(
sessionFactory(),
session -> session.createQuery( "delete Item" ).getLockMode() session -> session.createQuery( "delete Item" ).getLockMode()
); );
} }
@ -29,7 +26,6 @@ public void testNonSelectQueryGetLockMode() {
@Test( expected = IllegalStateException.class ) @Test( expected = IllegalStateException.class )
public void testNonSelectQuerySetLockMode() { public void testNonSelectQuerySetLockMode() {
inTransaction( inTransaction(
sessionFactory(),
session -> session.createQuery( "delete Item" ).setLockMode( LockModeType.PESSIMISTIC_WRITE ) session -> session.createQuery( "delete Item" ).setLockMode( LockModeType.PESSIMISTIC_WRITE )
); );
} }

View File

@ -18,7 +18,6 @@
import org.junit.Test; import org.junit.Test;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -41,7 +40,6 @@ protected void configure(Configuration configuration) {
@Test @Test
public void testResultClass() { public void testResultClass() {
inTransaction( inTransaction(
sessionFactory(),
session -> { session -> {
final ProcedureCall call = session.createStoredProcedureCall( final ProcedureCall call = session.createStoredProcedureCall(
"findOneUser", "findOneUser",
@ -61,7 +59,6 @@ public void testResultClass() {
@Test @Test
public void testMappingAllFields() { public void testMappingAllFields() {
inTransaction( inTransaction(
sessionFactory(),
session -> { session -> {
final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "all-fields" ); final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "all-fields" );
final ProcedureOutputs procedureResult = call.getOutputs(); final ProcedureOutputs procedureResult = call.getOutputs();
@ -78,7 +75,6 @@ public void testMappingAllFields() {
@Test @Test
public void testMappingSomeFields() { public void testMappingSomeFields() {
inTransaction( inTransaction(
sessionFactory(),
session -> { session -> {
final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "some-fields" ); final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "some-fields" );
final ProcedureOutputs procedureResult = call.getOutputs(); final ProcedureOutputs procedureResult = call.getOutputs();
@ -95,7 +91,6 @@ public void testMappingSomeFields() {
@Test @Test
public void testMappingNoFields() { public void testMappingNoFields() {
inTransaction( inTransaction(
sessionFactory(),
session -> { session -> {
final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "no-fields" ); final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "no-fields" );
final ProcedureOutputs procedureResult = call.getOutputs(); final ProcedureOutputs procedureResult = call.getOutputs();