Re-enabled additional tests
This commit is contained in:
parent
3ba826e1c8
commit
8c494a6f7f
|
@ -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.embedded.many2one;
|
||||
package org.hibernate.orm.test.annotations.embedded.many2one;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
|
@ -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.embedded.many2one;
|
||||
package org.hibernate.orm.test.annotations.embedded.many2one;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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.embedded.many2one;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Person.class, Country.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class EmbeddableWithMany2OneTest {
|
||||
|
||||
@Test
|
||||
public void testJoinAcrossEmbedded(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "from Person p join p.address as a join a.country as c where c.name = 'US'" )
|
||||
.list();
|
||||
session.createQuery( "from Person p join p.address as a join a.country as c where c.id = 'US'" )
|
||||
.list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicOps(SessionFactoryScope scope) {
|
||||
Person person = new Person( "Steve", new Address() );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Country country = new Country( "US", "United States of America" );
|
||||
session.persist( country );
|
||||
person.getAddress().setLine1( "123 Main" );
|
||||
person.getAddress().setCity( "Anywhere" );
|
||||
person.getAddress().setCountry( country );
|
||||
person.getAddress().setPostalCode( "123456789" );
|
||||
session.persist( person );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "from Person p where p.address.country.iso2 = 'US'" )
|
||||
.list();
|
||||
// same query!
|
||||
session.createQuery( "from Person p where p.address.country.id = 'US'" )
|
||||
.list();
|
||||
Person p = session.load( Person.class, person.getId() );
|
||||
session.delete( p );
|
||||
List countries = session.createQuery( "from Country" ).list();
|
||||
assertEquals( 1, countries.size() );
|
||||
session.delete( countries.get( 0 ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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.embedded.many2one;
|
||||
package org.hibernate.orm.test.annotations.embedded.many2one;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.annotations.embedded.one2many;
|
||||
package org.hibernate.orm.test.annotations.embedded.one2many;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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.embedded.one2many;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel(annotatedClasses = {
|
||||
// Alias.class, Person.class
|
||||
})
|
||||
@SessionFactory
|
||||
public class EmbeddableWithOne2ManyTest {
|
||||
|
||||
@Test
|
||||
@FailureExpected(jiraKey = "HHH-4883")
|
||||
public void testJoinAcrossEmbedded(SessionFactoryScope scope) {
|
||||
// NOTE : this may or may not work now with HHH-4883 fixed,
|
||||
// but i cannot do this checking until HHH-4599 is done.
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "from Person p join p.name.aliases a where a.source = 'FBI'" )
|
||||
.list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected(jiraKey = "HHH-4599")
|
||||
public void testBasicOps(SessionFactoryScope scope) {
|
||||
Person person = new Person( "John", "Dillinger" );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Alias alias = new Alias( "Public Enemy", "Number 1", "FBI" );
|
||||
session.persist( alias );
|
||||
person.getName().getAliases().add( alias );
|
||||
session.persist( person );
|
||||
}
|
||||
);
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person p = (Person) session.load( Person.class, person.getId() );
|
||||
session.delete( p );
|
||||
List aliases = session.createQuery( "from Alias" ).list();
|
||||
assertEquals( 0, aliases.size() );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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.embedded.one2many;
|
||||
package org.hibernate.orm.test.annotations.embedded.one2many;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
import org.hibernate.annotations.AccessType;
|
|
@ -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.embedded.one2many;
|
||||
package org.hibernate.orm.test.annotations.embedded.one2many;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.annotations.embedded.one2many;
|
||||
package org.hibernate.orm.test.annotations.embedded.one2many;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
|
@ -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.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.ElementCollection;
|
||||
|
@ -27,7 +27,7 @@ public class Classes {
|
|||
}
|
||||
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Book")
|
||||
@Table(name="Book")
|
||||
public static class Book {
|
||||
@Id
|
||||
|
@ -38,7 +38,7 @@ public class Classes {
|
|||
Edition<String> edition;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "PopularBook")
|
||||
@Table(name="PopularBook")
|
||||
public static class PopularBook {
|
||||
@Id
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Transient;
|
|
@ -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.orm.test.annotations.generics;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Classes.Book.class,
|
||||
Classes.PopularBook.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class EmbeddedGenericsTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Book" ).executeUpdate();
|
||||
session.createQuery( "delete from PopularBook" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorksWithGenericEmbedded(SessionFactoryScope scope) {
|
||||
Classes.Book b = new Classes.Book();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Classes.Edition<String> edition = new Classes.Edition<>();
|
||||
edition.name = "Second";
|
||||
b.edition = edition;
|
||||
session.persist( b );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Classes.Book retrieved = session.get( Classes.Book.class, b.id );
|
||||
assertEquals( "Second", retrieved.edition.name );
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorksWithGenericCollectionOfElements(SessionFactoryScope scope) {
|
||||
Classes.PopularBook b = new Classes.PopularBook();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Classes.Edition<String> edition = new Classes.Edition<>();
|
||||
edition.name = "Second";
|
||||
b.editions.add( edition );
|
||||
session.persist( b );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Classes.PopularBook retrieved = session.get( Classes.PopularBook.class, b.id );
|
||||
assertEquals( "Second", retrieved.editions.iterator().next().name );
|
||||
session.delete( retrieved );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
@ -21,7 +21,7 @@ public class Gene<T, STE extends Enum> {
|
|||
private Integer id;
|
||||
private STE state;
|
||||
|
||||
@Type(type="org.hibernate.test.annotations.generics.StateType")
|
||||
@Type(type="org.hibernate.orm.test.annotations.generics.StateType")
|
||||
public STE getState() {
|
||||
return state;
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* 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.generics;
|
||||
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.AbstractHANADialect;
|
||||
|
||||
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.hibernate.testing.orm.junit.SkipForDialect;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Paper.class,
|
||||
PaperType.class,
|
||||
SomeGuy.class,
|
||||
Price.class,
|
||||
WildEntity.class,
|
||||
|
||||
//test at deployment only test unbound property when default field access is used
|
||||
Dummy.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@ServiceRegistry(settings = @ServiceRegistry.Setting(name = Environment.AUTO_CLOSE_SESSION, value = "true"))
|
||||
public class GenericsTest {
|
||||
|
||||
@SkipForDialect(dialectClass = AbstractHANADialect.class, reason = "known bug in HANA: rs.next() returns false for org.hibernate.id.enhanced.SequenceStructure$1.getNextValue() for this test")
|
||||
@Test
|
||||
public void testManyToOneGenerics(SessionFactoryScope scope) {
|
||||
Paper white = new Paper();
|
||||
white.setName( "WhiteA4" );
|
||||
PaperType type = new PaperType();
|
||||
type.setName( "A4" );
|
||||
SomeGuy me = new SomeGuy();
|
||||
white.setType( type );
|
||||
white.setOwner( me );
|
||||
Price price = new Price();
|
||||
price.setAmount( new Double( 1 ) );
|
||||
price.setCurrency( "Euro" );
|
||||
white.setValue( price );
|
||||
|
||||
Session s = scope.getSessionFactory().openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
try {
|
||||
s.persist( type );
|
||||
s.persist( price );
|
||||
s.persist( me );
|
||||
s.persist( white );
|
||||
tx.commit();
|
||||
//s.close();
|
||||
|
||||
s = scope.getSessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
white = s.get( Paper.class, white.getId() );
|
||||
s.delete( white.getType() );
|
||||
s.delete( white.getOwner() );
|
||||
s.delete( white.getValue() );
|
||||
s.delete( white );
|
||||
tx.commit();
|
||||
//s.close();
|
||||
assertFalse( s.isOpen() );
|
||||
}
|
||||
finally {
|
||||
if ( tx.isActive() ) {
|
||||
tx.rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* @author Paolo Perrotta
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Gene.class,
|
||||
DNA.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class UnresolvedTypeTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from Gene" ).executeUpdate()
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptsUnresolvedPropertyTypesIfATargetEntityIsExplicitlySet(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Gene item = new Gene();
|
||||
session.persist( item );
|
||||
session.flush();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptsUnresolvedPropertyTypesIfATypeExplicitlySet(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Gene item = new Gene();
|
||||
item.setState( State.DORMANT );
|
||||
session.persist( item );
|
||||
session.flush();
|
||||
session.clear();
|
||||
item = (Gene) session.get( Gene.class, item.getId() );
|
||||
assertEquals( State.DORMANT, item.getState() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.generics;
|
||||
package org.hibernate.orm.test.annotations.generics;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance;
|
||||
package org.hibernate.orm.test.annotations.inheritance;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance;
|
||||
package org.hibernate.orm.test.annotations.inheritance;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance;
|
||||
package org.hibernate.orm.test.annotations.inheritance;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance;
|
||||
package org.hibernate.orm.test.annotations.inheritance;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance;
|
||||
package org.hibernate.orm.test.annotations.inheritance;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance;
|
||||
package org.hibernate.orm.test.annotations.inheritance;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Embeddable;
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* 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.inheritance.joined;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.test.annotations.inheritance.joined.Pool;
|
||||
import org.hibernate.test.annotations.inheritance.joined.PoolAddress;
|
||||
import org.hibernate.test.annotations.inheritance.joined.SwimmingPool;
|
||||
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.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Pool.class,
|
||||
org.hibernate.test.annotations.inheritance.joined.SwimmingPool.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class JoinedSubclassAndSecondaryTable {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
sesison ->
|
||||
sesison.createQuery( "from Pool" ).list().forEach(
|
||||
pool -> sesison.delete( pool )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondaryTableAndJoined(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
org.hibernate.test.annotations.inheritance.joined.SwimmingPool sp = new org.hibernate.test.annotations.inheritance.joined.SwimmingPool();
|
||||
session.persist( sp );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
// long rowCount = getTableRowCount( session, "POOL_ADDRESS" );
|
||||
// assertEquals(
|
||||
//
|
||||
// 0,
|
||||
// rowCount,
|
||||
// "The address table is marked as optional. For null values no database row should be created"
|
||||
// );
|
||||
|
||||
assertNumberOfRows(
|
||||
session,
|
||||
"POOL_ADDRESS",
|
||||
0,
|
||||
"The address table is marked as optional. For null values no database row should be created"
|
||||
);
|
||||
|
||||
org.hibernate.test.annotations.inheritance.joined.SwimmingPool sp2 = session.get( org.hibernate.test.annotations.inheritance.joined.SwimmingPool.class, sp.getId() );
|
||||
assertNull( sp.getAddress() );
|
||||
|
||||
org.hibernate.test.annotations.inheritance.joined.PoolAddress address = new org.hibernate.test.annotations.inheritance.joined.PoolAddress();
|
||||
address.setAddress( "Park Avenue" );
|
||||
sp2.setAddress( address );
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
sp2 = session.get( org.hibernate.test.annotations.inheritance.joined.SwimmingPool.class, sp.getId() );
|
||||
// rowCount = getTableRowCount( session, "POOL_ADDRESS" );
|
||||
// assertEquals(
|
||||
//
|
||||
// 1,
|
||||
// rowCount,
|
||||
// "Now we should have a row in the pool address table "
|
||||
//
|
||||
// );
|
||||
assertNumberOfRows(
|
||||
session,
|
||||
"POOL_ADDRESS",
|
||||
1,
|
||||
"Now we should have a row in the pool address table"
|
||||
);
|
||||
assertNotNull( sp2.getAddress() );
|
||||
assertEquals( "Park Avenue", sp2.getAddress().getAddress() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondaryTableAndJoinedInverse(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
org.hibernate.test.annotations.inheritance.joined.SwimmingPool sp = new org.hibernate.test.annotations.inheritance.joined.SwimmingPool();
|
||||
session.persist( sp );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
// long rowCount = getTableRowCount( session, "POOL_ADDRESS_2" );
|
||||
// assertEquals(
|
||||
// 0,
|
||||
// rowCount,
|
||||
// "The address table is marked as optional. For null values no database row should be created"
|
||||
// );
|
||||
assertNumberOfRows(
|
||||
session,
|
||||
"POOL_ADDRESS_2",
|
||||
0,
|
||||
"The address table is marked as optional. For null values no database row should be created"
|
||||
);
|
||||
|
||||
org.hibernate.test.annotations.inheritance.joined.SwimmingPool sp2 = session.get( org.hibernate.test.annotations.inheritance.joined.SwimmingPool.class, sp.getId() );
|
||||
assertNull( sp.getSecondaryAddress() );
|
||||
|
||||
org.hibernate.test.annotations.inheritance.joined.PoolAddress address = new PoolAddress();
|
||||
address.setAddress( "Park Avenue" );
|
||||
sp2.setSecondaryAddress( address );
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
sp2 = session.get( SwimmingPool.class, sp.getId() );
|
||||
// rowCount = getTableRowCount( session, "POOL_ADDRESS_2" );
|
||||
// assertEquals(
|
||||
//
|
||||
// 0,
|
||||
// rowCount,
|
||||
// "Now we should have a row in the pool address table "
|
||||
// );
|
||||
assertNumberOfRows( session,
|
||||
"POOL_ADDRESS_2",
|
||||
0,
|
||||
"Now we should not have a row in the pool address table " );
|
||||
assertNull( sp2.getSecondaryAddress() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void assertNumberOfRows(Session s, String tableName, int expectedNumberOfRows, String message) {
|
||||
s.doWork(
|
||||
work -> {
|
||||
PreparedStatement preparedStatement = work.prepareStatement( "select count(*) as row_count from " + tableName );
|
||||
preparedStatement.execute();
|
||||
ResultSet resultSet = preparedStatement.getResultSet();
|
||||
resultSet.next();
|
||||
long rowCount = resultSet.getLong( "row_count" );
|
||||
assertEquals(
|
||||
expectedNumberOfRows,
|
||||
rowCount,
|
||||
message
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private long getTableRowCount(Session s, String tableName) {
|
||||
// the type returned for count(*) in a native query depends on the dialect
|
||||
// Oracle returns Types.NUMERIC, which is mapped to BigDecimal;
|
||||
// H2 returns Types.BIGINT, which is mapped to BigInteger;
|
||||
Object retVal = s.createNativeQuery( "select count(*) from " + tableName ).uniqueResult();
|
||||
assertTrue( Number.class.isInstance( retVal ) );
|
||||
return ( (Number) retVal ).longValue();
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.interfaces;
|
||||
package org.hibernate.orm.test.annotations.interfaces;
|
||||
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.interfaces;
|
||||
package org.hibernate.orm.test.annotations.interfaces;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -4,23 +4,24 @@
|
|||
* 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.interfaces;
|
||||
package org.hibernate.orm.test.annotations.interfaces;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class InterfacesTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
ContactImpl.class, UserImpl.class
|
||||
}
|
||||
)
|
||||
public class InterfacesTest {
|
||||
@Test
|
||||
public void testInterface() {
|
||||
// test via SessionFactory building
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] { ContactImpl.class, UserImpl.class };
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.interfaces;
|
||||
package org.hibernate.orm.test.annotations.interfaces;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.interfaces;
|
||||
package org.hibernate.orm.test.annotations.interfaces;
|
||||
import java.util.Collection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -4,13 +4,14 @@
|
|||
* 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.override.inheritance;
|
||||
package org.hibernate.orm.test.annotations.override.inheritance;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
|
@ -19,19 +20,19 @@ import javax.persistence.UniqueConstraint;
|
|||
|
||||
import org.hibernate.cfg.AnnotationBinder;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-12609, HHH-12654, HHH-13172" )
|
||||
public class EntityInheritanceAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public class EntityInheritanceAttributeOverrideTest extends EntityManagerFactoryBasedFunctionalTest {
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||
|
@ -47,12 +48,13 @@ public class EntityInheritanceAttributeOverrideTest extends BaseEntityManagerFun
|
|||
}
|
||||
|
||||
@Override
|
||||
public void buildEntityManagerFactory() {
|
||||
public EntityManagerFactory produceEntityManagerFactory() {
|
||||
Triggerable warningLogged = logInspection.watchForLogMessages( "HHH000499:" );
|
||||
|
||||
super.buildEntityManagerFactory();
|
||||
EntityManagerFactory entityManagerFactory = super.produceEntityManagerFactory();
|
||||
|
||||
assertTrue("A warning should have been logged for this unsupported configuration", warningLogged.wasTriggered());
|
||||
return entityManagerFactory;
|
||||
}
|
||||
|
||||
@Test
|
|
@ -4,42 +4,40 @@
|
|||
* 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.override.inheritance;
|
||||
package org.hibernate.orm.test.annotations.override.inheritance;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
public class MappedSuperclassAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public class MappedSuperclassAttributeOverrideTest extends EntityManagerFactoryBasedFunctionalTest {
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
CategoryEntity.class,
|
||||
TaxonEntity.class
|
||||
return new Class[] {
|
||||
CategoryEntity.class,
|
||||
TaxonEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12609" )
|
||||
@TestForIssue(jiraKey = "HHH-12609")
|
||||
public void test() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
inTransaction( entityManager -> {
|
||||
TaxonEntity taxon1 = new TaxonEntity();
|
||||
taxon1.setId( 1L );
|
||||
taxon1.setCode( "Taxon" );
|
||||
|
@ -54,15 +52,16 @@ public class MappedSuperclassAttributeOverrideTest extends BaseEntityManagerFunc
|
|||
|
||||
entityManager.persist( taxon2 );
|
||||
} );
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
|
||||
inTransaction( entityManager -> {
|
||||
assertEquals(
|
||||
2,
|
||||
((Number) entityManager.createQuery(
|
||||
"select count(t) " +
|
||||
"from Taxon t " +
|
||||
"where t.code = :code" )
|
||||
.setParameter( "code", "Taxon" )
|
||||
.getSingleResult()).intValue()
|
||||
2,
|
||||
( (Number) entityManager.createQuery(
|
||||
"select count(t) " +
|
||||
"from Taxon t " +
|
||||
"where t.code = :code" )
|
||||
.setParameter( "code", "Taxon" )
|
||||
.getSingleResult() ).intValue()
|
||||
);
|
||||
} );
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.annotations.override.mappedsuperclass;
|
||||
package org.hibernate.orm.test.annotations.override.mappedsuperclass;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
|
@ -9,27 +9,25 @@ import javax.persistence.Id;
|
|||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Stanislav Gubanov
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-11771")
|
||||
public class MappedSuperClassBasicPropertyIdAttributeOverrideTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
MappedSuperClassBasicPropertyIdAttributeOverrideTest.BaseMappedSuperClass.class,
|
||||
MappedSuperClassBasicPropertyIdAttributeOverrideTest.ExtendBase.class
|
||||
}
|
||||
)
|
||||
public class MappedSuperClassBasicPropertyIdAttributeOverrideTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
BaseMappedSuperClass.class,
|
||||
ExtendBase.class
|
||||
};
|
||||
}
|
||||
|
||||
@MappedSuperclass
|
||||
@Access(AccessType.FIELD)
|
||||
public static class BaseMappedSuperClass {
|
|
@ -0,0 +1,44 @@
|
|||
package org.hibernate.orm.test.annotations.override.mappedsuperclass;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
|
||||
/**
|
||||
* @author Stanislav Gubanov
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-11771")
|
||||
public class MappedSuperClassIdPropertyBasicAttributeOverrideTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
try {
|
||||
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
StandardServiceRegistry ssr = ssrb.build();
|
||||
|
||||
MetadataSources metadataSources = new MetadataSources( ssr );
|
||||
metadataSources.addAnnotatedClasses( MappedSuperClassWithUuidAsBasic.class );
|
||||
metadataSources.addAnnotatedClasses( SubclassWithUuidAsId.class );
|
||||
|
||||
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
|
||||
metadata.buildSessionFactory();
|
||||
fail( "Should throw exception!" );
|
||||
}
|
||||
catch (MappingException expected) {
|
||||
assertEquals(
|
||||
"You cannot override the [uid] non-identifier property from the [org.hibernate.orm.test.annotations.override.mappedsuperclass.MappedSuperClassWithUuidAsBasic] base class or @MappedSuperclass and make it an identifier in the [org.hibernate.orm.test.annotations.override.mappedsuperclass.SubclassWithUuidAsId] subclass!",
|
||||
expected.getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.annotations.override.mappedsuperclass;
|
||||
package org.hibernate.orm.test.annotations.override.mappedsuperclass;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.annotations.override.mappedsuperclass;
|
||||
package org.hibernate.orm.test.annotations.override.mappedsuperclass;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.tableperclass;
|
||||
package org.hibernate.orm.test.annotations.tableperclass;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
@ -25,13 +26,10 @@ public abstract class Component {
|
|||
private Long manufacturerId;
|
||||
private Long id;
|
||||
|
||||
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@Id
|
||||
public Long getId() {
|
||||
return id;
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.tableperclass;
|
||||
package org.hibernate.orm.test.annotations.tableperclass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.tableperclass;
|
||||
package org.hibernate.orm.test.annotations.tableperclass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.tableperclass;
|
||||
package org.hibernate.orm.test.annotations.tableperclass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.tableperclass;
|
||||
package org.hibernate.orm.test.annotations.tableperclass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* 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.tableperclass;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Robot.class,
|
||||
T800.class,
|
||||
Machine.class,
|
||||
Component.class,
|
||||
Product.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class TablePerClassTest {
|
||||
|
||||
@Test
|
||||
public void testUnionSubClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Machine computer = new Machine();
|
||||
computer.setWeight( new Double( 4 ) );
|
||||
Robot asimov = new Robot();
|
||||
asimov.setWeight( new Double( 120 ) );
|
||||
asimov.setName( "Asimov" );
|
||||
T800 terminator = new T800();
|
||||
terminator.setName( "Terminator" );
|
||||
terminator.setWeight( new Double( 300 ) );
|
||||
terminator.setTargetName( "Sarah Connor" );
|
||||
session.persist( computer );
|
||||
session.persist( asimov );
|
||||
session.persist( terminator );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Query q = session.createQuery( "from Machine m where m.weight >= :weight" );
|
||||
q.setParameter( "weight", new Double( 10 ) );
|
||||
List result = q.list();
|
||||
assertEquals( 2, result.size() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstraintsOnSuperclassProperties(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Product product1 = new Product();
|
||||
product1.setId( 1l );
|
||||
product1.setManufacturerId( 1l );
|
||||
product1.setManufacturerPartNumber( "AAFR" );
|
||||
session.persist( product1 );
|
||||
session.flush();
|
||||
Product product2 = new Product();
|
||||
product2.setId( 2l );
|
||||
product2.setManufacturerId( 1l );
|
||||
product2.setManufacturerPartNumber( "AAFR" );
|
||||
session.persist( product2 );
|
||||
try {
|
||||
session.flush();
|
||||
fail( "Database Exception not handled" );
|
||||
}
|
||||
catch (PersistenceException e) {
|
||||
assertTyping( JDBCException.class, e.getCause() );
|
||||
//success
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static <T> T assertTyping(Class<T> expectedType, Object value) {
|
||||
if ( !expectedType.isInstance( value ) ) {
|
||||
fail(
|
||||
String.format(
|
||||
"Expecting value of type [%s], but found [%s]",
|
||||
expectedType.getName(),
|
||||
value == null ? "<null>" : value
|
||||
)
|
||||
);
|
||||
}
|
||||
return (T) value;
|
||||
}
|
||||
}
|
|
@ -10,10 +10,10 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.test.annotations.inheritance.Carrot;
|
||||
import org.hibernate.test.annotations.inheritance.Tomato;
|
||||
import org.hibernate.test.annotations.inheritance.Vegetable;
|
||||
import org.hibernate.test.annotations.inheritance.VegetablePk;
|
||||
import org.hibernate.orm.test.annotations.inheritance.Carrot;
|
||||
import org.hibernate.orm.test.annotations.inheritance.Tomato;
|
||||
import org.hibernate.orm.test.annotations.inheritance.Vegetable;
|
||||
import org.hibernate.orm.test.annotations.inheritance.VegetablePk;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
|
@ -1,70 +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.embedded.many2one;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class EmbeddableWithMany2OneTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Person.class, Country.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinAcrossEmbedded() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
session.createQuery( "from Person p join p.address as a join a.country as c where c.name = 'US'" )
|
||||
.list();
|
||||
session.createQuery( "from Person p join p.address as a join a.country as c where c.id = 'US'" )
|
||||
.list();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicOps() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
Country country = new Country( "US", "United States of America" );
|
||||
session.persist( country );
|
||||
Person person = new Person( "Steve", new Address() );
|
||||
person.getAddress().setLine1( "123 Main" );
|
||||
person.getAddress().setCity( "Anywhere" );
|
||||
person.getAddress().setCountry( country );
|
||||
person.getAddress().setPostalCode( "123456789" );
|
||||
session.persist( person );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
session.createQuery( "from Person p where p.address.country.iso2 = 'US'" )
|
||||
.list();
|
||||
// same query!
|
||||
session.createQuery( "from Person p where p.address.country.id = 'US'" )
|
||||
.list();
|
||||
person = (Person) session.load( Person.class, person.getId() );
|
||||
session.delete( person );
|
||||
List countries = session.createQuery( "from Country" ).list();
|
||||
assertEquals( 1, countries.size() );
|
||||
session.delete( countries.get( 0 ) );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
}
|
|
@ -1,64 +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.embedded.one2many;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class EmbeddableWithOne2ManyTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
// return new Class[] { Alias.class, Person.class };
|
||||
return new Class[] { };
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-4883")
|
||||
public void testJoinAcrossEmbedded() {
|
||||
// NOTE : this may or may not work now with HHH-4883 fixed,
|
||||
// but i cannot do this checking until HHH-4599 is done.
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
session.createQuery( "from Person p join p.name.aliases a where a.source = 'FBI'" )
|
||||
.list();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-4599")
|
||||
public void testBasicOps() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
Alias alias = new Alias( "Public Enemy", "Number 1", "FBI" );
|
||||
session.persist( alias );
|
||||
Person person = new Person( "John", "Dillinger" );
|
||||
person.getName().getAliases().add( alias );
|
||||
session.persist( person );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
person = (Person) session.load( Person.class, person.getId() );
|
||||
session.delete( person );
|
||||
List aliases = session.createQuery( "from Alias" ).list();
|
||||
assertEquals( 0, aliases.size() );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.annotations.generics;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EmbeddedGenericsTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testWorksWithGenericEmbedded() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
Classes.Edition<String> edition = new Classes.Edition<String>();
|
||||
edition.name = "Second";
|
||||
Classes.Book b = new Classes.Book();
|
||||
b.edition = edition;
|
||||
session.persist( b );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
Classes.Book retrieved = (Classes.Book) session.get( Classes.Book.class, b.id );
|
||||
assertEquals( "Second", retrieved.edition.name );
|
||||
session.delete( retrieved );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
public void testWorksWithGenericCollectionOfElements() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
Classes.Edition<String> edition = new Classes.Edition<String>();
|
||||
edition.name = "Second";
|
||||
Classes.PopularBook b = new Classes.PopularBook();
|
||||
b.editions.add( edition );
|
||||
session.persist( b );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
Classes.PopularBook retrieved = (Classes.PopularBook) session.get( Classes.PopularBook.class, b.id );
|
||||
assertEquals( "Second", retrieved.editions.iterator().next().name );
|
||||
session.delete( retrieved );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Classes.Book.class,
|
||||
Classes.PopularBook.class
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,76 +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.generics;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.AbstractHANADialect;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class GenericsTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@SkipForDialect(value = AbstractHANADialect.class, comment = "known bug in HANA: rs.next() returns false for org.hibernate.id.enhanced.SequenceStructure$1.getNextValue() for this test")
|
||||
@Test
|
||||
public void testManyToOneGenerics() throws Exception {
|
||||
Paper white = new Paper();
|
||||
white.setName( "WhiteA4" );
|
||||
PaperType type = new PaperType();
|
||||
type.setName( "A4" );
|
||||
SomeGuy me = new SomeGuy();
|
||||
white.setType( type );
|
||||
white.setOwner( me );
|
||||
Price price = new Price();
|
||||
price.setAmount( new Double( 1 ) );
|
||||
price.setCurrency( "Euro" );
|
||||
white.setValue( price );
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
s.persist( type );
|
||||
s.persist( price );
|
||||
s.persist( me );
|
||||
s.persist( white );
|
||||
tx.commit();
|
||||
//s.close();
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
white = (Paper) s.get( Paper.class, white.getId() );
|
||||
s.delete( white.getType() );
|
||||
s.delete( white.getOwner() );
|
||||
s.delete( white.getValue() );
|
||||
s.delete( white );
|
||||
tx.commit();
|
||||
//s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
||||
super.configure( cfg );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Paper.class,
|
||||
PaperType.class,
|
||||
SomeGuy.class,
|
||||
Price.class,
|
||||
WildEntity.class,
|
||||
|
||||
//test at deployment only test unbound property when default field access is used
|
||||
Dummy.class
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,54 +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.generics;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Paolo Perrotta
|
||||
*/
|
||||
public class UnresolvedTypeTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testAcceptsUnresolvedPropertyTypesIfATargetEntityIsExplicitlySet() {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Gene item = new Gene();
|
||||
s.persist( item );
|
||||
s.flush();
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptsUnresolvedPropertyTypesIfATypeExplicitlySet() {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Gene item = new Gene();
|
||||
item.setState( State.DORMANT );
|
||||
s.persist( item );
|
||||
s.flush();
|
||||
s.clear();
|
||||
item = (Gene) s.get( Gene.class, item.getId() );
|
||||
assertEquals( State.DORMANT, item.getState() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Gene.class,
|
||||
DNA.class
|
||||
};
|
||||
}
|
||||
}
|
|
@ -7,42 +7,53 @@
|
|||
package org.hibernate.test.annotations.inheritance;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.test.annotations.A320;
|
||||
import org.hibernate.test.annotations.A320b;
|
||||
import org.hibernate.test.annotations.Plane;
|
||||
import org.hibernate.orm.test.annotations.inheritance.Apple;
|
||||
import org.hibernate.orm.test.annotations.inheritance.singletable.Funk;
|
||||
import org.hibernate.orm.test.annotations.inheritance.singletable.Music;
|
||||
import org.hibernate.orm.test.annotations.inheritance.singletable.Noise;
|
||||
import org.hibernate.orm.test.annotations.inheritance.singletable.Rock;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.test.annotations.A320;
|
||||
import org.hibernate.test.annotations.A320b;
|
||||
import org.hibernate.test.annotations.Plane;
|
||||
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.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class SubclassTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected boolean isCleanupTestDataRequired() {
|
||||
return true;
|
||||
}
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
A320b.class, //subclasses should be properly reordered
|
||||
Plane.class,
|
||||
A320.class,
|
||||
Apple.class,
|
||||
Music.class,
|
||||
Rock.class,
|
||||
Funk.class,
|
||||
Noise.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class SubclassTest {
|
||||
|
||||
@Test
|
||||
public void testPolymorphism() {
|
||||
inTransaction(
|
||||
public void testPolymorphism(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
Plane p = new Plane();
|
||||
p.setNbrOfSeats( 10 );
|
||||
|
@ -54,7 +65,7 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
Query q = s.createQuery( "from " + A320.class.getName() );
|
||||
List a320s = q.list();
|
||||
|
@ -71,8 +82,8 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test2ndLevelSubClass() {
|
||||
inTransaction(
|
||||
public void test2ndLevelSubClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
A320b a = new A320b();
|
||||
a.setJavaEmbeddedVersion( "Elephant" );
|
||||
|
@ -81,7 +92,7 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
Query q = s.createQuery( "from " + A320.class.getName() + " as a where a.javaEmbeddedVersion = :version" );
|
||||
q.setParameter( "version", "Elephant" );
|
||||
|
@ -94,9 +105,9 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedSuperclass() {
|
||||
public void testEmbeddedSuperclass(SessionFactoryScope scope) {
|
||||
Plane plane = new Plane();
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
plane.setAlive( true ); //sic
|
||||
plane.setAltitude( 10000 );
|
||||
|
@ -107,7 +118,7 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
Plane p = s.get( Plane.class, plane.getId() );
|
||||
assertNotNull( p );
|
||||
|
@ -123,8 +134,8 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFormula() {
|
||||
inTransaction(
|
||||
public void testFormula(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
Rock guns = new Rock();
|
||||
guns.setAvgBeat( 90 );
|
||||
|
@ -138,7 +149,7 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
List result = createQueryForClass( s, Noise.class ).list();
|
||||
assertNotNull( result );
|
||||
|
@ -162,21 +173,21 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
return session.createQuery( criteria );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
A320b.class, //subclasses should be properly reordered
|
||||
Plane.class,
|
||||
A320.class,
|
||||
Fruit.class,
|
||||
//FlyingObject.class, //had to declare embedded superclasses
|
||||
//Thing.class,
|
||||
Apple.class,
|
||||
Music.class,
|
||||
Rock.class,
|
||||
Funk.class,
|
||||
Noise.class
|
||||
};
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from A320b" ).executeUpdate();
|
||||
session.createQuery( "delete from Plane" ).executeUpdate();
|
||||
session.createQuery( "delete from A320" ).executeUpdate();
|
||||
|
||||
session.createQuery( "delete from Noise" ).executeUpdate();
|
||||
session.createQuery( "delete from Rock" ).executeUpdate();
|
||||
session.createQuery( "delete from Apple" ).executeUpdate();
|
||||
session.createQuery( "delete from Music" ).executeUpdate();
|
||||
session.createQuery( "delete from Funk" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
0
hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/joined/Document.java
Executable file → Normal file
0
hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/joined/Document.java
Executable file → Normal file
0
hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/joined/File.java
Executable file → Normal file
0
hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/joined/File.java
Executable file → Normal file
0
hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/joined/Folder.java
Executable file → Normal file
0
hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/joined/Folder.java
Executable file → Normal file
|
@ -1,134 +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.inheritance.joined;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Pool.class,
|
||||
SwimmingPool.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class JoinedSubclassAndSecondaryTable {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
sesison ->
|
||||
sesison.createQuery( "from Pool" ).list().forEach(
|
||||
pool -> sesison.delete( pool )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondaryTableAndJoined(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
SwimmingPool sp = new SwimmingPool();
|
||||
session.persist( sp );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
long rowCount = getTableRowCount( session, "POOL_ADDRESS" );
|
||||
assertEquals(
|
||||
|
||||
0,
|
||||
rowCount,
|
||||
"The address table is marked as optional. For null values no database row should be created"
|
||||
);
|
||||
|
||||
SwimmingPool sp2 = session.get( SwimmingPool.class, sp.getId() );
|
||||
assertNull( sp.getAddress() );
|
||||
|
||||
PoolAddress address = new PoolAddress();
|
||||
address.setAddress( "Park Avenue" );
|
||||
sp2.setAddress( address );
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
sp2 = session.get( SwimmingPool.class, sp.getId() );
|
||||
rowCount = getTableRowCount( session, "POOL_ADDRESS" );
|
||||
assertEquals(
|
||||
|
||||
1,
|
||||
rowCount,
|
||||
"Now we should have a row in the pool address table "
|
||||
|
||||
);
|
||||
assertNotNull( sp2.getAddress() );
|
||||
assertEquals( sp2.getAddress().getAddress(), "Park Avenue" );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondaryTableAndJoinedInverse(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
SwimmingPool sp = new SwimmingPool();
|
||||
session.persist( sp );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
long rowCount = getTableRowCount( session, "POOL_ADDRESS_2" );
|
||||
assertEquals(
|
||||
0,
|
||||
rowCount,
|
||||
"The address table is marked as optional. For null values no database row should be created"
|
||||
);
|
||||
|
||||
SwimmingPool sp2 = session.get( SwimmingPool.class, sp.getId() );
|
||||
assertNull( sp.getSecondaryAddress() );
|
||||
|
||||
PoolAddress address = new PoolAddress();
|
||||
address.setAddress( "Park Avenue" );
|
||||
sp2.setSecondaryAddress( address );
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
sp2 = session.get( SwimmingPool.class, sp.getId() );
|
||||
rowCount = getTableRowCount( session, "POOL_ADDRESS_2" );
|
||||
assertEquals(
|
||||
|
||||
0,
|
||||
rowCount,
|
||||
"Now we should have a row in the pool address table "
|
||||
);
|
||||
assertNull( sp2.getSecondaryAddress() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private long getTableRowCount(Session s, String tableName) {
|
||||
// the type returned for count(*) in a native query depends on the dialect
|
||||
// Oracle returns Types.NUMERIC, which is mapped to BigDecimal;
|
||||
// H2 returns Types.BIGINT, which is mapped to BigInteger;
|
||||
Object retVal = s.createNativeQuery( "select count(*) from " + tableName ).uniqueResult();
|
||||
assertTrue( Number.class.isInstance( retVal ) );
|
||||
return ( (Number) retVal ).longValue();
|
||||
}
|
||||
}
|
0
hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/joined/SymbolicLink.java
Executable file → Normal file
0
hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/joined/SymbolicLink.java
Executable file → Normal file
|
@ -1,44 +0,0 @@
|
|||
package org.hibernate.test.annotations.override.mappedsuperclass;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Stanislav Gubanov
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-11771")
|
||||
public class MappedSuperClassIdPropertyBasicAttributeOverrideTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
MappedSuperClassWithUuidAsBasic.class,
|
||||
SubclassWithUuidAsId.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildResources() {
|
||||
try {
|
||||
super.buildResources();
|
||||
fail( "Should throw exception!" );
|
||||
}
|
||||
catch (MappingException expected) {
|
||||
assertEquals(
|
||||
"You cannot override the [uid] non-identifier property from the [org.hibernate.test.annotations.override.mappedsuperclass.MappedSuperClassWithUuidAsBasic] base class or @MappedSuperclass and make it an identifier in the [org.hibernate.test.annotations.override.mappedsuperclass.SubclassWithUuidAsId] subclass!",
|
||||
expected.getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,101 +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.tableperclass;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class TablePerClassTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testUnionSubClass() throws Exception {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Machine computer = new Machine();
|
||||
computer.setWeight( new Double( 4 ) );
|
||||
Robot asimov = new Robot();
|
||||
asimov.setWeight( new Double( 120 ) );
|
||||
asimov.setName( "Asimov" );
|
||||
T800 terminator = new T800();
|
||||
terminator.setName( "Terminator" );
|
||||
terminator.setWeight( new Double( 300 ) );
|
||||
terminator.setTargetName( "Sarah Connor" );
|
||||
s.persist( computer );
|
||||
s.persist( asimov );
|
||||
s.persist( terminator );
|
||||
tx.commit();
|
||||
s.close();
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
Query q = s.createQuery( "from Machine m where m.weight >= :weight" );
|
||||
q.setParameter( "weight", new Double( 10 ) );
|
||||
List result = q.list();
|
||||
assertEquals( 2, result.size() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstraintsOnSuperclassProperties() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Product product1 = new Product();
|
||||
product1.setId( 1l );
|
||||
product1.setManufacturerId( 1l );
|
||||
product1.setManufacturerPartNumber( "AAFR");
|
||||
s.persist( product1 );
|
||||
s.flush();
|
||||
Product product2 = new Product();
|
||||
product2.setId( 2l );
|
||||
product2.setManufacturerId( 1l );
|
||||
product2.setManufacturerPartNumber( "AAFR");
|
||||
s.persist( product2 );
|
||||
try {
|
||||
s.flush();
|
||||
fail( "Database Exception not handled" );
|
||||
}
|
||||
catch (PersistenceException e) {
|
||||
assertTyping( JDBCException.class, e.getCause() );
|
||||
//success
|
||||
}
|
||||
finally {
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Robot.class,
|
||||
T800.class,
|
||||
Machine.class,
|
||||
Component.class,
|
||||
Product.class
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue