I am trying to persist a Class with a LinkedList Attribute but can\'t seem to get it right. Here is my code and my mapping:
import java.util.LinkedList;
pu
Generally, Hibernate will provide its own implementations for collections so you should prefer interfaces to specific implementations. It's probably attempting to assign a different kind of list to images and failing. You would have to change your field to List<Image>
.
Hibernate (and JPA in general) persists collections using their interfaces. The list must be declared as a List
, and not as a LinkedList
. And it won't be loaded with a LinkedList
instance, because Hibernate uses its own List
implementation to implement dirty-checking, lazy-loading, etc.
It's a good practice to program on interfaces rather than programming on concrete implementations in general. In JPA entities, it's mandatory.