如何从metamodel.MapAttribute

时间:2016-05-11 20:00:47

标签: java spring jpa-2.0 metamodel

如何使用metamodel.MapAttribute?我想从Map获取值,但我不知道如何?我们的想法是了解校准台上的所有仪表。

public class Calibration_ {

public static volatile javax.persistence.metamodel.MapAttribute<Calibration,Integer, Meter> positionsMeters;

}

我有这种地图属性,以了解仪表在校准台上的位置

@Entity
public class Calibration extends AbstractEntity implements Serializable {

private Map<Integer, Meter> positionsMeters;   
….
}

我试图以这种方式获取值,但它不起作用:

final QueryData<Calibration> queryData = new QueryData<>(Calibration.class);
final EntityManagerFactory em = Main.context.getBean(EntityManagerFactory.class);
final CriteriaBuilder builder = em.getCriteriaBuilder();
final Root<Meter> meter= queryData.criteria.from(Meter.class); 
final Root<Company> company= queryData.criteria.from(Company.class); 
Predicate filter = null;

filter = builder.and(

    builder.like(queryData.builder.lower(company.get(Company_.name)),"%" +    attribute.toLowerCase() + "%"),

    builder.equal(meter.get(Meter_.owner), company),

    builder.isMember(meter,builder.values((Map<Integer,Meter>)queryData.root.get(Calibration_.positionsMeters)))

);

0 个答案:

没有答案