0

So I am having problems creating this new MenuPortlet when it has a parent of the same type. The parent exists in the database, and it is there when I setParent (mp).

package com.kpsol.version6.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

@Entity
@Table(name = "MENU_PORTLET")
@NamedQuery(name = "menuPortlet.findAll", query = "SELECT t FROM MenuPortlet t")

public class MenuPortlet extends Portlet implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableGenerator(name = "MenuPortlet", table = "NRD_ID", pkColumnName = "TABLENAME", valueColumnName = "NEXTID", pkColumnValue = "MENU_PORTLET", allocationSize = 1)
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "MenuPortlet")
    @Column(name = "MENUPORTLETID")
    private Long id;

    @ManyToOne
    @JoinColumn(name = "PARENTID")
    MenuPortlet parent;

    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = { CascadeType.ALL })
    @OrderBy("PORTLETORDER")
    Set<MenuPortlet> children = new HashSet<MenuPortlet>();

    @JoinColumn(name = "USERID")
    private Long userId;

    @Column(name = "ISUSER")
    private Boolean isUser;

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    public Long getUserId() {
        return this.userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public MenuPortlet getParent() {
        return this.parent;
    }

    public void setParent(MenuPortlet parent) {
        this.parent = parent;
    }

    public Set<MenuPortlet> getChildren() {
        return this.children;
    }

    public void setChildren(Set<MenuPortlet> children) {
        this.children = children;
    }

    public Boolean getIsUser() {
        return this.isUser;
    }

    public void setIsUser(Boolean isUser) {
        this.isUser = isUser;
    }

}

This is how I have my entity for the parent relationship. I have tried lazy and eager loads for both parent and children, neither seem to make a difference.

portlet.setParent(mp);
portlet = this.portletservice.create(portlet);

mp is the correct MenuPortlet, no problems there.

this.em.persist(portlet);

Honestly there is nothing else really to show. The annoying thing is I have done similar things in several other places and no problems, and I have literally copied down to the last part the same code, and it still does not work. What am I missing?

user1817988
  • 237
  • 2
  • 5
  • 11

0 Answers0