mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-10 05:04:52 +00:00
Merge branch '3.6' of github.com:hibernate/hibernate-core into 3.6
This commit is contained in:
commit
d85da2b66f
@ -360,7 +360,7 @@ inClassDeclaration!
|
|||||||
;
|
;
|
||||||
|
|
||||||
inCollectionDeclaration!
|
inCollectionDeclaration!
|
||||||
: IN! OPEN! p:path CLOSE! a:alias {
|
: IN! OPEN! p:path CLOSE! a:asAlias {
|
||||||
#inCollectionDeclaration = #([JOIN, "join"], [INNER, "inner"], #p, #a);
|
#inCollectionDeclaration = #([JOIN, "join"], [INNER, "inner"], #p, #a);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -65,7 +65,12 @@ protected T initializeCollection(int size) {
|
|||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
protected void addToCollection(T collection, Object collectionRow) {
|
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 the target entity is not audited, the elements may be the entities already, so we have to check
|
||||||
// if they are maps or not.
|
// if they are maps or not.
|
||||||
|
@ -63,13 +63,19 @@ protected List initializeCollection(int size) {
|
|||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
protected void addToCollection(List collection, Object collectionRow) {
|
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 ?
|
Object element = elementData instanceof Map ?
|
||||||
elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
|
elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
|
||||||
(Map<String, Object>) elementData, null, revision)
|
(Map<String, Object>) elementData, null, revision)
|
||||||
: elementData ;
|
: elementData ;
|
||||||
|
|
||||||
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
|
|
||||||
Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
|
Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
|
||||||
(Map<String, Object>) indexData, element, revision);
|
(Map<String, Object>) indexData, element, revision);
|
||||||
int index = ((Number) indexObj).intValue();
|
int index = ((Number) indexObj).intValue();
|
||||||
|
@ -67,14 +67,20 @@ protected T initializeCollection(int size) {
|
|||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
protected void addToCollection(T collection, Object collectionRow) {
|
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,
|
Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
|
||||||
(Map<String, Object>) elementData, null, revision);
|
(Map<String, Object>) elementData, null, revision);
|
||||||
|
|
||||||
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
|
|
||||||
Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
|
Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
|
||||||
(Map<String, Object>) indexData, element, revision);
|
(Map<String, Object>) indexData, element, revision);
|
||||||
|
|
||||||
collection.put(index, element);
|
collection.put(index, element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntities
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* The query that we need to create:
|
* The query that we need to create:
|
||||||
* SELECT new list(e) FROM versionsReferencedEntity e
|
* SELECT e FROM versionsReferencedEntity e
|
||||||
* WHERE
|
* WHERE
|
||||||
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
|
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
|
||||||
* e.id_ref_ing = :id_ref_ing AND
|
* e.id_ref_ing = :id_ref_ing AND
|
||||||
@ -73,9 +73,9 @@ public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntities
|
|||||||
|
|
||||||
String versionsReferencedEntityName = verEntCfg.getAuditEntityName(referencedEntityName);
|
String versionsReferencedEntityName = verEntCfg.getAuditEntityName(referencedEntityName);
|
||||||
|
|
||||||
// SELECT new list(e) FROM versionsEntity e
|
// SELECT e FROM versionsEntity e
|
||||||
QueryBuilder qb = new QueryBuilder(versionsReferencedEntityName, "e");
|
QueryBuilder qb = new QueryBuilder(versionsReferencedEntityName, "e");
|
||||||
qb.addProjection("new list", "e", false, false);
|
qb.addProjection(null, "e", false, false);
|
||||||
// WHERE
|
// WHERE
|
||||||
Parameters rootParameters = qb.getRootParameters();
|
Parameters rootParameters = qb.getRootParameters();
|
||||||
// e.id_ref_ed = :id_ref_ed
|
// e.id_ref_ed = :id_ref_ed
|
||||||
|
@ -53,7 +53,7 @@ public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* The query that we need to create:
|
* 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)
|
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
|
||||||
* ee.originalId.id_ref_ing = :id_ref_ing AND
|
* ee.originalId.id_ref_ing = :id_ref_ing AND
|
||||||
*
|
*
|
||||||
@ -73,9 +73,9 @@ public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg,
|
|||||||
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||||
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
||||||
|
|
||||||
// SELECT new list(ee) FROM middleEntity ee
|
// SELECT ee FROM middleEntity ee
|
||||||
QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
|
QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
|
||||||
qb.addProjection("new list", "ee", false, false);
|
qb.addProjection(null, "ee", false, false);
|
||||||
// WHERE
|
// WHERE
|
||||||
Parameters rootParameters = qb.getRootParameters();
|
Parameters rootParameters = qb.getRootParameters();
|
||||||
// ee.originalId.id_ref_ing = :id_ref_ing
|
// ee.originalId.id_ref_ing = :id_ref_ing
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
testsuite/src/test/java/org/hibernate/test/hql/Item.java
Normal file
32
testsuite/src/test/java/org/hibernate/test/hql/Item.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user