Test and fix for HHH-11140
This commit is contained in:
parent
f34508e3f3
commit
b6aa191720
|
@ -455,6 +455,19 @@ public class FromElement extends HqlSqlWalkerNode implements DisplayableNode, Pa
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FromElement getFetchOrigin() {
|
||||||
|
if ( origin == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ( !origin.isFetch() ) {
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
if ( origin.getText() == null || "".equals( origin.getText() ) ) {
|
||||||
|
return origin.getFetchOrigin();
|
||||||
|
}
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
|
||||||
public static final String DISCRIMINATOR_PROPERTY_NAME = "class";
|
public static final String DISCRIMINATOR_PROPERTY_NAME = "class";
|
||||||
private TypeDiscriminatorMetadata typeDiscriminatorMetadata;
|
private TypeDiscriminatorMetadata typeDiscriminatorMetadata;
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,9 @@ public class SelectClause extends SelectExpressionList {
|
||||||
else {
|
else {
|
||||||
origin = fromElement.getRealOrigin();
|
origin = fromElement.getRealOrigin();
|
||||||
}
|
}
|
||||||
if ( !fromElementsForLoad.contains( origin ) ) {
|
if ( !fromElementsForLoad.contains( origin )
|
||||||
|
// work around that fetch joins of element collections where their parent instead of the root is selected
|
||||||
|
&& ( !fromElement.isCollectionJoin() || !fromElementsForLoad.contains( fromElement.getFetchOrigin() ) ) ) {
|
||||||
throw new QueryException(
|
throw new QueryException(
|
||||||
"query specified join fetching, but the owner " +
|
"query specified join fetching, but the owner " +
|
||||||
"of the fetched association was not present in the select list " +
|
"of the fetched association was not present in the select list " +
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.hibernate.test.collection.map;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "multilingual_parent")
|
||||||
|
public class MultilingualStringParent {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private long id;
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
private MultilingualStringParent parent;
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
private MultilingualString string;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultilingualStringParent getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent(MultilingualStringParent parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultilingualString getString() {
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setString(MultilingualString string) {
|
||||||
|
this.string = string;
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,6 +53,7 @@ public class PersistentMapTest extends BaseCoreFunctionalTestCase {
|
||||||
User.class,
|
User.class,
|
||||||
UserData.class,
|
UserData.class,
|
||||||
MultilingualString.class,
|
MultilingualString.class,
|
||||||
|
MultilingualStringParent.class,
|
||||||
Address.class,
|
Address.class,
|
||||||
Detail.class
|
Detail.class
|
||||||
};
|
};
|
||||||
|
@ -238,6 +239,50 @@ public class PersistentMapTest extends BaseCoreFunctionalTestCase {
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HQLPARSER-15")
|
||||||
|
public void testJoinFetchElementCollectionWithParentSelect() {
|
||||||
|
Session s = openSession();
|
||||||
|
s.getTransaction().begin();
|
||||||
|
|
||||||
|
MultilingualString m = new MultilingualString();
|
||||||
|
LocalizedString localizedString = new LocalizedString();
|
||||||
|
localizedString.setLanguage( "English" );
|
||||||
|
localizedString.setText( "name" );
|
||||||
|
m.getMap().put( localizedString.getLanguage(), localizedString );
|
||||||
|
localizedString = new LocalizedString();
|
||||||
|
localizedString.setLanguage( "English Pig Latin" );
|
||||||
|
localizedString.setText( "amenay" );
|
||||||
|
m.getMap().put( localizedString.getLanguage(), localizedString );
|
||||||
|
|
||||||
|
MultilingualStringParent parent = new MultilingualStringParent();
|
||||||
|
parent.setString( m );
|
||||||
|
|
||||||
|
s.persist( m );
|
||||||
|
s.persist( parent );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
m = s.createQuery(
|
||||||
|
"SELECT s FROM MultilingualStringParent parent " +
|
||||||
|
"JOIN parent.string s " +
|
||||||
|
"JOIN FETCH s.map", MultilingualString.class )
|
||||||
|
.getSingleResult();
|
||||||
|
assertEquals( 2, m.getMap().size() );
|
||||||
|
localizedString = m.getMap().get( "English" );
|
||||||
|
assertEquals( "English", localizedString.getLanguage() );
|
||||||
|
assertEquals( "name", localizedString.getText() );
|
||||||
|
localizedString = m.getMap().get( "English Pig Latin" );
|
||||||
|
assertEquals( "English Pig Latin", localizedString.getLanguage() );
|
||||||
|
assertEquals( "amenay", localizedString.getText() );
|
||||||
|
s.delete( parent );
|
||||||
|
s.delete( m );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-11038" )
|
@TestForIssue( jiraKey = "HHH-11038" )
|
||||||
public void testMapKeyColumnNonInsertableNonUpdatableBidirOneToMany() {
|
public void testMapKeyColumnNonInsertableNonUpdatableBidirOneToMany() {
|
||||||
|
|
Loading…
Reference in New Issue