re-enable tests
re-organize some tests o.h.test.hql.ParameterTest -> LegacyParameterTests bug with binding ordinal parameter lists created "standard domain model" for Hibernate's legacy Animal model
This commit is contained in:
parent
cebb9d7649
commit
607234e7bf
|
@ -66,6 +66,7 @@ import org.hibernate.query.TypedParameterValue;
|
|||
import org.hibernate.query.internal.ScrollableResultsIterator;
|
||||
import org.hibernate.query.named.NamedQueryMemento;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.JavaObjectType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
import static org.hibernate.LockMode.UPGRADE;
|
||||
|
@ -964,8 +965,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
|||
}
|
||||
|
||||
if ( value instanceof Collection ) {
|
||||
//noinspection rawtypes
|
||||
setParameterList( Integer.toString( position ), (Collection) value );
|
||||
setParameterList( position, (Collection<?>) value );
|
||||
}
|
||||
else {
|
||||
locateBinding( position ).setBindValue( value );
|
||||
|
@ -1314,6 +1314,9 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
|||
type = getParameterMetadata().getQueryParameter( namedParam ).getHibernateType();
|
||||
}
|
||||
if ( type == null ) {
|
||||
if ( retType == null ) {
|
||||
return JavaObjectType.INSTANCE;
|
||||
}
|
||||
type = getSession().getFactory().resolveParameterBindType( retType );
|
||||
}
|
||||
return type;
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.tuple.component;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -103,8 +104,17 @@ public class ComponentTuplizerFactory implements Serializable {
|
|||
try {
|
||||
return constructor.newInstance( metadata );
|
||||
}
|
||||
catch ( Throwable t ) {
|
||||
throw new HibernateException( "Unable to instantiate default tuplizer [" + tuplizerClass.getName() + "]", t );
|
||||
catch (Exception e) {
|
||||
throw new HibernateException(
|
||||
String.format(
|
||||
Locale.ROOT,
|
||||
"Unable to instantiate tuplizer [%s] for component: `%s` (%s)",
|
||||
tuplizerClass.getName(),
|
||||
metadata.getComponentClassName(),
|
||||
metadata.getRoleName()
|
||||
),
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
* 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.query.hql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ExpectedException;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.domain.animal.Animal;
|
||||
import org.hibernate.testing.orm.domain.animal.Human;
|
||||
import org.hibernate.testing.orm.domain.animal.Name;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Isolated test for various usages of parameters
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel( standardModels = StandardDomainModel.ANIMAL )
|
||||
@SessionFactory
|
||||
public class LegacyParameterTests {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9154" )
|
||||
public void testClassAsParameter(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
s.createQuery( "from Human h where h.name = :class" ).setParameter( "class", new Name() ).list();
|
||||
s.createQuery( "from Human where name = :class" ).setParameter( "class", new Name() ).list();
|
||||
s.createQuery( "from Human h where :class = h.name" ).setParameter( "class", new Name() ).list();
|
||||
s.createQuery( "from Human h where :class <> h.name" ).setParameter( "class", new Name() ).list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7705")
|
||||
public void testSetPropertiesMapWithNullValues(SessionFactoryScope scope) {
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
parameters.put( "nickName", null );
|
||||
|
||||
Query<Human> q = s.createQuery(
|
||||
"from Human h where h.nickName = :nickName or (h.nickName is null and :nickName is null)",
|
||||
Human.class
|
||||
);
|
||||
q.setProperties( (parameters) );
|
||||
assertThat( q.list().size(), is( 0 ) );
|
||||
|
||||
Human human1 = new Human();
|
||||
human1.setId( 2L );
|
||||
human1.setNickName( null );
|
||||
s.save( human1 );
|
||||
|
||||
parameters = new HashMap<>();
|
||||
|
||||
parameters.put( "nickName", null );
|
||||
q = s.createQuery( "from Human h where h.nickName = :nickName or (h.nickName is null and :nickName is null)", Human.class );
|
||||
q.setProperties( (parameters) );
|
||||
assertThat( q.list().size(), is( 1 ) );
|
||||
Human found = q.list().get( 0 );
|
||||
assertThat( found.getId(), is( human1.getId() ) );
|
||||
|
||||
parameters = new HashMap<>();
|
||||
parameters.put( "nickName", "nick" );
|
||||
|
||||
q = s.createQuery( "from Human h where h.nickName = :nickName or (h.nickName is null and :nickName is null)", Human.class );
|
||||
q.setProperties( (parameters) );
|
||||
assertThat( q.list().size(), is( 1 ) );
|
||||
found = q.list().get( 0 );
|
||||
assertThat( found.getId(), is( 1L ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10796")
|
||||
public void testSetPropertiesMapNotContainingAllTheParameters(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
parameters.put( "nickNames", "nick" );
|
||||
|
||||
List<Integer> intValues = new ArrayList<>();
|
||||
intValues.add( 1 );
|
||||
//noinspection unchecked
|
||||
Query<Human> q = s.createQuery(
|
||||
"from Human h where h.nickName in (:nickNames) and h.intValue in (:intValues)"
|
||||
);
|
||||
q.setParameterList( "intValues" , intValues);
|
||||
q.setProperties( (parameters) );
|
||||
assertThat( q.list().size(), is( 1 ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9154" )
|
||||
public void testObjectAsParameter(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
s.createQuery( "from Human h where h.name = :OBJECT" ).setParameter( "OBJECT", new Name() ).list();
|
||||
s.createQuery( "from Human where name = :OBJECT" ).setParameter( "OBJECT", new Name() ).list();
|
||||
s.createQuery( "from Human h where :OBJECT = h.name" ).setParameter( "OBJECT", new Name() ).list();
|
||||
s.createQuery( "from Human h where :OBJECT <> h.name" ).setParameter( "OBJECT", new Name() ).list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetParameterListValue(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Query<Animal> query = session.createQuery( "from Animal a where a.id in :ids", Animal.class );
|
||||
query.setParameterList( "ids", Arrays.asList( 1L, 2L ) );
|
||||
|
||||
Object parameterListValue = query.getParameterValue( "ids" );
|
||||
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetParameterListValueAfterParameterExpansion(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Query<Animal> query = session.createQuery( "from Animal a where a.id in :ids", Animal.class );
|
||||
query.setParameterList( "ids", Arrays.asList( 1L, 2L ) );
|
||||
query.list();
|
||||
|
||||
Object parameterListValue = query.getParameterValue( "ids" );
|
||||
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExpectedException( IllegalStateException.class )
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetNotBoundParameterListValue(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Query<Animal> query = session.createQuery( "from Animal a where a.id in :ids", Animal.class );
|
||||
query.getParameterValue( "ids" );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetPositionalParameterListValue(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Query<Animal> query = session.createQuery( "from Animal a where a.id in ?1", Animal.class );
|
||||
query.setParameter( 1, Arrays.asList( 1L, 2L ) );
|
||||
|
||||
Object parameterListValue = query.getParameterValue( 1 );
|
||||
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
|
||||
|
||||
query.list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetPositionalParameterValue(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Query<Animal> query = session.createQuery( "from Animal a where a.id = ?1", Animal.class );
|
||||
query.setParameter( 1, 1L );
|
||||
|
||||
Object parameterListValue = query.getParameterValue( 1 );
|
||||
assertThat( parameterListValue, is( 1L ) );
|
||||
|
||||
query.list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetParameterByPositionListValueAfterParameterExpansion(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Query<Animal> query = session.createQuery( "from Animal a where a.id in ?1", Animal.class );
|
||||
query.setParameterList( 1, Arrays.asList( 1L, 2L ) );
|
||||
query.list();
|
||||
|
||||
Object parameterListValue = query.getParameterValue( 1 );
|
||||
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExpectedException( IllegalStateException.class )
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetPositionalNotBoundParameterListValue(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Query<Animal> query = session.createQuery( "from Animal a where a.id in ?1", Animal.class );
|
||||
query.getParameterValue( 1 );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void createTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
Human human = new Human();
|
||||
human.setId( 1L );
|
||||
human.setNickName( "nick" );
|
||||
human.setIntValue( 1 );
|
||||
s.save( human );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
s.createQuery( "delete Human" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -13,7 +13,10 @@ package org.hibernate.test.hql;
|
|||
* Implementation of Address.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Address} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Address {
|
||||
private String street;
|
||||
private String city;
|
||||
|
|
|
@ -12,7 +12,10 @@ import java.util.Set;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Animal} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Animal {
|
||||
private Long id;
|
||||
private float bodyWeight;
|
||||
|
|
|
@ -11,7 +11,10 @@ package org.hibernate.test.hql;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Cat} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Cat extends DomesticAnimal {
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,10 @@ import java.util.HashMap;
|
|||
* Mimic a JDK 5 enum.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Classification} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Classification implements Serializable, Comparable {
|
||||
|
||||
public static final Classification COOL = new Classification( "COOL", 0 );
|
||||
|
|
|
@ -11,7 +11,10 @@ package org.hibernate.test.hql;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Dog} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Dog extends DomesticAnimal {
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ package org.hibernate.test.hql;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.DomesticAnimal} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class DomesticAnimal extends Mammal {
|
||||
private Human owner;
|
||||
|
||||
|
|
|
@ -15,7 +15,10 @@ import java.util.Set;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Human} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Human extends Mammal {
|
||||
private Name name;
|
||||
private String nickName;
|
||||
|
|
|
@ -11,7 +11,10 @@ package org.hibernate.test.hql;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Lizard} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Lizard extends Reptile {
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Mammal} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Mammal extends Animal {
|
||||
private boolean pregnant;
|
||||
private Date birthdate;
|
||||
|
|
|
@ -11,7 +11,10 @@ package org.hibernate.test.hql;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Name} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Name {
|
||||
private String first;
|
||||
private Character initial;
|
||||
|
|
|
@ -1,258 +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.hql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Isolated test for various usages of parameters
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ParameterTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected String[] getMappings() {
|
||||
return new String[] { "hql/Animal.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9154" )
|
||||
public void testClassAsParameter() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
||||
s.createQuery( "from Human h where h.name = :class" ).setParameter( "class", new Name() ).list();
|
||||
s.createQuery( "from Human where name = :class" ).setParameter( "class", new Name() ).list();
|
||||
s.createQuery( "from Human h where :class = h.name" ).setParameter( "class", new Name() ).list();
|
||||
s.createQuery( "from Human h where :class <> h.name" ).setParameter( "class", new Name() ).list();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7705")
|
||||
public void testSetPropertiesMapWithNullValues() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
try {
|
||||
Human human = new Human();
|
||||
human.setNickName( "nick" );
|
||||
s.save( human );
|
||||
|
||||
Map parameters = new HashMap();
|
||||
parameters.put( "nickName", null );
|
||||
|
||||
Query q = s.createQuery(
|
||||
"from Human h where h.nickName = :nickName or (h.nickName is null and :nickName is null)" );
|
||||
q.setProperties( (parameters) );
|
||||
assertThat( q.list().size(), is( 0 ) );
|
||||
|
||||
Human human1 = new Human();
|
||||
human1.setNickName( null );
|
||||
s.save( human1 );
|
||||
|
||||
parameters = new HashMap();
|
||||
|
||||
parameters.put( "nickName", null );
|
||||
q = s.createQuery( "from Human h where h.nickName = :nickName or (h.nickName is null and :nickName is null)" );
|
||||
q.setProperties( (parameters) );
|
||||
assertThat( q.list().size(), is( 1 ) );
|
||||
Human found = (Human) q.list().get( 0 );
|
||||
assertThat( found.getId(), is( human1.getId() ) );
|
||||
|
||||
parameters = new HashMap();
|
||||
parameters.put( "nickName", "nick" );
|
||||
|
||||
q = s.createQuery( "from Human h where h.nickName = :nickName or (h.nickName is null and :nickName is null)" );
|
||||
q.setProperties( (parameters) );
|
||||
assertThat( q.list().size(), is( 1 ) );
|
||||
found = (Human) q.list().get( 0 );
|
||||
assertThat( found.getId(), is( human.getId() ) );
|
||||
|
||||
s.delete( human );
|
||||
s.delete( human1 );
|
||||
t.commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( session.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
|
||||
session.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10796")
|
||||
public void testSetPropertiesMapNotContainingAllTheParameters() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
try {
|
||||
Human human = new Human();
|
||||
human.setNickName( "nick" );
|
||||
human.setIntValue( 1 );
|
||||
s.save( human );
|
||||
|
||||
Map parameters = new HashMap();
|
||||
parameters.put( "nickNames", "nick" );
|
||||
|
||||
List<Integer> intValues = new ArrayList<>();
|
||||
intValues.add( 1 );
|
||||
Query q = s.createQuery(
|
||||
"from Human h where h.nickName in (:nickNames) and h.intValue in (:intValues)" );
|
||||
q.setParameterList( "intValues" , intValues);
|
||||
q.setProperties( (parameters) );
|
||||
assertThat( q.list().size(), is( 1 ) );
|
||||
|
||||
s.delete( human );
|
||||
t.commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( session.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
|
||||
session.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9154" )
|
||||
public void testObjectAsParameter() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
||||
s.createQuery( "from Human h where h.name = :OBJECT" ).setParameter( "OBJECT", new Name() ).list();
|
||||
s.createQuery( "from Human where name = :OBJECT" ).setParameter( "OBJECT", new Name() ).list();
|
||||
s.createQuery( "from Human h where :OBJECT = h.name" ).setParameter( "OBJECT", new Name() ).list();
|
||||
s.createQuery( "from Human h where :OBJECT <> h.name" ).setParameter( "OBJECT", new Name() ).list();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetParameterListValue() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
Query query = session.createQuery( "from Animal a where a.id in :ids" );
|
||||
query.setParameterList( "ids", Arrays.asList( 1L, 2L ) );
|
||||
|
||||
Object parameterListValue = query.getParameterValue( "ids" );
|
||||
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetParameterListValueAfterParameterExpansion() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
Query query = session.createQuery( "from Animal a where a.id in :ids" );
|
||||
query.setParameterList( "ids", Arrays.asList( 1L, 2L ) );
|
||||
query.list();
|
||||
|
||||
Object parameterListValue = query.getParameterValue( "ids" );
|
||||
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetNotBoundParameterListValue() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
Query query = session.createQuery( "from Animal a where a.id in :ids" );
|
||||
query.getParameterValue( "ids" );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetPositionalParameterListValue() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
Query query = session.createQuery( "from Animal a where a.id in ?1" );
|
||||
query.setParameter( 1, Arrays.asList( 1L, 2L ) );
|
||||
|
||||
Object parameterListValue = query.getParameterValue( 1 );
|
||||
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
|
||||
|
||||
query.list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetPositionalParameterValue() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
Query query = session.createQuery( "from Animal a where a.id = ?1" );
|
||||
query.setParameter( 1, 1L );
|
||||
|
||||
Object parameterListValue = query.getParameterValue( 1 );
|
||||
assertThat( parameterListValue, is( 1L ) );
|
||||
|
||||
query.list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetParameterByPositionListValueAfterParameterExpansion() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
Query query = session.createQuery( "from Animal a where a.id in ?1" );
|
||||
query.setParameterList( 1, Arrays.asList( 1L, 2L ) );
|
||||
query.list();
|
||||
|
||||
Object parameterListValue = query.getParameterValue( 1 );
|
||||
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@TestForIssue(jiraKey = "HHH-13310")
|
||||
public void testGetPositionalNotBoundParameterListValue() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
Query query = session.createQuery( "from Animal a where a.id in ?1" );
|
||||
query.getParameterValue( 1 );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -11,7 +11,10 @@ package org.hibernate.test.hql;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.PettingZoo} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class PettingZoo extends Zoo {
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ package org.hibernate.test.hql;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Reptile} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Reptile extends Animal {
|
||||
private float bodyTemperature;
|
||||
public float getBodyTemperature() {
|
||||
|
|
|
@ -13,7 +13,10 @@ package org.hibernate.test.hql;
|
|||
* Implementation of StateProvince.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.StateProvince} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class StateProvince {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
|
|
@ -12,7 +12,10 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.testing.orm.domain.animal.Zoo} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class Zoo {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.testing.orm.domain;
|
||||
|
||||
import org.hibernate.testing.orm.domain.animal.AnimalDomainModel;
|
||||
import org.hibernate.testing.orm.domain.contacts.ContactsDomainModel;
|
||||
import org.hibernate.testing.orm.domain.gambit.GambitDomainModel;
|
||||
import org.hibernate.testing.orm.domain.helpdesk.HelpDeskDomainModel;
|
||||
|
@ -16,6 +17,7 @@ import org.hibernate.testing.orm.domain.retail.RetailDomainModel;
|
|||
*/
|
||||
public enum StandardDomainModel {
|
||||
CONTACTS( ContactsDomainModel.INSTANCE ),
|
||||
ANIMAL( AnimalDomainModel.INSTANCE ),
|
||||
GAMBIT( GambitDomainModel.INSTANCE ),
|
||||
HELPDESK( HelpDeskDomainModel.INSTANCE ),
|
||||
RETAIL( RetailDomainModel.INSTANCE );
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Embeddable
|
||||
public class Address {
|
||||
private String street;
|
||||
private String city;
|
||||
private String postalCode;
|
||||
private String country;
|
||||
// private StateProvince stateProvince;
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getPostalCode() {
|
||||
return postalCode;
|
||||
}
|
||||
|
||||
public void setPostalCode(String postalCode) {
|
||||
this.postalCode = postalCode;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
// @ManyToOne
|
||||
// @JoinColumn( name = "state_prov_fk" )
|
||||
// public StateProvince getStateProvince() {
|
||||
// return stateProvince;
|
||||
// }
|
||||
//
|
||||
// public void setStateProvince(StateProvince stateProvince) {
|
||||
// this.stateProvince = stateProvince;
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public boolean equals(Object o) {
|
||||
// if ( this == o ) {
|
||||
// return true;
|
||||
// }
|
||||
// if ( o == null || getClass() != o.getClass() ) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// Address address = ( Address ) o;
|
||||
//
|
||||
// if ( city != null ? !city.equals( address.city ) : address.city != null ) {
|
||||
// return false;
|
||||
// }
|
||||
// if ( country != null ? !country.equals( address.country ) : address.country != null ) {
|
||||
// return false;
|
||||
// }
|
||||
// if ( postalCode != null ? !postalCode.equals( address.postalCode ) : address.postalCode != null ) {
|
||||
// return false;
|
||||
// }
|
||||
// if ( stateProvince != null ? !stateProvince.equals( address.stateProvince ) : address.stateProvince != null ) {
|
||||
// return false;
|
||||
// }
|
||||
// if ( street != null ? !street.equals( address.street ) : address.street != null ) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int hashCode() {
|
||||
// int result = street != null ? street.hashCode() : 0;
|
||||
// result = 31 * result + ( city != null ? city.hashCode() : 0 );
|
||||
// result = 31 * result + ( postalCode != null ? postalCode.hashCode() : 0 );
|
||||
// result = 31 * result + ( country != null ? country.hashCode() : 0 );
|
||||
// result = 31 * result + ( stateProvince != null ? stateProvince.hashCode() : 0 );
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return "Address{" +
|
||||
// "street='" + street + '\'' +
|
||||
// ", city='" + city + '\'' +
|
||||
// ", postalCode='" + postalCode + '\'' +
|
||||
// ", country='" + country + '\'' +
|
||||
// ", stateProvince=" + stateProvince +
|
||||
// '}';
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderBy;
|
||||
|
||||
@Entity
|
||||
@Inheritance( strategy = InheritanceType.JOINED )
|
||||
public class Animal {
|
||||
private Long id;
|
||||
private float bodyWeight;
|
||||
private Set offspring;
|
||||
private Animal mother;
|
||||
private Animal father;
|
||||
private String description;
|
||||
private Zoo zoo;
|
||||
private String serialNumber;
|
||||
|
||||
public Animal() {
|
||||
}
|
||||
|
||||
public Animal(String description, float bodyWeight) {
|
||||
this.description = description;
|
||||
this.bodyWeight = bodyWeight;
|
||||
}
|
||||
|
||||
@Id
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Column( name = "body_weight" )
|
||||
public float getBodyWeight() {
|
||||
return bodyWeight;
|
||||
}
|
||||
|
||||
public void setBodyWeight(float bodyWeight) {
|
||||
this.bodyWeight = bodyWeight;
|
||||
}
|
||||
|
||||
public String getSerialNumber() {
|
||||
return serialNumber;
|
||||
}
|
||||
|
||||
public void setSerialNumber(String serialNumber) {
|
||||
this.serialNumber = serialNumber;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn( name = "zoo_fk" )
|
||||
public Zoo getZoo() {
|
||||
return zoo;
|
||||
}
|
||||
|
||||
public void setZoo(Zoo zoo) {
|
||||
this.zoo = zoo;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn( name = "mother_fk" )
|
||||
public Animal getMother() {
|
||||
return mother;
|
||||
}
|
||||
|
||||
public void setMother(Animal mother) {
|
||||
this.mother = mother;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn( name = "father_fk" )
|
||||
public Animal getFather() {
|
||||
return father;
|
||||
}
|
||||
|
||||
public void setFather(Animal father) {
|
||||
this.father = father;
|
||||
}
|
||||
|
||||
@OneToMany
|
||||
@JoinColumn( name = "mother_fk" )
|
||||
@OrderBy( "father_fk" )
|
||||
public Set<Human> getOffspring() {
|
||||
return offspring;
|
||||
}
|
||||
|
||||
public void addOffspring(Animal offspring) {
|
||||
if ( this.offspring == null ) {
|
||||
this.offspring = new HashSet();
|
||||
}
|
||||
|
||||
this.offspring.add( offspring );
|
||||
}
|
||||
|
||||
public void setOffspring(Set offspring) {
|
||||
this.offspring = offspring;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
|
||||
import org.hibernate.testing.orm.domain.AbstractDomainModelDescriptor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class AnimalDomainModel extends AbstractDomainModelDescriptor {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final AnimalDomainModel INSTANCE = new AnimalDomainModel();
|
||||
|
||||
public static void applyContactsModel(MetadataSources sources) {
|
||||
INSTANCE.applyDomainModel( sources );
|
||||
}
|
||||
|
||||
public AnimalDomainModel() {
|
||||
super(
|
||||
Address.class,
|
||||
Animal.class,
|
||||
Cat.class,
|
||||
Classification.class,
|
||||
Dog.class,
|
||||
DomesticAnimal.class,
|
||||
Human.class,
|
||||
Lizard.class,
|
||||
Mammal.class,
|
||||
Name.class,
|
||||
PettingZoo.class,
|
||||
Reptile.class,
|
||||
StateProvince.class,
|
||||
Zoo.class
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn( name = "cat_id_fk" )
|
||||
public class Cat extends DomesticAnimal {
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
/**
|
||||
* Mimic a JDK 5 enum.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum Classification implements Comparable<Classification> {
|
||||
COOL,
|
||||
LAME;
|
||||
|
||||
public static Classification valueOf(Integer ordinal) {
|
||||
if ( ordinal == null ) {
|
||||
return null;
|
||||
}
|
||||
switch ( ordinal ) {
|
||||
case 0: return COOL;
|
||||
case 1: return LAME;
|
||||
default: throw new IllegalArgumentException( "unknown classification ordinal [" + ordinal + "]" );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn( name = "dog_id_fk" )
|
||||
public class Dog extends DomesticAnimal {
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn( name = "domestic_animal_id_fk" )
|
||||
public class DomesticAnimal extends Mammal {
|
||||
private Human owner;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn( name = "owner_fk" )
|
||||
public Human getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(Human owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
import org.hibernate.annotations.ColumnTransformer;
|
||||
import org.hibernate.annotations.SortNatural;
|
||||
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn( name = "human_id_fk" )
|
||||
public class Human extends Mammal {
|
||||
private Name name;
|
||||
private String nickName;
|
||||
private double heightInches;
|
||||
|
||||
private BigInteger bigIntegerValue;
|
||||
private BigDecimal bigDecimalValue;
|
||||
private int intValue;
|
||||
private float floatValue;
|
||||
|
||||
private Collection<Human> friends;
|
||||
private Collection<DomesticAnimal> pets;
|
||||
private Map <String,Human> family;
|
||||
private Set<String> nickNames;
|
||||
private Map<String,Address> addresses;
|
||||
|
||||
@Embedded
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
@Column( name = "height_centimeters", nullable = false )
|
||||
@ColumnTransformer( read = "height_centimeters / 2.54E0", write = "? * 2.54E0" )
|
||||
public double getHeightInches() {
|
||||
return heightInches;
|
||||
}
|
||||
|
||||
public void setHeightInches(double height) {
|
||||
this.heightInches = height;
|
||||
}
|
||||
|
||||
public BigDecimal getBigDecimalValue() {
|
||||
return bigDecimalValue;
|
||||
}
|
||||
|
||||
public void setBigDecimalValue(BigDecimal bigDecimalValue) {
|
||||
this.bigDecimalValue = bigDecimalValue;
|
||||
}
|
||||
|
||||
public BigInteger getBigIntegerValue() {
|
||||
return bigIntegerValue;
|
||||
}
|
||||
|
||||
public void setBigIntegerValue(BigInteger bigIntegerValue) {
|
||||
this.bigIntegerValue = bigIntegerValue;
|
||||
}
|
||||
|
||||
public float getFloatValue() {
|
||||
return floatValue;
|
||||
}
|
||||
|
||||
public void setFloatValue(float floatValue) {
|
||||
this.floatValue = floatValue;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
||||
public void setIntValue(int intValue) {
|
||||
this.intValue = intValue;
|
||||
}
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable( name = "human_nick_names", joinColumns = @JoinColumn( name = "human_fk" ) )
|
||||
@Column( name = "nick_name" )
|
||||
@SortNatural
|
||||
public Set<String> getNickNames() {
|
||||
return nickNames;
|
||||
}
|
||||
|
||||
public void setNickNames(Set<String> nickNames) {
|
||||
this.nickNames = nickNames;
|
||||
}
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "friends",
|
||||
joinColumns = @JoinColumn( name = "friend_fk1" ),
|
||||
inverseJoinColumns = @JoinColumn( name = "friend_fk2" )
|
||||
)
|
||||
public Collection<Human> getFriends() {
|
||||
return friends;
|
||||
}
|
||||
|
||||
public void setFriends(Collection<Human> friends) {
|
||||
this.friends = friends;
|
||||
}
|
||||
|
||||
@OneToMany( mappedBy = "owner" )
|
||||
public Collection<DomesticAnimal> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void setPets(Collection<DomesticAnimal> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "family",
|
||||
joinColumns = @JoinColumn( name = "family_fk1" ),
|
||||
inverseJoinColumns = @JoinColumn( name = "family_fk2" )
|
||||
)
|
||||
@MapKeyColumn( name = "relationship" )
|
||||
public Map<String,Human> getFamily() {
|
||||
return family;
|
||||
}
|
||||
|
||||
|
||||
public void setFamily(Map family) {
|
||||
this.family = family;
|
||||
}
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable( name = "human_addresses", joinColumns = @JoinColumn( name = "human_fk" ) )
|
||||
@MapKeyColumn( name = "`type`" )
|
||||
public Map<String,Address> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setAddresses(Map<String,Address> addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn( name = "lizard_id_fk" )
|
||||
public class Lizard extends Reptile {
|
||||
}
|
|
@ -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.testing.orm.domain.animal;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn( name = "mammal_id_fk" )
|
||||
public class Mammal extends Animal {
|
||||
private boolean pregnant;
|
||||
private Date birthdate;
|
||||
|
||||
public boolean isPregnant() {
|
||||
return pregnant;
|
||||
}
|
||||
|
||||
public void setPregnant(boolean pregnant) {
|
||||
this.pregnant = pregnant;
|
||||
}
|
||||
|
||||
@Temporal( TemporalType.DATE )
|
||||
public Date getBirthdate() {
|
||||
return birthdate;
|
||||
}
|
||||
|
||||
|
||||
public void setBirthdate(Date birthdate) {
|
||||
this.birthdate = birthdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( !( o instanceof Mammal ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Mammal mammal = ( Mammal ) o;
|
||||
|
||||
if ( pregnant != mammal.pregnant ) {
|
||||
return false;
|
||||
}
|
||||
if ( birthdate != null ? !birthdate.equals( mammal.birthdate ) : mammal.birthdate != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ( pregnant ? 1 : 0 );
|
||||
result = 31 * result + ( birthdate != null ? birthdate.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class Name {
|
||||
private String first;
|
||||
private Character initial;
|
||||
private String last;
|
||||
|
||||
public Name() {}
|
||||
|
||||
public Name(String first, Character initial, String last) {
|
||||
this.first = first;
|
||||
this.initial = initial;
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
public Name(String first, char initial, String last) {
|
||||
this( first, Character.valueOf( initial ), last );
|
||||
}
|
||||
|
||||
@Column( name = "name_first" )
|
||||
public String getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(String first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
@Column( name = "name_initial" )
|
||||
public Character getInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
public void setInitial(Character initial) {
|
||||
this.initial = initial;
|
||||
}
|
||||
|
||||
@Column( name = "name_last" )
|
||||
public String getLast() {
|
||||
return last;
|
||||
}
|
||||
|
||||
public void setLast(String last) {
|
||||
this.last = last;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
@DiscriminatorValue( "P" )
|
||||
public class PettingZoo extends Zoo {
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn( name = "reptile_id_fk" )
|
||||
public class Reptile extends Animal {
|
||||
private float bodyTemperature;
|
||||
public float getBodyTemperature() {
|
||||
return bodyTemperature;
|
||||
}
|
||||
public void setBodyTemperature(float bodyTemperature) {
|
||||
this.bodyTemperature = bodyTemperature;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class StateProvince {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String isoCode;
|
||||
|
||||
@Id
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIsoCode() {
|
||||
return isoCode;
|
||||
}
|
||||
|
||||
public void setIsoCode(String isoCode) {
|
||||
this.isoCode = isoCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( !( o instanceof StateProvince ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StateProvince that = ( StateProvince ) o;
|
||||
|
||||
if ( isoCode != null ? !isoCode.equals( that.getIsoCode() ) : that.getIsoCode() != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( name != null ? !name.equals( that.getName() ) : that.getName() != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + ( isoCode != null ? isoCode.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StateProvince{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", isoCode='" + isoCode + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* 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.testing.orm.domain.animal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
@Entity
|
||||
@Inheritance
|
||||
@DiscriminatorColumn( name = "zooType" )
|
||||
@DiscriminatorValue( "Z" )
|
||||
public class Zoo {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Classification classification;
|
||||
private Map directors = new HashMap();
|
||||
private Map animals = new HashMap();
|
||||
private Map mammals = new HashMap();
|
||||
private Address address;
|
||||
|
||||
public Zoo() {
|
||||
}
|
||||
|
||||
public Zoo(String name, Address address) {
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Id
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "t_directors",
|
||||
joinColumns = @JoinColumn( name = "zoo_fk" ),
|
||||
inverseJoinColumns = @JoinColumn( name = "director_fk" )
|
||||
)
|
||||
@MapKeyColumn( name = "`title`" )
|
||||
public Map<String,Human> getDirectors() {
|
||||
return directors;
|
||||
}
|
||||
|
||||
public void setDirectors(Map directors) {
|
||||
this.directors = directors;
|
||||
}
|
||||
|
||||
@OneToMany
|
||||
@JoinColumn( name = "mammal_fk" )
|
||||
@MapKeyColumn( name = "name" )
|
||||
public Map<String,Mammal> getMammals() {
|
||||
return mammals;
|
||||
}
|
||||
|
||||
public void setMammals(Map mammals) {
|
||||
this.mammals = mammals;
|
||||
}
|
||||
|
||||
@OneToMany( mappedBy = "zoo" )
|
||||
@MapKeyColumn( name = "serialNumber" )
|
||||
public Map<String, Animal> getAnimals() {
|
||||
return animals;
|
||||
}
|
||||
|
||||
public void setAnimals(Map animals) {
|
||||
this.animals = animals;
|
||||
}
|
||||
|
||||
@Embedded
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Enumerated( value = EnumType.STRING )
|
||||
public Classification getClassification() {
|
||||
return classification;
|
||||
}
|
||||
|
||||
public void setClassification(Classification classification) {
|
||||
this.classification = classification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( !( o instanceof Zoo ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Zoo zoo = ( Zoo ) o;
|
||||
|
||||
if ( address != null ? !address.equals( zoo.address ) : zoo.address != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( name != null ? !name.equals( zoo.name ) : zoo.name != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + ( address != null ? address.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Standard model for Hibernate's legacy Animal model used in HQL testing
|
||||
*/
|
||||
package org.hibernate.testing.orm.domain.animal;
|
Loading…
Reference in New Issue