jpa多对多映射时(@ManyToMany)时堆溢出(java.lang.StackOverflowError: null )

JPA(多对多映射)  角色和菜单多对多映射

 

TSRoleEntity.class
 
package com.nwnu.GanSuBank.system.manager.role.domain; import com.fasterxml.jackson.annotation.JsonIgnore; import com.nwnu.GanSuBank.system.manager.menu.domain.TSMenuEntity; import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; import java.io.Serializable; import java.sql.Time; import java.util.HashSet; import java.util.Set; @Entity @Table(name = "T_S_ROLE", schema = "C##GSBANK", catalog = "") public class TSRoleEntity implements Serializable { private String roleid; private String rolename; private String remark; private Time gmtCreate; private Time gmtModifid;
    @ManyToMany
    @JoinTable(name="ROLE_MENU",
            joinColumns={@JoinColumn(name="ROLEID", referencedColumnName="ROLEID")},
            inverseJoinColumns={@JoinColumn(name="MENUID", referencedColumnName="MENUID")})
    public Set getMenuid() {
        return menuid;
    }

    public void setMenuid(Set menuid) {
        this.menuid = menuid;
    }

    private Set menuid = new HashSet();

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name="system-uuid", strategy = "uuid")
    @Column(name = "ROLEID", nullable = false, length = 32)
    public String getRoleid() {
        return roleid;
    }

    public void setRoleid(String roleid) {
        this.roleid = roleid;
    }

    @Basic
    @Column(name = "ROLENAME", nullable = false, length = 255)
    public String getRolename() {
        return rolename;
    }

    public void setRolename(String rolename) {
        this.rolename = rolename;
    }

    @Basic
    @Column(name = "REMARK", nullable = false, length = 255)
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Basic
    @Column(name = "GMT_CREATE", nullable = true)
    public Time getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(Time gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    @Basic
    @Column(name = "GMT_MODIFID", nullable = true)
    public Time getGmtModifid() {
        return gmtModifid;
    }

    public void setGmtModifid(Time gmtModifid) {
        this.gmtModifid = gmtModifid;
    }
}
TSMenuEntity.class
 
 
package com.nwnu.GanSuBank.system.manager.menu.domain; import com.fasterxml.jackson.annotation.JsonIgnore; import com.nwnu.GanSuBank.system.manager.role.domain.TSRoleEntity; import javax.persistence.*; import java.io.Serializable; import java.sql.Time; import java.util.HashSet; import java.util.Set; @Entity @Table(name = "T_S_MENU", schema = "C##GSBANK", catalog = "") public class TSMenuEntity implements Serializable { private long menuid; private Long parentid; private String menuname; private String url; private String perms; private Long type; private Long ordername; private Time gmtcreate; private Time gmtmodified;   @ManyToMany(mappedBy="menuid") public Set getTsRoleEntitySet() { return tsRoleEntitySet; } public void setTsRoleEntitySet(Set tsRoleEntitySet) { this.tsRoleEntitySet = tsRoleEntitySet; } private Set tsRoleEntitySet = new HashSet(); @Id  @Column(name = "MENUID") public long getMenuid() { return menuid; } public void setMenuid(long menuid) { this.menuid = menuid; } @Basic  @Column(name = "PARENTID") public Long getParentid() { return parentid; } public void setParentid(Long parentid) { this.parentid = parentid; } @Basic  @Column(name = "MENUNAME") public String getMenuname() { return menuname; } public void setMenuname(String menuname) { this.menuname = menuname; } @Basic  @Column(name = "URL") public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } @Basic  @Column(name = "PERMS") public String getPerms() { return perms; } public void setPerms(String perms) { this.perms = perms; } @Basic  @Column(name = "TYPE") public Long getType() { return type; } public void setType(Long type) { this.type = type; } @Basic  @Column(name = "ORDERNAME") public Long getOrdername() { return ordername; } public void setOrdername(Long ordername) { this.ordername = ordername; } @Basic  @Column(name = "GMTCREATE") public Time getGmtcreate() { return gmtcreate; } public void setGmtcreate(Time gmtcreate) { this.gmtcreate = gmtcreate; } @Basic  @Column(name = "GMTMODIFIED") public Time getGmtmodified() { return gmtmodified; } public void setGmtmodified(Time gmtmodified) { this.gmtmodified = gmtmodified; } }

就会报错java.lang.StackOverflowError: null
at java.lang.ClassLoader.defineClass1(ClassLoader.java) ~[na:1.8.0_144]
at java.lang.ClassLoader._jr$defineClass(ClassLoader.java:763) ~[na:1.8.0_144]
at java.lang.ClassLoader.defineClass(ClassLoader.java) ~[na:1.8.0_144]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_144]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) ~[na:1.8.0_144]
at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_144]
at java.net.URLClassLoader$1.run(URLClassLoader.java:368) ~[na:1.8.0_144]
at java.net.URLClassLoader$1.run(URLClassLoader.java:362) ~[na:1.8.0_144]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_144]
at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[na:1.8.0_144]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_144]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_144]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_144]

 

我在网上查jpa堆溢出,这个问题很多人遇到。解决方案也有很多.

在关联的实体上面设置@JsonIgnore,这个注解的意思是表示在序列化的时候,忽略这个属性.但是我现在的逻辑是在页面中必须使用到这个关联实体中的属性,所以就不能这么做了,不然在页面中是取不出这个数据的。

Uncaught TypeError: Cannot read property 'name' of undefined

 

   更多计算机视频教程(Java、Python、大数据等等)、计算机软件(Mac)、影视资源推荐。

         欢迎大家关注本公众号:V的聚集地 

 

 

 

 

 

 

 

你可能感兴趣的:(spring,boot)