Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » CriteriaBuilder and ManyToOne Entity
CriteriaBuilder and ManyToOne Entity [message #637147] Thu, 04 November 2010 11:43 Go to next message
joaquin  is currently offline joaquin Friend
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 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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
Re: CriteriaBuilder and ManyToOne Entity [message #637913 is a reply to message #637147] Tue, 09 November 2010 10:32 Go to previous message
joaquin  is currently offline joaquin Friend
Messages: 4
Registered: November 2010
Junior Member
Ok, it's working, thanks a lot
Previous Topic:ClassLoader Problem
Next Topic:em.persist trigger duplicate insertion
Goto Forum:
  


Current Time: Mon Nov 24 07:16:35 GMT 2014

Powered by FUDForum. Page generated in 0.01545 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software