HHH-7849 Unable to join on an embedded field

This commit is contained in:
mgrenonville 2012-12-07 17:40:51 +01:00 committed by brmeyer
parent 1286c2319c
commit 419e440629
3 changed files with 62 additions and 8 deletions

View File

@ -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];

View File

@ -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;
}
}
}

View File

@ -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();
}