mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-13 14:44:48 +00:00
HHH-7037 Dealing with @OrderBy
This commit is contained in:
parent
3fc75c8f4d
commit
f475dc096b
@ -29,26 +29,28 @@
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.DotName;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.hibernate.metamodel.internal.source.annotations.HibernateDotNames;
|
||||
import org.hibernate.metamodel.internal.source.annotations.JPADotNames;
|
||||
import org.hibernate.metamodel.internal.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
|
||||
|
||||
/**
|
||||
* Represents an association attribute.
|
||||
* Represents an collection association attribute.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class PluralAssociationAttribute extends AssociationAttribute {
|
||||
public class CollectionAssociationAttribute extends AssociationAttribute {
|
||||
private final String whereClause;
|
||||
private final String orderBy;
|
||||
|
||||
public static PluralAssociationAttribute createPluralAssociationAttribute(String name,
|
||||
Class<?> attributeType,
|
||||
AttributeNature attributeNature,
|
||||
String accessType,
|
||||
Map<DotName, List<AnnotationInstance>> annotations,
|
||||
EntityBindingContext context) {
|
||||
return new PluralAssociationAttribute(
|
||||
public static CollectionAssociationAttribute createPluralAssociationAttribute(String name,
|
||||
Class<?> attributeType,
|
||||
AttributeNature attributeNature,
|
||||
String accessType,
|
||||
Map<DotName, List<AnnotationInstance>> annotations,
|
||||
EntityBindingContext context) {
|
||||
return new CollectionAssociationAttribute(
|
||||
name,
|
||||
attributeType,
|
||||
attributeNature,
|
||||
@ -58,12 +60,12 @@ public static PluralAssociationAttribute createPluralAssociationAttribute(String
|
||||
);
|
||||
}
|
||||
|
||||
private PluralAssociationAttribute(String name,
|
||||
Class<?> javaType,
|
||||
AttributeNature associationType,
|
||||
String accessType,
|
||||
Map<DotName, List<AnnotationInstance>> annotations,
|
||||
EntityBindingContext context) {
|
||||
private CollectionAssociationAttribute(String name,
|
||||
Class<?> javaType,
|
||||
AttributeNature associationType,
|
||||
String accessType,
|
||||
Map<DotName, List<AnnotationInstance>> annotations,
|
||||
EntityBindingContext context) {
|
||||
super( name, javaType, associationType, accessType, annotations, context );
|
||||
this.whereClause = determineWereClause();
|
||||
this.orderBy = determineOrderBy();
|
||||
@ -83,12 +85,34 @@ private String determineWereClause() {
|
||||
private String determineOrderBy() {
|
||||
String orderBy = null;
|
||||
|
||||
AnnotationInstance whereAnnotation = JandexHelper.getSingleAnnotation(
|
||||
AnnotationInstance hibernateWhereAnnotation = JandexHelper.getSingleAnnotation(
|
||||
annotations(),
|
||||
HibernateDotNames.ORDER_BY
|
||||
);
|
||||
if ( whereAnnotation != null ) {
|
||||
orderBy = JandexHelper.getValue( whereAnnotation, "clause", String.class );
|
||||
|
||||
AnnotationInstance jpaWhereAnnotation = JandexHelper.getSingleAnnotation(
|
||||
annotations(),
|
||||
JPADotNames.ORDER_BY
|
||||
);
|
||||
|
||||
if ( jpaWhereAnnotation != null && hibernateWhereAnnotation != null ) {
|
||||
throw new AnnotationException(
|
||||
"Cannot use sql order by clause (@org.hibernate.annotations.OrderBy) " +
|
||||
"in conjunction with JPA order by clause (@java.persistence.OrderBy) on " + getName()
|
||||
);
|
||||
}
|
||||
|
||||
if ( hibernateWhereAnnotation != null ) {
|
||||
orderBy = JandexHelper.getValue( hibernateWhereAnnotation, "clause", String.class );
|
||||
}
|
||||
|
||||
if ( jpaWhereAnnotation != null ) {
|
||||
// todo
|
||||
// this could be an empty string according to JPA spec 11.1.38 -
|
||||
// If the ordering element is not specified for an entity association, ordering by the primary key of the
|
||||
// associated entity is assumed
|
||||
// The binder will need to take this into account and generate the right property names
|
||||
orderBy = JandexHelper.getValue( jpaWhereAnnotation, "value", String.class );
|
||||
}
|
||||
|
||||
return orderBy;
|
@ -35,9 +35,9 @@
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class ManyToManyPluralAttributeElementSourceImpl implements ManyToManyPluralAttributeElementSource {
|
||||
private final PluralAssociationAttribute associationAttribute;
|
||||
private final CollectionAssociationAttribute associationAttribute;
|
||||
|
||||
public ManyToManyPluralAttributeElementSourceImpl(PluralAssociationAttribute associationAttribute) {
|
||||
public ManyToManyPluralAttributeElementSourceImpl(CollectionAssociationAttribute associationAttribute) {
|
||||
this.associationAttribute = associationAttribute;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
|
||||
import org.hibernate.metamodel.internal.source.annotations.attribute.CollectionAssociationAttribute;
|
||||
import org.hibernate.metamodel.spi.source.MappingException;
|
||||
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
|
||||
import org.hibernate.metamodel.internal.source.annotations.HibernateDotNames;
|
||||
@ -143,7 +143,6 @@ public ConfiguredClass(
|
||||
this.parent = parent;
|
||||
this.classInfo = classInfo;
|
||||
this.clazz = context.locateClassByName( classInfo.toString() );
|
||||
// this.configuredClassType = determineType();
|
||||
this.classAccessType = determineClassAccessType( defaultAccessType );
|
||||
this.customTuplizer = determineCustomTuplizer();
|
||||
|
||||
@ -480,7 +479,7 @@ else if ( attribute.isVersioned() ) {
|
||||
}
|
||||
case ONE_TO_MANY:
|
||||
case MANY_TO_MANY: {
|
||||
AssociationAttribute attribute = PluralAssociationAttribute.createPluralAssociationAttribute(
|
||||
AssociationAttribute attribute = CollectionAssociationAttribute.createPluralAssociationAttribute(
|
||||
attributeName,
|
||||
attributeType,
|
||||
attributeNature,
|
||||
|
Loading…
x
Reference in New Issue
Block a user