diff --git a/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/Account.java b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/Account.java new file mode 100644 index 0000000000..0810c5f0df --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/Account.java @@ -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 ); + } +} \ No newline at end of file diff --git a/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/AccountBase.java b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/AccountBase.java new file mode 100644 index 0000000000..b493250d96 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/AccountBase.java @@ -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; + } +} \ No newline at end of file diff --git a/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/IntermediateMappedSuperclassTest.java b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/IntermediateMappedSuperclassTest.java new file mode 100644 index 0000000000..40c73afaf3 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/IntermediateMappedSuperclassTest.java @@ -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(); + } +} diff --git a/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/SavingsAccount.java b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/SavingsAccount.java new file mode 100644 index 0000000000..dd1942da7a --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/SavingsAccount.java @@ -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 ); + } +} \ No newline at end of file diff --git a/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/SavingsAccountBase.java b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/SavingsAccountBase.java new file mode 100644 index 0000000000..f81f7a98cb --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/SavingsAccountBase.java @@ -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; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hibernate/mapping/Subclass.java b/core/src/main/java/org/hibernate/mapping/Subclass.java index 3587e22e91..b7ecbaf1e6 100644 --- a/core/src/main/java/org/hibernate/mapping/Subclass.java +++ b/core/src/main/java/org/hibernate/mapping/Subclass.java @@ -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); }