Merge branch '3.6' of github.com:hibernate/hibernate-core into 3.6

This commit is contained in:
Hardy Ferentschik 2010-11-11 18:34:39 +01:00
commit d85da2b66f
9 changed files with 137 additions and 13 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

@ -65,7 +65,12 @@ protected T initializeCollection(int size) {
@SuppressWarnings({"unchecked"})
protected void addToCollection(T collection, Object collectionRow) {
Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
// collectionRow will be the actual object if retrieved from audit relation or middle table
// otherwise it will be a List
Object elementData = collectionRow;
if (collectionRow instanceof java.util.List) {
elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
}
// If the target entity is not audited, the elements may be the entities already, so we have to check
// if they are maps or not.

View File

@ -63,13 +63,19 @@ protected List initializeCollection(int size) {
@SuppressWarnings({"unchecked"})
protected void addToCollection(List collection, Object collectionRow) {
Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
// collectionRow will be the actual object if retrieved from audit relation or middle table
// otherwise it will be a List
Object elementData = collectionRow;
Object indexData = collectionRow;
if (collectionRow instanceof java.util.List) {
elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
}
Object element = elementData instanceof Map ?
elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
(Map<String, Object>) elementData, null, revision)
: elementData ;
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
(Map<String, Object>) indexData, element, revision);
int index = ((Number) indexObj).intValue();

View File

@ -67,14 +67,20 @@ protected T initializeCollection(int size) {
@SuppressWarnings({"unchecked"})
protected void addToCollection(T collection, Object collectionRow) {
Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
// collectionRow will be the actual object if retrieved from audit relation or middle table
// otherwise it will be a List
Object elementData = collectionRow;
Object indexData = collectionRow;
if (collectionRow instanceof java.util.List) {
elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
}
Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
(Map<String, Object>) elementData, null, revision);
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
(Map<String, Object>) indexData, element, revision);
collection.put(index, element);
}
}
}

View File

@ -52,7 +52,7 @@ public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntities
/*
* The query that we need to create:
* SELECT new list(e) FROM versionsReferencedEntity e
* SELECT e FROM versionsReferencedEntity e
* WHERE
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* e.id_ref_ing = :id_ref_ing AND
@ -73,9 +73,9 @@ public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntities
String versionsReferencedEntityName = verEntCfg.getAuditEntityName(referencedEntityName);
// SELECT new list(e) FROM versionsEntity e
// SELECT e FROM versionsEntity e
QueryBuilder qb = new QueryBuilder(versionsReferencedEntityName, "e");
qb.addProjection("new list", "e", false, false);
qb.addProjection(null, "e", false, false);
// WHERE
Parameters rootParameters = qb.getRootParameters();
// e.id_ref_ed = :id_ref_ed

View File

@ -53,7 +53,7 @@ public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg,
/*
* The query that we need to create:
* SELECT new list(ee) FROM middleEntity ee WHERE
* SELECT ee FROM middleEntity ee WHERE
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* ee.originalId.id_ref_ing = :id_ref_ing AND
*
@ -73,9 +73,9 @@ public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg,
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
// SELECT new list(ee) FROM middleEntity ee
// SELECT ee FROM middleEntity ee
QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
qb.addProjection("new list", "ee", false, false);
qb.addProjection(null, "ee", false, false);
// WHERE
Parameters rootParameters = qb.getRootParameters();
// ee.originalId.id_ref_ing = :id_ref_ing

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