Search in sources :

Example 6 with NamedQuery

use of javax.persistence.NamedQuery in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getNamedQueries.

private NamedQueries getNamedQueries(Element tree, XMLContext.Default defaults) {
    //TODO avoid the Proxy Creation (@NamedQueries) when possible
    List<NamedQuery> queries = (List<NamedQuery>) buildNamedQueries(tree, false, defaults, classLoaderAccess);
    if (defaults.canUseJavaAnnotations()) {
        NamedQuery annotation = getPhysicalAnnotation(NamedQuery.class);
        addNamedQueryIfNeeded(annotation, queries);
        NamedQueries annotations = getPhysicalAnnotation(NamedQueries.class);
        if (annotations != null) {
            for (NamedQuery current : annotations.value()) {
                addNamedQueryIfNeeded(current, queries);
            }
        }
    }
    if (queries.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(NamedQueries.class);
        ad.setValue("value", queries.toArray(new NamedQuery[queries.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) NamedQueries(javax.persistence.NamedQueries) NamedQuery(javax.persistence.NamedQuery)

Example 7 with NamedQuery

use of javax.persistence.NamedQuery in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method addNamedQueryIfNeeded.

private void addNamedQueryIfNeeded(NamedQuery annotation, List<NamedQuery> queries) {
    if (annotation != null) {
        String queryName = annotation.name();
        boolean present = false;
        for (NamedQuery current : queries) {
            if (current.name().equals(queryName)) {
                present = true;
                break;
            }
        }
        if (!present) {
            queries.add(annotation);
        }
    }
}
Also used : NamedQuery(javax.persistence.NamedQuery)

Aggregations

NamedQuery (javax.persistence.NamedQuery)7 List (java.util.List)6 NamedNativeQuery (javax.persistence.NamedNativeQuery)5 Query (javax.persistence.Query)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 Session (org.hibernate.Session)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 NamedQueries (javax.persistence.NamedQueries)1 NamedStoredProcedureQuery (javax.persistence.NamedStoredProcedureQuery)1 SequenceGenerator (javax.persistence.SequenceGenerator)1 SqlResultSetMapping (javax.persistence.SqlResultSetMapping)1 TableGenerator (javax.persistence.TableGenerator)1 Element (org.dom4j.Element)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1