HHH-5727 Collection member declaration not handling optional AS in HQL.

This commit is contained in:
Strong Liu 2010-11-11 19:09:50 +08:00
parent 6e565102b5
commit 97f8ceac9b
4 changed files with 108 additions and 1 deletions

View File

@ -360,7 +360,7 @@ inClassDeclaration!
;
inCollectionDeclaration!
: IN! OPEN! p:path CLOSE! a:alias {
: IN! OPEN! p:path CLOSE! a:asAlias {
#inCollectionDeclaration = #([JOIN, "join"], [INNER, "inner"], #p, #a);
}
;

View File

@ -0,0 +1,36 @@
package org.hibernate.test.hql;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class EntityBean {
@Id
@GeneratedValue
private Long id;
@OneToMany(cascade=CascadeType.ALL)
private Set<Item> items = new HashSet<Item>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Set<Item> getItems() {
return items;
}
public void setItems(Set<Item> items) {
this.items = items;
}
}

View File

@ -0,0 +1,39 @@
package org.hibernate.test.hql;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.test.annotations.TestCase;
public class EntityBeanTest extends TestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[]{EntityBean.class,Item.class};
}
public void testAAA(){
Session s=openSession();
s.beginTransaction();
Item item = new Item();
item.setItemValue("1");
EntityBean eb = new EntityBean();
eb.getItems().add(item);
item=new Item();
item.setItemValue("2");
eb.getItems().add(item);
s.persist(eb);
s.getTransaction().commit();
s.close();
s=openSession();
s.beginTransaction();
Query query = s.createQuery("SELECT o FROM EntityBean AS o, IN (o.items) l WHERE l.itemValue = '1'");
List list = query.list();
assertEquals(list.size(), 1);
s.getTransaction().commit();
s.close();
}
}

View File

@ -0,0 +1,32 @@
package org.hibernate.test.hql;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Item {
@Id
@GeneratedValue
private Long id;
private String itemValue;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getItemValue() {
return itemValue;
}
public void setItemValue(String itemValue) {
this.itemValue = itemValue;
}
}