facebook

EJB 3 – Reverse Engineered Tables, Autogenerated Field

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #279832 Reply

    amattas
    Member

    I reverse engineered a table to create all my EJB 3 code, however one field on this table (refnum) is generated by a sequence in postgresql, how do I adjust the code for this, or how can I have EJB generate the value instead. (I’m sure I’ll have to modify my code regaurdless).

    Below is the Entity class.

    
    package com.stryker.cmf.ordermanagerbean;
    
    import java.util.Date;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    
    /**
     * Orders entity.
     * 
     * @author MyEclipse Persistence Tools
     */
    @Entity
    @Table(name = "orders", schema = "public", uniqueConstraints = {})
    public class Orders implements java.io.Serializable {
    
        // Fields
    
        private Integer refnum;
        private String ponumber;
        private Double thickness;
        private String patientid;
        private Date surgdate;
        private Integer patientage;
        private String gender;
        private String comments;
        private String shipto;
        private String address1;
        private String address2;
        private String city;
        private String state;
        private String zip;
        private Byte loc1;
        private Byte loc2;
        private Byte loc3;
        private Byte loc4;
        private Byte loc5;
        private Byte loc6;
        private Byte loc7;
        private Byte loc8;
        private Byte loc9;
        private Byte loc10;
        private Byte loc11;
        private Byte loc12;
        private Byte loc13;
        private Byte loc14;
        private Byte loc15;
        private Byte loc16;
        private Byte loc17;
        private Byte loc18;
        private Byte loc19;
        private Byte loc20;
        private String orderstage;
        private String user;
    
        // Constructors
    
        /** default constructor */
        public Orders() {
        }
    
        /** minimal constructor */
        public Orders(Integer refnum, String ponumber, String patientid,
                Date surgdate, Integer patientage, String gender, String shipto) {
            this.refnum = refnum;
            this.ponumber = ponumber;
            this.patientid = patientid;
            this.surgdate = surgdate;
            this.patientage = patientage;
            this.gender = gender;
            this.shipto = shipto;
        }
    
        /** full constructor */
        public Orders(Integer refnum, String ponumber, Double thickness,
                String patientid, Date surgdate, Integer patientage, String gender,
                String comments, String shipto, String address1, String address2,
                String city, String state, String zip, Byte loc1, Byte loc2,
                Byte loc3, Byte loc4, Byte loc5, Byte loc6, Byte loc7, Byte loc8,
                Byte loc9, Byte loc10, Byte loc11, Byte loc12, Byte loc13,
                Byte loc14, Byte loc15, Byte loc16, Byte loc17, Byte loc18,
                Byte loc19, Byte loc20, String orderstage, String user) {
            this.refnum = refnum;
            this.ponumber = ponumber;
            this.thickness = thickness;
            this.patientid = patientid;
            this.surgdate = surgdate;
            this.patientage = patientage;
            this.gender = gender;
            this.comments = comments;
            this.shipto = shipto;
            this.address1 = address1;
            this.address2 = address2;
            this.city = city;
            this.state = state;
            this.zip = zip;
            this.loc1 = loc1;
            this.loc2 = loc2;
            this.loc3 = loc3;
            this.loc4 = loc4;
            this.loc5 = loc5;
            this.loc6 = loc6;
            this.loc7 = loc7;
            this.loc8 = loc8;
            this.loc9 = loc9;
            this.loc10 = loc10;
            this.loc11 = loc11;
            this.loc12 = loc12;
            this.loc13 = loc13;
            this.loc14 = loc14;
            this.loc15 = loc15;
            this.loc16 = loc16;
            this.loc17 = loc17;
            this.loc18 = loc18;
            this.loc19 = loc19;
            this.loc20 = loc20;
            this.orderstage = orderstage;
            this.user = user;
        }
    
        // Property accessors
        @Id
        @Column(name = "refnum", unique = true, nullable = false, insertable = true, updatable = true)
        public Integer getRefnum() {
            return this.refnum;
        }
    
        public void setRefnum(Integer refnum) {
            this.refnum = refnum;
        }
    
        @Column(name = "ponumber", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
        public String getPonumber() {
            return this.ponumber;
        }
    
        public void setPonumber(String ponumber) {
            this.ponumber = ponumber;
        }
    
        @Column(name = "thickness", unique = false, nullable = true, insertable = true, updatable = true, precision = 17, scale = 17)
        public Double getThickness() {
            return this.thickness;
        }
    
        public void setThickness(Double thickness) {
            this.thickness = thickness;
        }
    
        @Column(name = "patientid", unique = false, nullable = false, insertable = true, updatable = true, length = 64)
        public String getPatientid() {
            return this.patientid;
        }
    
        public void setPatientid(String patientid) {
            this.patientid = patientid;
        }
    
        @Temporal(TemporalType.DATE)
        @Column(name = "surgdate", unique = false, nullable = false, insertable = true, updatable = true, length = 13)
        public Date getSurgdate() {
            return this.surgdate;
        }
    
        public void setSurgdate(Date surgdate) {
            this.surgdate = surgdate;
        }
    
        @Column(name = "patientage", unique = false, nullable = false, insertable = true, updatable = true)
        public Integer getPatientage() {
            return this.patientage;
        }
    
        public void setPatientage(Integer patientage) {
            this.patientage = patientage;
        }
    
        @Column(name = "gender", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
        public String getGender() {
            return this.gender;
        }
    
        public void setGender(String gender) {
            this.gender = gender;
        }
    
        @Column(name = "comments", unique = false, nullable = true, insertable = true, updatable = true, length = 2048)
        public String getComments() {
            return this.comments;
        }
    
        public void setComments(String comments) {
            this.comments = comments;
        }
    
        @Column(name = "shipto", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
        public String getShipto() {
            return this.shipto;
        }
    
        public void setShipto(String shipto) {
            this.shipto = shipto;
        }
    
        @Column(name = "address1", unique = false, nullable = true, insertable = true, updatable = true, length = 128)
        public String getAddress1() {
            return this.address1;
        }
    
        public void setAddress1(String address1) {
            this.address1 = address1;
        }
    
        @Column(name = "address2", unique = false, nullable = true, insertable = true, updatable = true, length = 128)
        public String getAddress2() {
            return this.address2;
        }
    
        public void setAddress2(String address2) {
            this.address2 = address2;
        }
    
        @Column(name = "city", unique = false, nullable = true, insertable = true, updatable = true, length = 64)
        public String getCity() {
            return this.city;
        }
    
        public void setCity(String city) {
            this.city = city;
        }
    
        @Column(name = "state", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
        public String getState() {
            return this.state;
        }
    
        public void setState(String state) {
            this.state = state;
        }
    
        @Column(name = "zip", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
        public String getZip() {
            return this.zip;
        }
    
        public void setZip(String zip) {
            this.zip = zip;
        }
    
        @Column(name = "loc1", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc1() {
            return this.loc1;
        }
    
        public void setLoc1(Byte loc1) {
            this.loc1 = loc1;
        }
    
        @Column(name = "loc2", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc2() {
            return this.loc2;
        }
    
        public void setLoc2(Byte loc2) {
            this.loc2 = loc2;
        }
    
        @Column(name = "loc3", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc3() {
            return this.loc3;
        }
    
        public void setLoc3(Byte loc3) {
            this.loc3 = loc3;
        }
    
        @Column(name = "loc4", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc4() {
            return this.loc4;
        }
    
        public void setLoc4(Byte loc4) {
            this.loc4 = loc4;
        }
    
        @Column(name = "loc5", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc5() {
            return this.loc5;
        }
    
        public void setLoc5(Byte loc5) {
            this.loc5 = loc5;
        }
    
        @Column(name = "loc6", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc6() {
            return this.loc6;
        }
    
        public void setLoc6(Byte loc6) {
            this.loc6 = loc6;
        }
    
        @Column(name = "loc7", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc7() {
            return this.loc7;
        }
    
        public void setLoc7(Byte loc7) {
            this.loc7 = loc7;
        }
    
        @Column(name = "loc8", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc8() {
            return this.loc8;
        }
    
        public void setLoc8(Byte loc8) {
            this.loc8 = loc8;
        }
    
        @Column(name = "loc9", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc9() {
            return this.loc9;
        }
    
        public void setLoc9(Byte loc9) {
            this.loc9 = loc9;
        }
    
        @Column(name = "loc10", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc10() {
            return this.loc10;
        }
    
        public void setLoc10(Byte loc10) {
            this.loc10 = loc10;
        }
    
        @Column(name = "loc11", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc11() {
            return this.loc11;
        }
    
        public void setLoc11(Byte loc11) {
            this.loc11 = loc11;
        }
    
        @Column(name = "loc12", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc12() {
            return this.loc12;
        }
    
        public void setLoc12(Byte loc12) {
            this.loc12 = loc12;
        }
    
        @Column(name = "loc13", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc13() {
            return this.loc13;
        }
    
        public void setLoc13(Byte loc13) {
            this.loc13 = loc13;
        }
    
        @Column(name = "loc14", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc14() {
            return this.loc14;
        }
    
        public void setLoc14(Byte loc14) {
            this.loc14 = loc14;
        }
    
        @Column(name = "loc15", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc15() {
            return this.loc15;
        }
    
        public void setLoc15(Byte loc15) {
            this.loc15 = loc15;
        }
    
        @Column(name = "loc16", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc16() {
            return this.loc16;
        }
    
        public void setLoc16(Byte loc16) {
            this.loc16 = loc16;
        }
    
        @Column(name = "loc17", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc17() {
            return this.loc17;
        }
    
        public void setLoc17(Byte loc17) {
            this.loc17 = loc17;
        }
    
        @Column(name = "loc18", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc18() {
            return this.loc18;
        }
    
        public void setLoc18(Byte loc18) {
            this.loc18 = loc18;
        }
    
        @Column(name = "loc19", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc19() {
            return this.loc19;
        }
    
        public void setLoc19(Byte loc19) {
            this.loc19 = loc19;
        }
    
        @Column(name = "loc20", unique = false, nullable = true, insertable = true, updatable = true)
        public Byte getLoc20() {
            return this.loc20;
        }
    
        public void setLoc20(Byte loc20) {
            this.loc20 = loc20;
        }
    
        @Column(name = "orderstage", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
        public String getOrderstage() {
            return this.orderstage;
        }
    
        public void setOrderstage(String orderstage) {
            this.orderstage = orderstage;
        }
    
        @Column(name = "user", unique = false, nullable = true, insertable = true, updatable = true, length = 64)
        public String getUser() {
            return this.user;
        }
    
        public void setUser(String user) {
            this.user = user;
        }
    
    }
    #279844 Reply

    Girish Pandit
    Participant

    You would have to do something like:

    Add this before your class declaration: @SequenceGenerator (name=”ANYNAME”, sequenceName=”YOUR_SEQ_NAME”)

    add this before getRefnum() method: @GeneratedValue (generator=”ANYNAME_GIVEN_ABOVE”, strategy=GenerationType.SEQUENCE)

    then try it out…it should work.

    #279847 Reply

    amattas
    Member

    When I construct the object what do I set the refnum field to? or do I remove that from the constructor?

    #279853 Reply

    Girish Pandit
    Participant

    do not set value for refnum, leave it blank. I would go with empty constructor and then set values using set method.

    #279854 Reply

    Girish Pandit
    Participant

    when I saw leave it blank means do not call set method on Refnum 🙂

    #279865 Reply

    amattas
    Member

    Alright that worked niceley, but how do I pull the generated refnum out to be used later inthe program?

    #279868 Reply

    Girish Pandit
    Participant

    what ever object that you saved, you have to have that object carried out to other places and you can say obj.getRefnum() and it would give you saved value.

    #279870 Reply

    amattas
    Member

    I tried doing that, and it returns null, I tried doing an entitymanager.refresh() as well to grab the number and had no luck with that

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: EJB 3 – Reverse Engineered Tables, Autogenerated Field

You must be logged in to post in the forum log in