Daredevil
Daredevil

Reputation: 1782

java- How to retrieve an id from a different class?

I have a Java class that links info to a table in database.

The class Fmpolicy.java:

  @Entity
    @Table(name = "fmpolicy")
    public class Fmpolicy implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "FMPID")
        private Long fmpid;
        @Basic(optional = false)
        @NotNull
        @Column(name = "NODEID")
        private long nodeid;
        @Basic(optional = false)
        @NotNull
        @Column(name = "FMPUGID")
        private long fmpugid;
        @Basic(optional = false)
        @NotNull
        @Column(name = "FMPUGTYPE")
        private int fmpugtype;
        @Basic(optional = false)
        @NotNull
        @Column(name = "FMPVIEW")
        private boolean fmpview;
        @Basic(optional = false)
        @NotNull
        @Column(name = "FMPREVISE")
        private boolean fmprevise;
        @Basic(optional = false)
        @NotNull
        @Column(name = "FMPDOWNLOAD")
        private boolean fmpdownload;

        @ManyToOne(fetch=FetchType.EAGER)
        @JoinColumn(referencedColumnName="nodeid",  name="NODEID", updatable=false, insertable=false)
        private Node fmn;

        public Fmpolicy() {
        }

        public Fmpolicy(Long fmpid) {
            this.fmpid = fmpid;
        }

        public Fmpolicy(Long fmpid, long nodeid, long fmpugid, int fmpugtype, boolean fmpview, boolean fmprevise, boolean fmpdownload) {
            this.fmpid = fmpid;
            this.nodeid = nodeid;
            this.fmpugid = fmpugid;
            this.fmpugtype = fmpugtype;
            this.fmpview = fmpview;
            this.fmprevise = fmprevise;
            this.fmpdownload = fmpdownload;
        }

        public Long getFmpid() {
            return fmpid;
        }

        public void setFmpid(Long fmpid) {
            this.fmpid = fmpid;
        }

        public long getNodeid() {
            return nodeid;
        }

        public void setNodeid(long nodeid) {
            this.nodeid = nodeid;
        }
............

The above is just some snippet of it. Then, I have a JSP page that I want to create an object of instance from this Fmpolicy.

The Jsp page:

    long nodeID = Long.parseLong(request.getParameter("nodeID"));
        long graphID = Long.parseLong(request.getParameter("graphID"));


        Fmpolicy fp = new Fmpolicy(nodeID);
        fp.getNodeid();
........
//this part should be able to check FMPVIEW column for it's nodeID respectively rather than FMPID
 if(fp.getFmpview(nodeID)==true) {
// do something if true

}

The problem is when I tried to debug it, the value of nodeID returns correctly but it is replaced by fmpid instead.For example, nodeID=123 but it passed the value to fmpid=123 instead.

So, I couldn't retrieve the particular id I want to achieve my goal. How do I properly passed nodeID to the object so I can check the conditions?

What did I do wrong?

Upvotes: 0

Views: 57

Answers (1)

Ryuzaki L
Ryuzaki L

Reputation: 39978

The single arg constructor you have will take the fmpid as an argument and assign it to private Long fmpid;

 public Fmpolicy(Long fmpid) {
        this.fmpid = fmpid;
    }

To set the nodeId create an object with no arg constructor and use setter method to set nodeId

Fmpolicy fp = new Fmpolicy();
fp.setNodeid(nodeID);

Upvotes: 1

Related Questions