Persisting LinkedList in Hibernate

后端 未结 2 1349
温柔的废话
温柔的废话 2021-01-07 02:28

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         


        
2条回答
  •  渐次进展
    2021-01-07 03:09

    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.

提交回复
热议问题