Search in sources :

Example 6 with NamedNativeQuery

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

the class JPAOverriddenAnnotationReader method addNamedNativeQueryIfNeeded.

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

Example 7 with NamedNativeQuery

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

the class JPAOverriddenAnnotationReader method getNamedNativeQueries.

private NamedNativeQueries getNamedNativeQueries(Element tree, XMLContext.Default defaults) {
    List<NamedNativeQuery> queries = (List<NamedNativeQuery>) buildNamedQueries(tree, true, defaults, classLoaderAccess);
    if (defaults.canUseJavaAnnotations()) {
        NamedNativeQuery annotation = getPhysicalAnnotation(NamedNativeQuery.class);
        addNamedNativeQueryIfNeeded(annotation, queries);
        NamedNativeQueries annotations = getPhysicalAnnotation(NamedNativeQueries.class);
        if (annotations != null) {
            for (NamedNativeQuery current : annotations.value()) {
                addNamedNativeQueryIfNeeded(current, queries);
            }
        }
    }
    if (queries.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(NamedNativeQueries.class);
        ad.setValue("value", queries.toArray(new NamedNativeQuery[queries.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) NamedNativeQuery(javax.persistence.NamedNativeQuery) NamedNativeQueries(javax.persistence.NamedNativeQueries) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

NamedNativeQuery (javax.persistence.NamedNativeQuery)7 List (java.util.List)6 NamedQuery (javax.persistence.NamedQuery)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 NamedNativeQueries (javax.persistence.NamedNativeQueries)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