Why does jpa one-way one-to-many association thymeleaf or stack overflow?

there is a set collection of tag classes in the user class;

maintain relationships only from the user class, one-to-many

@ OneToMany

@JoinTable(name="shuo_tag",

        inverseJoinColumns=@JoinColumn(name="tag_id"),

        joinColumns=@JoinColumn(name="shuo_id"))

private Set<Tag> tags;


there is no maintenance relationship in the Tag class

then I am in html

[[${user}]] so getting user will cause the following error

java.lang.StackOverflowError: null

at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1012) ~[na:1.8.0_151]

at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1535) ~[na:1.8.0_151]

at java.lang.ClassLoader.getClassLoadingLock(ClassLoader.java:463) ~[na:1.8.0_151]

at java.lang.ClassLoader.loadClass(ClassLoader.java:404) ~[na:1.8.0_151]

at java.lang.ClassLoader.loadClass(ClassLoader.java:411) ~[na:1.8.0_151]

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_151]

at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_151]

at org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365) ~[thymeleaf-2.1.6.RELEASE.jar:2.1.6.RELEASE]

at org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184) ~[thymeleaf-2.1.6.RELEASE.jar:2.1.6.RELEASE]

at org.thymeleaf.util.JavaScriptUtils.printArray(JavaScriptUtils.java:227) ~[thymeleaf-2.1.6.RELEASE.jar:2.1.6.RELEASE]

@ OneToMany has an attribute called fetch , which defaults to LAZY :

@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface OneToMany {

    /** (Optional) Whether the association should be lazily loaded or
     * must be eagerly fetched. The EAGER strategy is a requirement on
     * the persistence provider runtime that the associated entities
     * must be eagerly fetched.  The LAZY strategy is a hint to the
     * persistence provider runtime.
     */
    FetchType fetch() default LAZY;

}

so you need to use it directly. You need to modify it to load immediately. You can modify it like this:

@OneToMany(fetch = FetchType.EAGER)

this is the bug of thymeleaf 2. Upgrading to thymeleaf 3 can resolve this bug;

thymeleaf2 is handled by json;
thymeleaf3. The jackson,jackson used by thymeleaf3 can solve the problem of mutual reference between the two classes by using @ JsonIgnoreProperties and @ JsonIgnore annotations.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bcf200-451e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bcf200-451e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?