HHH-5102 - Instances of a subclass can't be loaded

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19220 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-04-13 14:01:54 +00:00
parent 38be092aae
commit 7323ab9876
6 changed files with 275 additions and 1 deletions

View File

@ -0,0 +1,46 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.mappedsuperclass.intermediate;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
/**
* The intermediate entity in the hierarchy
*
* @author Saša Obradović
*/
@Entity
@Table(name = "ACCOUNT")
@Inheritance(strategy = InheritanceType.JOINED)
public class Account extends AccountBase {
public Account() {
}
public Account(String accountNumber) {
super( accountNumber );
}
}

View File

@ -0,0 +1,67 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.mappedsuperclass.intermediate;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.GenerationType;
/**
* Represents the most base super class in the hierarchy.
*
* @author Saša Obradović
*/
@MappedSuperclass
public abstract class AccountBase {
@Id
@org.hibernate.annotations.GenericGenerator(name = "generator::Account", strategy = "increment")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator::Account")
@Column(name = "ACC_ID")
private Long id;
@Column(name = "ACC_NO")
private String accountNumber;
public Long getId() {
return id;
}
protected AccountBase() {
}
protected AccountBase(String accountNumber) {
this.accountNumber = accountNumber;
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
}

View File

@ -0,0 +1,59 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.mappedsuperclass.intermediate;
import java.math.BigDecimal;
import org.hibernate.Session;
import org.hibernate.test.annotations.TestCase;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public class IntermediateMappedSuperclassTest extends TestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { AccountBase.class, Account.class, SavingsAccountBase.class, SavingsAccount.class };
}
public void testGetOnIntermediateMappedSuperclass() {
final BigDecimal withdrawalLimit = new BigDecimal( 1000 );
Session session = openSession();
session.beginTransaction();
SavingsAccount savingsAccount = new SavingsAccount( "123", withdrawalLimit );
session.save( savingsAccount );
session.getTransaction().commit();
session.close();
session = openSession();
session.beginTransaction();
Account account = (Account) session.get( Account.class, savingsAccount.getId() );
assertEquals( withdrawalLimit, ( (SavingsAccount) account ).getWithdrawalLimit() );
session.delete( account );
session.getTransaction().commit();
session.close();
}
}

View File

@ -0,0 +1,46 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.mappedsuperclass.intermediate;
import java.math.BigDecimal;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
/**
* The "leaf" entity in the hierarchy
*
* @author Saša Obradović
*/
@Entity
@Table(name = "SAVINGS_ACCOUNT")
@PrimaryKeyJoinColumn(name = "SAVACC_ACC_ID")
public class SavingsAccount extends SavingsAccountBase {
public SavingsAccount() {
}
public SavingsAccount(String accountNumber, BigDecimal withdrawalLimit) {
super( accountNumber, withdrawalLimit );
}
}

View File

@ -0,0 +1,56 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.mappedsuperclass.intermediate;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
/**
* Represents the intermediate mapped superclass in the hierarchy.
*
* @author Saša Obradović
*/
@MappedSuperclass
public abstract class SavingsAccountBase extends Account {
@Column(name = "SAVACC_WITHDRAWALLIMIT")
private BigDecimal withdrawalLimit;
protected SavingsAccountBase() {
}
protected SavingsAccountBase(String accountNumber, BigDecimal withdrawalLimit) {
super( accountNumber );
this.withdrawalLimit = withdrawalLimit;
}
public BigDecimal getWithdrawalLimit() {
return withdrawalLimit;
}
public void setWithdrawalLimit(BigDecimal withdrawalLimit) {
this.withdrawalLimit = withdrawalLimit;
}
}

View File

@ -99,7 +99,7 @@ public class Subclass extends PersistentClass {
getSuperclass().addSubclassProperty(p);
}
public void addMappedsuperClassProperty(Property p) {
public void addMappedsuperclassProperty(Property p) {
super.addMappedsuperclassProperty( p );
getSuperclass().addSubclassProperty(p);
}