fix Oracle test failures

This commit is contained in:
Steve Ebersole 2021-12-10 13:36:26 -06:00
parent c6ed830d82
commit a2a6425b82
5 changed files with 7 additions and 236 deletions

View File

@ -17,12 +17,16 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderColumn;
import jakarta.persistence.Table;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -170,6 +174,7 @@ public class LoadEntityWithElementCollectionTest {
}
@Entity(name = "IndexedEntity")
@Table( name = "t_entities" )
public static class IndexedEntity {
@Id
public Long id;
@ -177,10 +182,12 @@ public class LoadEntityWithElementCollectionTest {
public boolean[] serializableArray;
@ElementCollection
@CollectionTable( name = "t_array_items", joinColumns = @JoinColumn( name = "entity_fk") )
@OrderColumn
public boolean[] elementCollectionArray;
@OneToMany(fetch = FetchType.EAGER)
@JoinTable( name = "t_referenced_entities", joinColumns = @JoinColumn( name = "entity_fk") )
public Set<IndexedEntity> indexedEntities;
public Long getId() {

View File

@ -1,122 +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.orm.test.generatedkeys.seqidentity;
import java.io.Serializable;
import java.util.List;
import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorType;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.PrimaryKeyJoinColumn;
import jakarta.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.OracleDialect;
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.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "5" ),
@Setting( name = AvailableSettings.USE_GET_GENERATED_KEYS, value = "true" )
}
)
@DomainModel(
annotatedClasses = {
JoinedSequenceIdentityBatchTest.Resource.class,
JoinedSequenceIdentityBatchTest.FolderResource.class
}
)
@SessionFactory
@TestForIssue( jiraKey = "HHH-13365" )
@RequiresDialect( value = OracleDialect.class, majorVersion = 9 )
public class JoinedSequenceIdentityBatchTest {
@Test
public void testInsertAndUpdate(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
FolderResource folder = new FolderResource();
folder.name = "PARENT";
session.persist( folder );
}
);
scope.inTransaction(
session -> {
List<FolderResource> folderResources = session.createQuery( "from FolderResource" ).getResultList();
assertEquals( 1, folderResources.size() );
final FolderResource folderResource = folderResources.get( 0 );
assertNull( folderResource.description );
folderResource.description = "A folder resource";
}
);
scope.inTransaction(
session -> {
List<FolderResource> folderResources = session.createQuery( "from FolderResource" ).getResultList();
assertEquals( 1, folderResources.size() );
final FolderResource folderResource = folderResources.get( 0 );
assertEquals( "A folder resource", folderResource.description );
}
);
}
@Entity(name = "Resource")
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "WORKSPACE_RESOURCE")
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public static class Resource {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_WORKSPACE_RESOURCE")
@GenericGenerator(name = "SEQ_WORKSPACE_RESOURCE", strategy = "sequence-identity",
parameters = {@Parameter(name = "sequence", value = "SEQ_WORKSPACE_RESOURCE")})
@Column(name = "ID_WORKSPACE_RESOURCE", nullable = false, precision = 18)
private Long id;
@Column(name = "NAME", nullable = false, length = 256)
protected String name;
@Column(name = "RESOURCE_TYPE", nullable = false, length = 20)
protected String type;
}
@Entity(name = "FolderResource")
@Table(name = "WORKSPACE_RESOURCE_FOLDER")
@PrimaryKeyJoinColumn(name = "ID_WORKSPACE_RESOURCE_FOLDER")
@DiscriminatorValue("FOLDER")
public static class FolderResource extends Resource implements Serializable {
private String description;
public FolderResource()
{
super();
type = "FOLDER";
}
}
}

View File

@ -1,24 +0,0 @@
<?xml version="1.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>.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.orm.test.generatedkeys.seqidentity" default-access="field">
<class name="MyEntity" table="my_entity">
<id name="id">
<generator class="sequence-identity"/>
</id>
<natural-id>
<property name="name"/>
</natural-id>
</class>
</hibernate-mapping>

View File

@ -1,35 +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.orm.test.generatedkeys.seqidentity;
/**
* @author <a href="mailto:steve@hibernate.org">Steve Ebersole </a>
*/
public class MyEntity {
private Long id;
private String name;
public MyEntity() {
}
public MyEntity(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,55 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.generatedkeys.seqidentity;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Steve Ebersole
*/
@ServiceRegistry(
settings = {
//this test makes no sense w/o the following property enabled
//note : this property is set to false by default in Oracle9iDialect
//but if this property is set to false, then the AssertionFailure will
//be thrown by {@link org.hibernate.engine.jdbc.internal.StatementPreparerImpl.checkAutoGeneratedKeysSupportEnabled()}
//so let just change this here and this should be invested deeper.
@Setting( name = Environment.USE_GET_GENERATED_KEYS, value = "true")
}
)
@DomainModel(
xmlMappings = "org/hibernate/orm/test/generatedkeys/seqidentity/MyEntity.hbm.xml"
)
@SessionFactory
@RequiresDialect(value = OracleDialect.class, majorVersion = 9)
public class SequenceIdentityTest {
@Test
public void testSequenceIdentityGenerator(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
MyEntity e = new MyEntity( "entity-1" );
session.save( e );
// this insert should happen immediately!
assertNotNull( e.getId(), "id not generated through forced insertion" );
session.delete( e );
}
);
}
}