mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-09 20:54:46 +00:00
Fix issue with query alias case sensitive and JPAQL strict compliance
This commit is contained in:
parent
d4c296b732
commit
fb62f9611a
@ -233,9 +233,13 @@ private boolean definesAttribute(SqmPathSource containerType, String name) {
|
|||||||
public SqmAliasedNode<?> findAliasedNodeByAlias(String alias) {
|
public SqmAliasedNode<?> findAliasedNodeByAlias(String alias) {
|
||||||
assert alias != null;
|
assert alias != null;
|
||||||
|
|
||||||
|
final String aliasToUse = jpaCompliance.isJpaQueryComplianceEnabled()
|
||||||
|
? alias.toLowerCase( Locale.getDefault() )
|
||||||
|
: alias;
|
||||||
|
|
||||||
for ( int i = 0; i < simpleSelectionNodes.size(); i++ ) {
|
for ( int i = 0; i < simpleSelectionNodes.size(); i++ ) {
|
||||||
final SqmAliasedNode<?> node = simpleSelectionNodes.get( i );
|
final SqmAliasedNode<?> node = simpleSelectionNodes.get( i );
|
||||||
if ( alias.equals( node.getAlias() ) ) {
|
if ( aliasToUse.equals( node.getAlias() ) ) {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,11 +253,15 @@ public Integer findAliasedNodePosition(String alias) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String aliasToUse = jpaCompliance.isJpaQueryComplianceEnabled()
|
||||||
|
? alias.toLowerCase( Locale.getDefault() )
|
||||||
|
: alias;
|
||||||
|
|
||||||
// NOTE : 1-based
|
// NOTE : 1-based
|
||||||
|
|
||||||
for ( int i = 0; i < simpleSelectionNodes.size(); i++ ) {
|
for ( int i = 0; i < simpleSelectionNodes.size(); i++ ) {
|
||||||
final SqmAliasedNode<?> node = simpleSelectionNodes.get( i );
|
final SqmAliasedNode<?> node = simpleSelectionNodes.get( i );
|
||||||
if ( alias.equals( node.getAlias() ) ) {
|
if ( aliasToUse.equals( node.getAlias() ) ) {
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
package org.hibernate.orm.test.jpa;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DomainModel(
|
||||||
|
annotatedClasses = JpaqlStrictComplianceAliasTest.Part.class
|
||||||
|
)
|
||||||
|
@ServiceRegistry(
|
||||||
|
settings = @Setting(name = Environment.JPAQL_STRICT_COMPLIANCE, value = "true")
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
public class JpaqlStrictComplianceAliasTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlias(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session ->
|
||||||
|
session.createQuery( "select p.stockNumber as stockNo FROM Part p ORDER BY stockNo" )
|
||||||
|
.getResultList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlias2(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session ->
|
||||||
|
session.createQuery( "select p.stockNumber as stockNo FROM Part P ORDER BY stockNo" )
|
||||||
|
.getResultList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlias3(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session ->
|
||||||
|
session.createQuery( "select P.stockNumber as stockNo FROM Part P ORDER BY stockNo" )
|
||||||
|
.getResultList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Entity(name = "Part")
|
||||||
|
public static class Part {
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String stockNumber;
|
||||||
|
|
||||||
|
public Part() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStockNumber() {
|
||||||
|
return stockNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStockNumber(String stockNumber) {
|
||||||
|
this.stockNumber = stockNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user