HHH-7849 Unable to join on an embedded field
This commit is contained in:
parent
1286c2319c
commit
419e440629
|
@ -57,7 +57,8 @@ public class ComponentJoin extends FromElement {
|
|||
fromClause.addJoinByPathMap( componentPath, this );
|
||||
initializeComponentJoin( new ComponentFromElementType( this ) );
|
||||
|
||||
this.columns = origin.getPropertyMapping( "" ).toColumns( getTableAlias(), componentProperty );
|
||||
String[] cols = origin.getPropertyMapping( "" ).toColumns( getTableAlias(), componentProperty );
|
||||
this.columns = cols.length == 0 ? new String[] { null} : cols;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for ( int j = 0; j < columns.length; j++ ) {
|
||||
final String column = columns[j];
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.hibernate.test.component.basic2;
|
||||
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Mathieu Grenonville
|
||||
*/
|
||||
@Entity
|
||||
public class Component {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
@Embedded
|
||||
private Component.Emb emb;
|
||||
|
||||
public Component() {
|
||||
}
|
||||
|
||||
@Access(AccessType.FIELD)
|
||||
@Embeddable
|
||||
public static class Emb {
|
||||
|
||||
@OneToMany(targetEntity = Stuff.class)
|
||||
Set<Stuff> stuffs = new HashSet<Stuff>();
|
||||
|
||||
@Entity
|
||||
public static class Stuff {
|
||||
@Id
|
||||
private Long id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
package org.hibernate.test.component.basic2;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
@ -36,7 +37,7 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|||
public class ComponentJoinsTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] { Person.class };
|
||||
return new Class[]{Person.class, Component.class, Component.Emb.Stuff.class};
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -45,14 +46,27 @@ public class ComponentJoinsTest extends BaseCoreFunctionalTestCase {
|
|||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
// use it in WHERE
|
||||
session.createQuery( "select p from Person p join p.name as n where n.lastName like '%'" ).list();
|
||||
session.createQuery("select p from Person p join p.name as n where n.lastName like '%'").list();
|
||||
// use it in SELECT
|
||||
session.createQuery( "select n.lastName from Person p join p.name as n" ).list();
|
||||
session.createQuery( "select n from Person p join p.name as n" ).list();
|
||||
session.createQuery("select n.lastName from Person p join p.name as n").list();
|
||||
session.createQuery("select n from Person p join p.name as n").list();
|
||||
// use it in ORDER BY
|
||||
session.createQuery( "select n from Person p join p.name as n order by n.lastName" ).list();
|
||||
session.createQuery( "select n from Person p join p.name as n order by p" ).list();
|
||||
session.createQuery( "select n from Person p join p.name as n order by n" ).list();
|
||||
session.createQuery("select n from Person p join p.name as n order by n.lastName").list();
|
||||
session.createQuery("select n from Person p join p.name as n order by p").list();
|
||||
session.createQuery("select n from Person p join p.name as n order by n").list();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7849")
|
||||
public void testComponentJoins_HHH_7849() {
|
||||
// Just checking proper query construction and syntax checking via database query parser...
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
// use it in WHERE
|
||||
session.createQuery("select c from Component c join c.emb as e where e.stuffs is empty ").list();
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue