Re-enabled additional tests
This commit is contained in:
parent
01b24089c2
commit
b06be7ff6d
|
@ -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.genericsinheritance;
|
||||
package org.hibernate.orm.test.annotations.genericsinheritance;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MappedSuperclass;
|
|
@ -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.genericsinheritance;
|
||||
package org.hibernate.orm.test.annotations.genericsinheritance;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
|
@ -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.genericsinheritance;
|
||||
package org.hibernate.orm.test.annotations.genericsinheritance;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
|
@ -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.genericsinheritance;
|
||||
package org.hibernate.orm.test.annotations.genericsinheritance;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.genericsinheritance;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(annotatedClasses = {
|
||||
ChildHierarchy1.class,
|
||||
ParentHierarchy1.class,
|
||||
ChildHierarchy22.class,
|
||||
ParentHierarchy22.class
|
||||
})
|
||||
@SessionFactory
|
||||
public class GenericsInheritanceTest {
|
||||
@Test
|
||||
public void testMapping(SessionFactoryScope scope) {
|
||||
scope.inSession( sessionImplementor -> {
|
||||
//mapping is tested
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
|
@ -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.genericsinheritance;
|
||||
package org.hibernate.orm.test.annotations.genericsinheritance;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -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.genericsinheritance;
|
||||
package org.hibernate.orm.test.annotations.genericsinheritance;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
|
@ -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.genericsinheritance;
|
||||
package org.hibernate.orm.test.annotations.genericsinheritance;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
|
@ -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.genericsinheritance;
|
||||
package org.hibernate.orm.test.annotations.genericsinheritance;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
// $Id$
|
||||
package org.hibernate.test.annotations.inheritance.discriminatoroptions;
|
||||
package org.hibernate.orm.test.annotations.inheritance.discriminatoroptions;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -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.inheritance.discriminatoroptions;
|
||||
package org.hibernate.orm.test.annotations.inheritance.discriminatoroptions;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
|
@ -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.inheritance.discriminatoroptions;
|
||||
package org.hibernate.orm.test.annotations.inheritance.discriminatoroptions;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
|
@ -13,21 +13,21 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.RootClass;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.junit5.BaseUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Test for the @DiscriminatorOptions annotations.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class DiscriminatorOptionsTest extends BaseUnitTestCase {
|
||||
public class DiscriminatorOptionsTest extends BaseUnitTest {
|
||||
@Test
|
||||
public void testNonDefaultOptions() throws Exception {
|
||||
public void testNonDefaultOptions() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
|
||||
try {
|
||||
|
@ -41,7 +41,7 @@ public class DiscriminatorOptionsTest extends BaseUnitTestCase {
|
|||
assertTrue( persistentClass instanceof RootClass );
|
||||
|
||||
RootClass root = (RootClass) persistentClass;
|
||||
assertTrue( "Discriminator should be forced", root.isForceDiscriminator() );
|
||||
assertTrue( root.isForceDiscriminator(), "Discriminator should be forced" );
|
||||
assertFalse( "Discriminator should not be insertable", root.isDiscriminatorInsertable() );
|
||||
}
|
||||
finally {
|
||||
|
@ -50,7 +50,7 @@ public class DiscriminatorOptionsTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBaseline() throws Exception {
|
||||
public void testBaseline() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
|
||||
try {
|
||||
|
@ -63,7 +63,7 @@ public class DiscriminatorOptionsTest extends BaseUnitTestCase {
|
|||
assertNotNull( persistentClass );
|
||||
assertTrue( persistentClass instanceof RootClass );
|
||||
|
||||
RootClass root = ( RootClass ) persistentClass;
|
||||
RootClass root = (RootClass) persistentClass;
|
||||
assertFalse( "Discriminator should not be forced by default", root.isForceDiscriminator() );
|
||||
}
|
||||
finally {
|
||||
|
@ -72,7 +72,7 @@ public class DiscriminatorOptionsTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyBasedDiscriminatorForcing() throws Exception {
|
||||
public void testPropertyBasedDiscriminatorForcing() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
|
||||
try {
|
||||
|
@ -87,8 +87,8 @@ public class DiscriminatorOptionsTest extends BaseUnitTestCase {
|
|||
assertNotNull( persistentClass );
|
||||
assertTrue( persistentClass instanceof RootClass );
|
||||
|
||||
RootClass root = ( RootClass ) persistentClass;
|
||||
assertTrue( "Discriminator should be forced by property", root.isForceDiscriminator() );
|
||||
RootClass root = (RootClass) persistentClass;
|
||||
assertTrue( root.isForceDiscriminator(), "Discriminator should be forced by property" );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
// $Id$
|
||||
package org.hibernate.test.annotations.inheritance.discriminatoroptions;
|
||||
package org.hibernate.orm.test.annotations.inheritance.discriminatoroptions;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
|
@ -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.inheritance.discriminatoroptions;
|
||||
package org.hibernate.orm.test.annotations.inheritance.discriminatoroptions;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
|
@ -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.inheritance.joined;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "`ACCOUNT`")
|
||||
public class Account implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@Column(name="fld_number")
|
||||
private String number;
|
||||
|
||||
@OneToMany(mappedBy="account")
|
||||
private Set<Client> clients;
|
||||
|
||||
private double balance;
|
||||
|
||||
public Account() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return this.number;
|
||||
}
|
||||
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void setBalance(double balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public void addClient(Client c) {
|
||||
if (clients == null) {
|
||||
clients = new HashSet<Client>();
|
||||
}
|
||||
clients.add(c);
|
||||
c.setAccount(this);
|
||||
}
|
||||
|
||||
|
||||
public Set<Client> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
public void setClients(Set<Client> clients) {
|
||||
this.clients = clients;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
@DiscriminatorValue("AlarmT")
|
||||
public class Alarm extends EventInformation {
|
||||
|
||||
protected EventInformation eventInfo;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumns({@JoinColumn(name = "EVENTINFO_NOTIFICATIONID",
|
||||
referencedColumnName = "NOTIFICATIONID")})
|
||||
public EventInformation getEventInfo() {
|
||||
return eventInfo;
|
||||
}
|
||||
|
||||
public void setEventInfo(EventInformation value) {
|
||||
this.eventInfo = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String eventId = ( getEventInfo() != null ?
|
||||
getEventInfo().getNotificationId() : null );
|
||||
sb.append(
|
||||
"AlarmT: id = " + getNotificationId() + "\t" +
|
||||
"has event id = " + eventId
|
||||
);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@Table(name = "TBLASSET")
|
||||
public class Asset {
|
||||
private Integer id;
|
||||
|
||||
private Parent parent = null;
|
||||
|
||||
@Id @GeneratedValue public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@ManyToOne(targetEntity = Parent.class)
|
||||
@JoinColumn(name = "PARENTID")
|
||||
public Parent getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Parent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "CLIENT")
|
||||
public class Client extends Person implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String street;
|
||||
|
||||
private String code;
|
||||
|
||||
private String city;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "CLIENT_ACCOUNT",
|
||||
joinColumns = {@JoinColumn(name = "FK_CLIENT", referencedColumnName = "ID")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "FK_ACCOUNT", referencedColumnName = "ID")})
|
||||
private Account account;
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public Client() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
public abstract class Clothing {
|
||||
private long id;
|
||||
private int size;
|
||||
private String color;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "cloth_size")
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.SecondaryTable;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author Sharath Reddy
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "Company")
|
||||
@SecondaryTable(name = "CompanyAddress")
|
||||
public class Company extends Customer {
|
||||
|
||||
private String companyName;
|
||||
private String companyAddress;
|
||||
|
||||
@Column
|
||||
public String getCompanyName() {
|
||||
return companyName;
|
||||
}
|
||||
|
||||
public void setCompanyName(String companyName) {
|
||||
this.companyName = companyName;
|
||||
}
|
||||
|
||||
@Column(table = "CompanyAddress")
|
||||
public String getCompanyAddress() {
|
||||
return companyAddress;
|
||||
}
|
||||
|
||||
public void setCompanyAddress(String companyAddress) {
|
||||
this.companyAddress = companyAddress;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.SecondaryTable;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author Sharath Reddy
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@Table(name = "Customer")
|
||||
@SecondaryTable(name = "CustomerDetails")
|
||||
public class Customer extends LegalEntity {
|
||||
|
||||
public String customerName;
|
||||
public String customerCode;
|
||||
|
||||
@Column
|
||||
public String getCustomerName() {
|
||||
return customerName;
|
||||
}
|
||||
|
||||
public void setCustomerName(String val) {
|
||||
this.customerName = val;
|
||||
}
|
||||
|
||||
@Column(table="CustomerDetails")
|
||||
public String getCustomerCode() {
|
||||
return customerCode;
|
||||
}
|
||||
|
||||
public void setCustomerCode(String val) {
|
||||
this.customerCode = val;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
import org.hibernate.annotations.ForeignKey;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
@ForeignKey(name = "FK_DOCU_FILE")
|
||||
public class Document extends File {
|
||||
@Column(nullable = false, name="xsize")
|
||||
private int size;
|
||||
|
||||
Document() {
|
||||
}
|
||||
|
||||
Document(String name, int size) {
|
||||
super( name );
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
|
||||
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING, length = 80)
|
||||
@DiscriminatorValue("EventInformationT")
|
||||
public class EventInformation implements java.io.Serializable {
|
||||
|
||||
|
||||
protected String notificationId;
|
||||
|
||||
@Id
|
||||
public String getNotificationId() {
|
||||
return notificationId;
|
||||
}
|
||||
|
||||
public void setNotificationId(String value) {
|
||||
this.notificationId = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append( "EventInformationT: id = " + getNotificationId() );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@Table(name="joined_file")
|
||||
public abstract class File {
|
||||
@Id @Column(name="filename")
|
||||
private String name;
|
||||
@ManyToOne
|
||||
private Folder parent;
|
||||
|
||||
File() {
|
||||
}
|
||||
|
||||
public File(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String id) {
|
||||
this.name = id;
|
||||
}
|
||||
|
||||
public Folder getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Folder parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class FinancialAsset extends Asset {
|
||||
private double price;
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class Folder extends File {
|
||||
@OneToMany(mappedBy = "parent")
|
||||
private Set<File> children = new HashSet<File>();
|
||||
|
||||
Folder() {
|
||||
}
|
||||
|
||||
public Folder(String name) {
|
||||
super( name );
|
||||
}
|
||||
|
||||
public Set<File> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(Set children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* 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.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
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.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
File.class,
|
||||
Folder.class,
|
||||
Document.class,
|
||||
SymbolicLink.class,
|
||||
ProgramExecution.class,
|
||||
Clothing.class,
|
||||
Sweater.class,
|
||||
EventInformation.class,
|
||||
Alarm.class,
|
||||
Client.class,
|
||||
Account.class,
|
||||
Company.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class JoinedSubclassTest {
|
||||
|
||||
@Test
|
||||
public void testDefault(SessionFactoryScope scope) {
|
||||
File doc = new Document( "Enron Stuff To Shred", 1000 );
|
||||
Folder folder = new Folder( "Enron" );
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
s.persist( doc );
|
||||
s.persist( folder );
|
||||
}
|
||||
);
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<File> criteria = criteriaBuilder.createQuery( File.class );
|
||||
criteria.from( File.class );
|
||||
List<File> result = s.createQuery( criteria ).list();
|
||||
// List result = s.createCriteria( File.class ).list();
|
||||
assertNotNull( result );
|
||||
assertEquals( 2, result.size() );
|
||||
File f2 = result.get( 0 );
|
||||
checkClassType( f2, doc, folder );
|
||||
f2 = result.get( 1 );
|
||||
checkClassType( f2, doc, folder );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManyToOneOnAbstract(SessionFactoryScope scope) {
|
||||
Folder f = new Folder();
|
||||
f.setName( "data" );
|
||||
ProgramExecution remove = new ProgramExecution();
|
||||
remove.setAction( "remove" );
|
||||
remove.setAppliesOn( f );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( f );
|
||||
session.persist( remove );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
ProgramExecution programExecution = session.get( ProgramExecution.class, remove.getId() );
|
||||
assertNotNull( programExecution );
|
||||
assertNotNull( programExecution.getAppliesOn().getName() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinedAbstractClass(SessionFactoryScope scope) {
|
||||
Sweater sw = new Sweater();
|
||||
sw.setColor( "Black" );
|
||||
sw.setSize( 2 );
|
||||
sw.setSweat( true );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> session.persist( sw )
|
||||
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Sweater toDelete = session.get( Sweater.class, sw.getId() );
|
||||
session.delete( toDelete );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInheritance(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
String eventPK = "event1";
|
||||
EventInformation event = session.get( EventInformation.class, eventPK );
|
||||
if ( event == null ) {
|
||||
event = new EventInformation();
|
||||
event.setNotificationId( eventPK );
|
||||
session.persist( event );
|
||||
}
|
||||
String alarmPK = "alarm1";
|
||||
Alarm alarm = session.get( Alarm.class, alarmPK );
|
||||
if ( alarm == null ) {
|
||||
alarm = new Alarm();
|
||||
alarm.setNotificationId( alarmPK );
|
||||
alarm.setEventInfo( event );
|
||||
session.persist( alarm );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-4250")
|
||||
public void testManyToOneWithJoinTable(SessionFactoryScope scope) {
|
||||
//HHH-4250 : @ManyToOne - @OneToMany doesn't work with @Inheritance(strategy= InheritanceType.JOINED)
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Client c1 = new Client();
|
||||
c1.setFirstname( "Firstname1" );
|
||||
c1.setName( "Name1" );
|
||||
c1.setCode( "1234" );
|
||||
c1.setStreet( "Street1" );
|
||||
c1.setCity( "City1" );
|
||||
|
||||
Account a1 = new Account();
|
||||
a1.setNumber( "1000" );
|
||||
a1.setBalance( 5000.0 );
|
||||
|
||||
a1.addClient( c1 );
|
||||
|
||||
session.persist( c1 );
|
||||
session.persist( a1 );
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
c1 = session.load( Client.class, c1.getId() );
|
||||
assertEquals( 5000.0, c1.getAccount().getBalance(), 0.01 );
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
a1 = session.load( Account.class, a1.getId() );
|
||||
Set<Client> clients = a1.getClients();
|
||||
assertEquals( 1, clients.size() );
|
||||
Iterator<Client> it = clients.iterator();
|
||||
c1 = it.next();
|
||||
assertEquals( "Name1", c1.getName() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-4240")
|
||||
public void testSecondaryTables(SessionFactoryScope scope) {
|
||||
// HHH-4240 - SecondaryTables not recognized when using JOINED inheritance
|
||||
Company company = new Company();
|
||||
company.setCustomerName( "Mama" );
|
||||
company.setCustomerCode( "123" );
|
||||
company.setCompanyName( "Mama Mia Pizza" );
|
||||
company.setCompanyAddress( "Rome" );
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( company )
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Company c = session.get( Company.class, company.getId() );
|
||||
assertEquals( "Mama", c.getCustomerName() );
|
||||
assertEquals( "123", c.getCustomerCode() );
|
||||
assertEquals( "Mama Mia Pizza", c.getCompanyName() );
|
||||
assertEquals( "Rome", c.getCompanyAddress() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void checkClassType(File fruitToTest, File f, Folder a) {
|
||||
if ( fruitToTest.getName().equals( f.getName() ) ) {
|
||||
assertFalse( fruitToTest instanceof Folder );
|
||||
}
|
||||
else if ( fruitToTest.getName().equals( a.getName() ) ) {
|
||||
assertTrue( fruitToTest instanceof Folder );
|
||||
}
|
||||
else {
|
||||
fail( "Result does not contains the previously inserted elements" );
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "from Customer" ).list().forEach(
|
||||
customer -> session.delete( customer )
|
||||
);
|
||||
|
||||
session.createQuery( "from Account" ).list().forEach(
|
||||
account -> session.delete( account )
|
||||
);
|
||||
|
||||
session.createQuery( "from Client" ).list().forEach(
|
||||
client -> session.delete( client )
|
||||
);
|
||||
|
||||
session.createQuery( "from ProgramExecution" ).list().forEach(
|
||||
programExecution -> session.delete( programExecution )
|
||||
);
|
||||
|
||||
session.createQuery( "from Alarm" ).list().forEach(
|
||||
alarm -> session.delete( alarm )
|
||||
);
|
||||
|
||||
session.createQuery( "from EventInformation" ).list().forEach(
|
||||
eventInformation -> session.delete( eventInformation )
|
||||
);
|
||||
|
||||
|
||||
session.createQuery( "from File" ).list().forEach(
|
||||
file -> session.delete( file )
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* @author Sharath Reddy
|
||||
*
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class LegalEntity {
|
||||
|
||||
private Long id;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "Parent")
|
||||
public class Parent {
|
||||
private Integer id;
|
||||
private Set propertyAssets = new HashSet();
|
||||
private Set financialAssets = new HashSet();
|
||||
|
||||
@Id @GeneratedValue public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "parent", targetEntity = PropertyAsset.class)
|
||||
public Set getPropertyAssets() {
|
||||
return this.propertyAssets;
|
||||
}
|
||||
|
||||
public void setPropertyAssets(Set propertyAssets) {
|
||||
this.propertyAssets = propertyAssets;
|
||||
}
|
||||
|
||||
@OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "parent", targetEntity = FinancialAsset.class)
|
||||
public Set getFinancialAssets() {
|
||||
return this.financialAssets;
|
||||
}
|
||||
|
||||
public void setFinancialAssets(Set financialAssets) {
|
||||
this.financialAssets = financialAssets;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@Table(name = "PERSON")
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String firtsname;
|
||||
|
||||
public Person() {
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firtsname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firtsname = firstname;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.SecondaryTable;
|
||||
import javax.persistence.SecondaryTables;
|
||||
|
||||
import org.hibernate.annotations.Tables;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@SecondaryTables({
|
||||
@SecondaryTable(name="POOL_ADDRESS"),
|
||||
@SecondaryTable(name="POOL_ADDRESS_2")
|
||||
})
|
||||
@Tables({
|
||||
@org.hibernate.annotations.Table(appliesTo="POOL_ADDRESS", optional=true),
|
||||
@org.hibernate.annotations.Table(appliesTo="POOL_ADDRESS_2", optional=true, inverse = true)
|
||||
})
|
||||
public class Pool {
|
||||
@Id @GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
@Embedded
|
||||
private PoolAddress address;
|
||||
|
||||
@Embedded
|
||||
@AttributeOverride(name = "address", column = @Column(table = "POOL_ADDRESS_2"))
|
||||
private PoolAddress secondaryAddress;
|
||||
|
||||
public PoolAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(PoolAddress address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public PoolAddress getSecondaryAddress() {
|
||||
return secondaryAddress;
|
||||
}
|
||||
|
||||
public void setSecondaryAddress(PoolAddress secondaryAddress) {
|
||||
this.secondaryAddress = secondaryAddress;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class PoolAddress {
|
||||
@Column(table = "POOL_ADDRESS")
|
||||
private String address;
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class ProgramExecution {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
private String action;
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private File appliesOn;
|
||||
|
||||
|
||||
public File getAppliesOn() {
|
||||
return appliesOn;
|
||||
}
|
||||
|
||||
public void setAppliesOn(File appliesOn) {
|
||||
this.appliesOn = appliesOn;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class PropertyAsset extends Asset {
|
||||
private double price;
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumn(name = "clothing_id")
|
||||
public class Sweater extends Clothing {
|
||||
private boolean isSweat;
|
||||
|
||||
public boolean isSweat() {
|
||||
return isSweat;
|
||||
}
|
||||
|
||||
public void setSweat(boolean sweat) {
|
||||
isSweat = sweat;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class SwimmingPool extends Pool {
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class SymbolicLink extends File {
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
File target;
|
||||
|
||||
SymbolicLink() {
|
||||
}
|
||||
|
||||
public SymbolicLink(File target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public File getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(File target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.mixed;
|
||||
package org.hibernate.orm.test.annotations.inheritance.mixed;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.mixed;
|
||||
package org.hibernate.orm.test.annotations.inheritance.mixed;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.mixed;
|
||||
package org.hibernate.orm.test.annotations.inheritance.mixed;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.DiscriminatorValue;
|
|
@ -4,19 +4,17 @@
|
|||
* 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.mixed;
|
||||
package org.hibernate.orm.test.annotations.inheritance.mixed;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -27,27 +25,30 @@ import static org.junit.Assert.fail;
|
|||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class SubclassTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
File.class,
|
||||
Folder.class,
|
||||
Document.class,
|
||||
SymbolicLink.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class SubclassTest {
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
public void testDefault(SessionFactoryScope scope) {
|
||||
File doc = new Document( "Enron Stuff To Shred", 1000 );
|
||||
Folder folder = new Folder( "Enron" );
|
||||
try {
|
||||
s.persist( doc );
|
||||
s.persist( folder );
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
{
|
||||
session.persist( doc );
|
||||
session.persist( folder );
|
||||
}
|
||||
);
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
catch (SQLGrammarException e) {
|
||||
System.err.println( e.getSQLException().getNextException() );
|
||||
}
|
||||
s.close();
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<File> criteria = criteriaBuilder.createQuery( File.class );
|
||||
|
@ -78,15 +79,4 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
fail( "Result does not contains the previously inserted elements" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
File.class,
|
||||
Folder.class,
|
||||
Document.class,
|
||||
SymbolicLink.class
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.mixed;
|
||||
package org.hibernate.orm.test.annotations.inheritance.mixed;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorValue;
|
|
@ -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.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
|
@ -21,31 +21,32 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
|||
import org.hibernate.internal.SessionFactoryRegistry;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.junit5.BaseUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-7214" )
|
||||
public class DuplicatedDiscriminatorValueTest extends BaseUnitTestCase {
|
||||
public class DuplicatedDiscriminatorValueTest extends BaseUnitTest {
|
||||
private static final String DISCRIMINATOR_VALUE = "D";
|
||||
|
||||
@Test
|
||||
public void testDuplicatedDiscriminatorValueSameHierarchy() {
|
||||
try {
|
||||
tryBuildingSessionFactory( Building.class, Building1.class, Building2.class );
|
||||
Assert.fail( MappingException.class.getName() + " expected when two subclasses are mapped with the same discriminator value." );
|
||||
fail( MappingException.class.getName() + " expected when two subclasses are mapped with the same discriminator value." );
|
||||
}
|
||||
catch ( MappingException e ) {
|
||||
final String errorMsg = e.getCause().getMessage();
|
||||
// Check if error message contains descriptive information.
|
||||
Assert.assertTrue( errorMsg.contains( Building1.class.getName() ) );
|
||||
Assert.assertTrue( errorMsg.contains( Building2.class.getName() ) );
|
||||
Assert.assertTrue( errorMsg.contains( "discriminator value '" + DISCRIMINATOR_VALUE + "'." ) );
|
||||
assertTrue( errorMsg.contains( Building1.class.getName() ) );
|
||||
assertTrue( errorMsg.contains( Building2.class.getName() ) );
|
||||
assertTrue( errorMsg.contains( "discriminator value '" + DISCRIMINATOR_VALUE + "'." ) );
|
||||
}
|
||||
|
||||
assertFalse( SessionFactoryRegistry.INSTANCE.hasRegistrations() );
|
||||
|
@ -57,6 +58,7 @@ public class DuplicatedDiscriminatorValueTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
private void tryBuildingSessionFactory(Class... annotatedClasses) {
|
||||
SessionFactoryRegistry.INSTANCE.clearRegistrations();
|
||||
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build();
|
||||
try {
|
||||
final MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.singletable;
|
||||
package org.hibernate.orm.test.annotations.inheritance.singletable;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
import javax.persistence.Entity;
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.union;
|
||||
package org.hibernate.orm.test.annotations.inheritance.union;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.union;
|
||||
package org.hibernate.orm.test.annotations.inheritance.union;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.union;
|
||||
package org.hibernate.orm.test.annotations.inheritance.union;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Entity;
|
|
@ -4,42 +4,50 @@
|
|||
* 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.union;
|
||||
package org.hibernate.orm.test.annotations.inheritance.union;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.junit.Test;
|
||||
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 org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class SubclassTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
File.class,
|
||||
Folder.class,
|
||||
Document.class,
|
||||
SymbolicLink.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class SubclassTest {
|
||||
@Test
|
||||
public void testDefault() {
|
||||
public void testDefault(SessionFactoryScope scope) {
|
||||
File doc = new Document( "Enron Stuff To Shred", 1000 );
|
||||
Folder folder = new Folder( "Enron" );
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
s.persist( doc );
|
||||
s.persist( folder );
|
||||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<File> criteria = criteriaBuilder.createQuery( File.class );
|
||||
|
@ -68,14 +76,4 @@ public class SubclassTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
File.class,
|
||||
Folder.class,
|
||||
Document.class,
|
||||
SymbolicLink.class
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.union;
|
||||
package org.hibernate.orm.test.annotations.inheritance.union;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
|
@ -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.subclassProxyInterface;
|
||||
package org.hibernate.orm.test.subclassProxyInterface;
|
||||
|
||||
|
||||
/**
|
|
@ -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.subclassProxyInterface;
|
||||
package org.hibernate.orm.test.subclassProxyInterface;
|
||||
|
||||
|
||||
/**
|
|
@ -9,7 +9,7 @@
|
|||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.subclassProxyInterface">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.subclassProxyInterface">
|
||||
<class name="Person">
|
||||
<id name="id" type="long">
|
||||
<generator class="increment"/>
|
|
@ -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.subclassProxyInterface;
|
||||
package org.hibernate.orm.test.subclassProxyInterface;
|
||||
|
||||
|
||||
/**
|
|
@ -4,21 +4,20 @@
|
|||
* 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.subclassProxyInterface;
|
||||
|
||||
import org.junit.Test;
|
||||
package org.hibernate.orm.test.subclassProxyInterface;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.junit5.BaseUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SubclassProxyInterfaceTest extends BaseUnitTestCase {
|
||||
public class SubclassProxyInterfaceTest extends BaseUnitTest {
|
||||
@Test
|
||||
public void testSubclassProxyInterfaces() {
|
||||
final Configuration cfg = new Configuration()
|
|
@ -1,34 +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.genericsinheritance;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class GenericsInheritanceTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testMapping() throws Exception {
|
||||
Session s = openSession();
|
||||
s.close();
|
||||
//mapping is tested
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
ChildHierarchy1.class,
|
||||
ParentHierarchy1.class,
|
||||
ChildHierarchy22.class,
|
||||
ParentHierarchy22.class
|
||||
};
|
||||
}
|
||||
}
|
|
@ -19,10 +19,10 @@ 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.test.annotations.inheritance.singletable.Funk;
|
||||
import org.hibernate.test.annotations.inheritance.singletable.Music;
|
||||
import org.hibernate.test.annotations.inheritance.singletable.Noise;
|
||||
import org.hibernate.test.annotations.inheritance.singletable.Rock;
|
||||
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 static org.junit.Assert.assertEquals;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* 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 java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* 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 java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
|
@ -30,8 +30,6 @@ public class Client extends Person implements Serializable {
|
|||
joinColumns = {@JoinColumn(name = "FK_CLIENT", referencedColumnName = "ID")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "FK_ACCOUNT", referencedColumnName = "ID")})
|
||||
private Account account;
|
||||
|
||||
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* 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 javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.SecondaryTable;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* 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 javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Entity;
|
||||
|
|
|
@ -6,100 +6,121 @@
|
|||
*/
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
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.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
|
||||
*/
|
||||
public class JoinedSubclassAndSecondaryTable extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Pool.class,
|
||||
SwimmingPool.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class JoinedSubclassAndSecondaryTable {
|
||||
|
||||
@Test
|
||||
public void testSecondaryTableAndJoined() {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
SwimmingPool sp = new SwimmingPool();
|
||||
s.persist( sp );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
long rowCount = getTableRowCount( s, "POOL_ADDRESS" );
|
||||
assertEquals(
|
||||
"The address table is marked as optional. For null values no database row should be created",
|
||||
0,
|
||||
rowCount
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
sesison ->
|
||||
sesison.createQuery( "from Pool" ).list().forEach(
|
||||
pool -> sesison.delete( pool )
|
||||
)
|
||||
);
|
||||
|
||||
SwimmingPool sp2 = (SwimmingPool) s.get( SwimmingPool.class, sp.getId() );
|
||||
assertNull( sp.getAddress() );
|
||||
|
||||
PoolAddress address = new PoolAddress();
|
||||
address.setAddress( "Park Avenue" );
|
||||
sp2.setAddress( address );
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
sp2 = (SwimmingPool) s.get( SwimmingPool.class, sp.getId() );
|
||||
rowCount = getTableRowCount( s, "POOL_ADDRESS" );
|
||||
assertEquals(
|
||||
"Now we should have a row in the pool address table ",
|
||||
1,
|
||||
rowCount
|
||||
);
|
||||
assertNotNull( sp2.getAddress() );
|
||||
assertEquals( sp2.getAddress().getAddress(), "Park Avenue" );
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondaryTableAndJoinedInverse() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
SwimmingPool sp = new SwimmingPool();
|
||||
s.persist( sp );
|
||||
s.flush();
|
||||
s.clear();
|
||||
public void testSecondaryTableAndJoined(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
SwimmingPool sp = new SwimmingPool();
|
||||
session.persist( sp );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
long rowCount = getTableRowCount( s, "POOL_ADDRESS_2" );
|
||||
assertEquals(
|
||||
"The address table is marked as optional. For null values no database row should be created",
|
||||
0,
|
||||
rowCount
|
||||
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" );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
SwimmingPool sp2 = (SwimmingPool) s.get( SwimmingPool.class, sp.getId() );
|
||||
assertNull( sp.getSecondaryAddress() );
|
||||
@Test
|
||||
public void testSecondaryTableAndJoinedInverse(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
SwimmingPool sp = new SwimmingPool();
|
||||
session.persist( sp );
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
PoolAddress address = new PoolAddress();
|
||||
address.setAddress( "Park Avenue" );
|
||||
sp2.setSecondaryAddress( address );
|
||||
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"
|
||||
);
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
SwimmingPool sp2 = session.get( SwimmingPool.class, sp.getId() );
|
||||
assertNull( sp.getSecondaryAddress() );
|
||||
|
||||
sp2 = (SwimmingPool) s.get( SwimmingPool.class, sp.getId() );
|
||||
rowCount = getTableRowCount( s, "POOL_ADDRESS_2" );
|
||||
assertEquals(
|
||||
"Now we should have a row in the pool address table ",
|
||||
0,
|
||||
rowCount
|
||||
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() );
|
||||
}
|
||||
);
|
||||
assertNull( sp2.getSecondaryAddress() );
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
private long getTableRowCount(Session s, String tableName) {
|
||||
|
@ -108,11 +129,6 @@ public class JoinedSubclassAndSecondaryTable extends BaseCoreFunctionalTestCase
|
|||
// 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] { Pool.class, SwimmingPool.class };
|
||||
return ( (Number) retVal ).longValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,242 +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 java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testDefault() {
|
||||
File doc = new Document( "Enron Stuff To Shred", 1000 );
|
||||
Folder folder = new Folder( "Enron" );
|
||||
inTransaction(
|
||||
s -> {
|
||||
s.persist( doc );
|
||||
s.persist( folder );
|
||||
}
|
||||
);
|
||||
inTransaction(
|
||||
s -> {
|
||||
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<File> criteria = criteriaBuilder.createQuery( File.class );
|
||||
criteria.from( File.class );
|
||||
List<File> result = s.createQuery( criteria ).list();
|
||||
// List result = s.createCriteria( File.class ).list();
|
||||
assertNotNull( result );
|
||||
assertEquals( 2, result.size() );
|
||||
File f2 = result.get( 0 );
|
||||
checkClassType( f2, doc, folder );
|
||||
f2 = result.get( 1 );
|
||||
checkClassType( f2, doc, folder );
|
||||
s.delete( result.get( 0 ) );
|
||||
s.delete( result.get( 1 ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManyToOneOnAbstract() throws Exception {
|
||||
Folder f = new Folder();
|
||||
f.setName( "data" );
|
||||
ProgramExecution remove = new ProgramExecution();
|
||||
remove.setAction( "remove" );
|
||||
remove.setAppliesOn( f );
|
||||
|
||||
try(Session s = openSession()) {
|
||||
Transaction tx = s.beginTransaction();
|
||||
try {
|
||||
s.persist( f );
|
||||
s.persist( remove );
|
||||
tx.commit();
|
||||
s.clear();
|
||||
tx = s.beginTransaction();
|
||||
remove = s.get( ProgramExecution.class, remove.getId() );
|
||||
assertNotNull( remove );
|
||||
assertNotNull( remove.getAppliesOn().getName() );
|
||||
s.delete( remove );
|
||||
s.delete( remove.getAppliesOn() );
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( s.getTransaction().isActive() ) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkClassType(File fruitToTest, File f, Folder a) {
|
||||
if ( fruitToTest.getName().equals( f.getName() ) ) {
|
||||
assertFalse( fruitToTest instanceof Folder );
|
||||
}
|
||||
else if ( fruitToTest.getName().equals( a.getName() ) ) {
|
||||
assertTrue( fruitToTest instanceof Folder );
|
||||
}
|
||||
else {
|
||||
fail( "Result does not contains the previously inserted elements" );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinedAbstractClass() {
|
||||
Session s;
|
||||
s = openSession();
|
||||
s.getTransaction().begin();
|
||||
Sweater sw = new Sweater();
|
||||
sw.setColor( "Black" );
|
||||
sw.setSize( 2 );
|
||||
sw.setSweat( true );
|
||||
s.persist( sw );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
|
||||
s = openSession();
|
||||
s.getTransaction().begin();
|
||||
sw = s.get( Sweater.class, sw.getId() );
|
||||
s.delete( sw );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInheritance() {
|
||||
Session session = openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
String eventPK = "event1";
|
||||
EventInformation event = session.get( EventInformation.class, eventPK );
|
||||
if ( event == null ) {
|
||||
event = new EventInformation();
|
||||
event.setNotificationId( eventPK );
|
||||
session.persist( event );
|
||||
}
|
||||
String alarmPK = "alarm1";
|
||||
Alarm alarm = (Alarm) session.get( Alarm.class, alarmPK );
|
||||
if ( alarm == null ) {
|
||||
alarm = new Alarm();
|
||||
alarm.setNotificationId( alarmPK );
|
||||
alarm.setEventInfo( event );
|
||||
session.persist( alarm );
|
||||
}
|
||||
transaction.commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-4250" )
|
||||
public void testManyToOneWithJoinTable() {
|
||||
//HHH-4250 : @ManyToOne - @OneToMany doesn't work with @Inheritance(strategy= InheritanceType.JOINED)
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Client c1 = new Client();
|
||||
c1.setFirstname("Firstname1");
|
||||
c1.setName("Name1");
|
||||
c1.setCode("1234");
|
||||
c1.setStreet("Street1");
|
||||
c1.setCity("City1");
|
||||
|
||||
Account a1 = new Account();
|
||||
a1.setNumber("1000");
|
||||
a1.setBalance(5000.0);
|
||||
|
||||
a1.addClient(c1);
|
||||
|
||||
s.persist(c1);
|
||||
s.persist(a1);
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
c1 = s.load(Client.class, c1.getId());
|
||||
assertEquals( 5000.0, c1.getAccount().getBalance(), 0.01 );
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
a1 = s.load(Account.class,a1.getId());
|
||||
Set<Client> clients = a1.getClients();
|
||||
assertEquals(1, clients.size());
|
||||
Iterator<Client> it = clients.iterator();
|
||||
c1 = it.next();
|
||||
assertEquals("Name1", c1.getName());
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-4240" )
|
||||
public void testSecondaryTables() {
|
||||
// HHH-4240 - SecondaryTables not recognized when using JOINED inheritance
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
|
||||
Company company = new Company();
|
||||
company.setCustomerName("Mama");
|
||||
company.setCustomerCode("123");
|
||||
company.setCompanyName("Mama Mia Pizza");
|
||||
company.setCompanyAddress("Rome");
|
||||
|
||||
s.persist( company );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
|
||||
s = openSession();
|
||||
s.getTransaction().begin();
|
||||
company = (Company) s.get( Company.class, company.getId());
|
||||
assertEquals("Mama", company.getCustomerName());
|
||||
assertEquals("123", company.getCustomerCode());
|
||||
assertEquals("Mama Mia Pizza", company.getCompanyName());
|
||||
assertEquals("Rome", company.getCompanyAddress());
|
||||
|
||||
s.delete( company );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
File.class,
|
||||
Folder.class,
|
||||
Document.class,
|
||||
SymbolicLink.class,
|
||||
ProgramExecution.class,
|
||||
Clothing.class,
|
||||
Sweater.class,
|
||||
EventInformation.class,
|
||||
Alarm.class,
|
||||
Client.class,
|
||||
Account.class,
|
||||
Company.class
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -4,8 +4,8 @@
|
|||
* 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 javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* 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 javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import org.hibernate.annotations.Tables;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
|
|
Loading…
Reference in New Issue