CriteriaBuilder and ManyToOne Entity [message #637147] |
Thu, 04 November 2010 11:43 |
joaquin Messages: 4 Registered: November 2010 |
Junior Member |
|
|
Hello,
I am new on this forum and developing with eclipseLink.
Can I somehow access the field without having to create such a class field?
The code developed is like this
@IdClass(CabDecsalEntityPK.class)
public class CabDecsalEntity implements Serializable {
...
@JoinColumns({
@JoinColumn(name = "ALMDESTINO", referencedColumnName = "ALMACEN"),
@JoinColumn(name = "PASDESTINO", referencedColumnName = "PASILLO"),
@JoinColumn(name = "ESTDESTINO", referencedColumnName = "ESTANTERIA"),
@JoinColumn(name = "TRSDESTINO", referencedColumnName = "TRASLACION"),
@JoinColumn(name = "ELVDESTINO", referencedColumnName = "ELEVACION"),
@JoinColumn(name = "PRFDESTINO", referencedColumnName = "PROFUNDIDAD")})
@ManyToOne
private CabMapalmEntity cabMapalmDestinoEntity;
...
}
public class EntityFacade<T> implements EntityFacadeLocal<T> {
...
public List<T> findAll(Class<T> clazz, QueryFilterList filters, QueryOrder order) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(clazz);
Root<T> mapa = cq.from(clazz);
Predicate restriction = cb.conjunction();
restriction = cb.and(restriction, filters.applyToPredicate(cb, mapa));
cq.where(restriction);
if (order != null)
cq.orderBy(order.getOrderBy(cb, mapa));
return em.createQuery(cq).getResultList();
}
...
}
QueryFilterList is a list of fields and comparisons to add to the query
If the filter contains the field "ALMDESTINO" the EJB returns next error:
java.lang.IllegalArgumentException: The attribute [almdestino] from the managed type [EntityTypeImpl@1801682842:CabDecsalEntity [ javaType: class com.felguerati.entity.sga.CabDecsalEntity descriptor: RelationalDescriptor(com.felguerati.entity.sga.CabDecsalEnti ty --> [DatabaseTable(CAB_DECSAL)]), mappings: 35]] is not present.
Thanks in advance
|
|
|
Re: CriteriaBuilder and ManyToOne Entity [message #637205 is a reply to message #637147] |
Thu, 04 November 2010 15:08 |
|
What does your applyToPredicate() do? It sounds like it is trying to compare on a relationship that does not exist?
If you want to compare on a foreign key field in Criteria, you need to either compare to object (i.e. cabMapalmDestinoEntity = :cabMapalmDestinoEntity) or traverse the relationship (i.e. cabMapalmDestinoEntity.almdestino = :almdestino).
In EclipseLink you can also add a QueryKey for the foreign key, or in a EclipseLink Expression query use a FieldExpression (ExpressionBuilder.getField()).
Can you include the full stack trace.
James : Wiki : Book : Blog : Twitter
|
|
|
|
Powered by
FUDForum. Page generated in 0.03531 seconds