viernes, 22 de octubre de 2010

Cannot navigate association field [field] in the SET clause target TOPLINK

We migrated an application from Hibernate to TopLink with almost no efford, having an standard pesistence layer is awesome! Anyway some querys after the migration wasn't working and we were getting
'cannot navigate association field [field] in the SET clause target exceptions'. This happends because TopLink is a little more strict about your Entity Relations.

Example:

You have an entity School that includes an entity adress, and in the same way the adress is identified using an integer adressID.

School Entity


@Entity
class School{
@ID
private int schoolID;
@OneToOne
private Address address;
}



@Entity
class Address{
@ID
private int addressID;
}


If you create this query:

UPDATE School s SET s.address.adressID = :anAddressID

Hibernate will not complain but Toplink will fail. In toplink is mandatory to use the entity object instead the attributes of the entity: The correct query in toplink is:

UPDATE School s SET s.address = :anAddress

In my opinion is better using the entity object and not the ids 'cause you are taking advantage of the object abstraction provided by the persistence provider.

No hay comentarios:

Publicar un comentario