Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用ElementCollection持久化字符串列表_Java_Hibernate_Spring Boot - Fatal编程技术网

Java 使用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注释的属性。当然,关键是要持久化/检索字符串列表

@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<>();