Java 使用ElementCollection持久化字符串列表
所以我有一个实体类,它为字符串列表保存一个带有@ElementCollection注释的属性。当然,关键是要持久化/检索字符串列表Java 使用ElementCollection持久化字符串列表,java,hibernate,spring-boot,Java,Hibernate,Spring Boot,所以我有一个实体类,它为字符串列表保存一个带有@ElementCollection注释的属性。当然,关键是要持久化/检索字符串列表 @ElementCollection private List<String> listOfThings; 我可以看出有一个例外: method threw 'org.hibernate.lazyinitializationexception' exception. cannot evaluate tostring() ... 所以,在了解到我实际上
@ElementCollection
private List<String> listOfThings;
我可以看出有一个例外:
method threw 'org.hibernate.lazyinitializationexception' exception. cannot evaluate tostring() ...
所以,在了解到我实际上需要用急切的加载来注释listOfThings
之后:
@ElementCollection(fetch = FetchType.EAGER)
private List<String> listOfThings;
因此,无论哪种方式,存储字符串列表都不起作用。非常感谢您的帮助。您需要初始化您的收藏,例如:
private List<String> listOfThings = new ArrayList<>();
private List of things=new ArrayList();
对我来说很好
org.hibernate.SessionException: collections cannot be fetched by a stateless org.hibernate.internal.StatelessSessionImpl.initializeCollection(StatelessSessionImpl.java:299)
private List<String> listOfThings = new ArrayList<>();