相关疑难解决方法(0)

在Hibernate中使用Transformers.aliasToBean填充子bean

我有下几个豆子:

Address {
    String name;
    String number;
    String zipcode;
    String town;
}

MyEntity {
    Address address;
    String value1;
    String value2;
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试执行下一个Hibernate查询:

private final List<String> propertiesDistinct = Arrays.asList("address.name");
private final List<String> properties = Arrays.asList("address.number",
        "address.zipcode", "address.town")

ProjectionList projectionList = Projections.projectionList();

if (propertiesDistinct != null) {
    ProjectionList projectionListDistinct = Projections.projectionList();
for (String propertyDistinct : propertiesDistinct)
         projectionListDistinct.add(Projections.property(propertyDistinct).as(propertyDistinct));

    projectionList.add(Projections.distinct(projectionListAgrupar));
}

if (properties != null)
    for (String property : properties)
         projectionList.add(Projections.property(property).as(property));
criterio.setProjection(projectionList);

// MORE FILTERS ON MyEntity FIELDS
//... criterio.add(Restrinctions...);

// I want to …
Run Code Online (Sandbox Code Playgroud)

java hibernate

4
推荐指数
1
解决办法
2万
查看次数

Java Hibernate Transformer AliasToBeanNestedResultTransformer

我有这样的查询.我传递学生证我需要学生以及他们的父母的一些字段以及父母的一些字段 - >地址[这是我面临的主要问题]我正在使用Sami Andoni的AliasToBeanNestedResultTransformer变压器

这里是CODE的实现

这是我的代码.

public List<Student>searchForStudent(Integer studentId)
{           
    Projection p=Projections.projectionList().create()
    .add(Projections.property("name"),"name")//the student name it works O.K
    .add(Projections.property("lastname"),"lastname")//the student name it works O.K
    .add(Projections.property("age"),"age")//the student AGE it works O.K                
    .add(Projections.property("p.phone"),"parent.phone")//the parent phone it works O.K                
    .add(Projections.property("address.state").as("parent.Address.state")); // i need a field from address.state here is the problem...  
    Session session = ......
    Criteria like = session.createCriteria(Student.class).add(prepareForSelect())//some filters..
    .createAlias("parent","p")//the parent of the student. a student have one parent
    .createAlias("parent.Address","address")//the address of the parent.... a parent have …
Run Code Online (Sandbox Code Playgroud)

java hibernate transformer-model

0
推荐指数
1
解决办法
2093
查看次数

标签 统计

hibernate ×2

java ×2

transformer-model ×1