Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-8980 - Instance of super-class not found because of joined subcla…
…ss reference is an inner join
- Loading branch information
Showing
6 changed files
with
266 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...rnate-core/src/test/java/org/hibernate/test/loadplans/process/inheritance/Contractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* Copyright (c) 2014, 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.loadplans.process.inheritance; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@Entity | ||
public class Contractor extends User { | ||
|
||
// illustrates the problematic situation described in HHH-8330 | ||
|
||
@ManyToOne(fetch= FetchType.EAGER) | ||
@JoinColumn(name="reportsTo_id",nullable=false) | ||
Department reportsTo; | ||
|
||
public Contractor(Integer id, Department reportsTo) { | ||
super( id ); | ||
this.reportsTo = reportsTo; | ||
} | ||
|
||
public Contractor() { | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...rnate-core/src/test/java/org/hibernate/test/loadplans/process/inheritance/Department.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* Copyright (c) 2014, 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.loadplans.process.inheritance; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@Entity | ||
public class Department { | ||
@Id | ||
Integer id; | ||
|
||
public Department(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public Department() { | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
hibernate-core/src/test/java/org/hibernate/test/loadplans/process/inheritance/Employee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* Copyright (c) 2014, 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.loadplans.process.inheritance; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.ManyToOne; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@Entity | ||
public class Employee extends User { | ||
|
||
// illustrates the problematic situation described in HHH-8980 | ||
|
||
@ManyToOne(optional = false) | ||
Department belongsTo; | ||
|
||
public Employee(Integer id, Department belongsTo) { | ||
super( id ); | ||
this.belongsTo = belongsTo; | ||
} | ||
|
||
public Employee() { | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
hibernate-core/src/test/java/org/hibernate/test/loadplans/process/inheritance/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* Copyright (c) 2014, 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.loadplans.process.inheritance; | ||
|
||
import org.hibernate.Session; | ||
|
||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public class Test extends BaseCoreFunctionalTestCase { | ||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class[] { Department.class, User.class, Employee.class, Contractor.class }; | ||
} | ||
|
||
@org.junit.Test | ||
public void basicTest() { | ||
Session s = openSession(); | ||
s.beginTransaction(); | ||
User user = new User( 2 ); | ||
s.save( user ); | ||
s.getTransaction().commit(); | ||
s.close(); | ||
|
||
s = openSession(); | ||
s.beginTransaction(); | ||
assertNotNull( s.get( User.class, 2 ) ); | ||
s.getTransaction().commit(); | ||
s.close(); | ||
|
||
s = openSession(); | ||
s.beginTransaction(); | ||
s.createQuery( "delete User" ).executeUpdate(); | ||
s.getTransaction().commit(); | ||
s.close(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
hibernate-core/src/test/java/org/hibernate/test/loadplans/process/inheritance/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* Copyright (c) 2014, 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.loadplans.process.inheritance; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.Inheritance; | ||
import javax.persistence.InheritanceType; | ||
import javax.persistence.Table; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@Entity | ||
@Table( name = "`user`" ) | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
class User { | ||
@Id | ||
Integer id; | ||
|
||
User(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
User() { | ||
} | ||
} |