HHH-4364 support @NamedQuery on a @MappedSuperclass (Sharath Reddy)
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17530 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
b8da757937
commit
88caf4d958
|
@ -429,6 +429,12 @@ public final class AnnotationBinder {
|
|||
//TODO: be more strict with secondarytable allowance (not for ids, not for secondary table join columns etc)
|
||||
InheritanceState inheritanceState = inheritanceStatePerClass.get( clazzToProcess );
|
||||
AnnotatedClassType classType = mappings.getClassType( clazzToProcess );
|
||||
|
||||
//Queries declared in MappedSuperclass should be usable in Subclasses
|
||||
if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType )) {
|
||||
bindQueries(clazzToProcess, mappings );
|
||||
}
|
||||
|
||||
if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) //will be processed by their subentities
|
||||
|| AnnotatedClassType.NONE.equals( classType ) //to be ignored
|
||||
|| AnnotatedClassType.EMBEDDABLE.equals( classType ) //allow embeddable element declaration
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.hibernate.test.annotations.query;
|
||||
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@org.hibernate.annotations.NamedQuery(
|
||||
name = "night.olderThan",
|
||||
query = "select n from Night n where n.date <= :date"
|
||||
)
|
||||
|
||||
@MappedSuperclass
|
||||
public class Darkness {
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ import javax.persistence.NamedQuery;
|
|||
query = "select n from Night n where n.duration = :duration",
|
||||
cacheable = true, cacheRegion = "nightQuery"
|
||||
)
|
||||
public class Night {
|
||||
public class Night extends Darkness {
|
||||
private Integer id;
|
||||
private long duration;
|
||||
private Date date;
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Date;
|
|||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
@ -110,6 +111,17 @@ public class QueryAndSQLTest extends TestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
public void testImportQueryFromMappedSuperclass() {
|
||||
Session s = openSession();
|
||||
try {
|
||||
s.getNamedQuery( "night.olderThan" );
|
||||
}
|
||||
catch(MappingException ex) {
|
||||
assertTrue("Query imported from MappedSuperclass", false);
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
|
||||
public void testSQLQueryWithManyToOne() {
|
||||
Night n = new Night();
|
||||
Calendar c = new GregorianCalendar();
|
||||
|
|
Loading…
Reference in New Issue