Results 1 to 19 of 19
Like Tree1Likes
  • 1 Post By crystalclearwater

Thread: Persistance-API / Entity Class

  1. #1
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Persistance-API / Entity Class

    Hi guys,

    Iam a newbie to Java and working on my first Java-GUI. The Gui have access to a Firebird database.
    At the moment I have a problem with Save my Data. I will try to explain well defined my problem.

    At the time I use 3 Tables in my Database with references to each other.
    Table: KUNDE, VORGANG, VORGANG_AUGENPAAR

    KUNDE.KUNDENNUMMER = VORGANG.KUNDENNUMMER
    VORGANG.ID = VORGANG_AUGENPAAR.VORGANG_ID

    For this I use 4 entity classes (Kunde, Vorgang, VorgangAugenpaar and VorgangAugenpaarPK)
    In my application I could insert with "newButton" a new Kunde (customer) with Adress etc.
    Also I could insert a new Vorgang (the KUNDENNUMMER is automatically filled in) with "newDetailButton1"
    But I could not inser a new Vorgang_Augenpaar. For this purpose the VORGANG_ID should automatically filled in but I guess there is may failure.

    At the time Iam a beginner with the persistance api and I suppose that this is my problem.

    This is my log file:
    run:
    [EL Info]: 2013-02-05 08:45:09.544--ServerSession(1685985802)--EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
    [EL Info]: 2013-02-05 08:45:09.919--ServerSession(1685985802)--file:/D:/netbeans/OpticaNuova/build/classes/_OpticaNuovaPU login successful
    [EL Warning]: 2013-02-05 08:45:27.09--UnitOfWork(469288094)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseExcepti on
    javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseExcepti on
    Internal Exception: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544347. validation error for column VORGANG_ID, value "*** null ***"
    Error Code: 335544347
    Internal Exception: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544347. validation error for column VORGANG_ID, value "*** null ***"
    Call: INSERT INTO VORGANG_AUGENPAAR (LINSE_PROTOKOLL, LINSE_STATUS, PRODUKT_ID, REF_LINSE_DATUM, REF_LINSE_LI_ACHSE, REF_LINSE_LI_ADD, REF_LINSE_LI_BC, REF_LINSE_LI_CYL, REF_LINSE_LI_DIA, REF_LINSE_LI_SPH, REF_LINSE_RE_ACHSE, REF_LINSE_RE_ADD, REF_LINSE_RE_BC, REF_LINSE_RE_CYL, REF_LINSE_RE_DIA, REF_LINSE_RE_SPH, AUGENPAAR_ID, VORGANG_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    Error Code: 335544347
    bind => [18 parameters bound]
    Query: InsertObjectQuery(opticanuova.ui.VorgangAugenpaar[ vorgangAugenpaarPK=null ])
    Could you please help me to change my entity classes. I attached my classes and the gui-form "Formular_Kunden"
    (I could not add any attachements. I will try it again in few minutes)
    Last edited by crystalclearwater; 02-05-2013 at 09:50 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    What is the definition of the VORGANG_AUGENPAAR.VORGANG_ID field?
    I'm presuming it is NOT NULL.

    How are you creating a new VORGANG_AUGENPAAR?
    What does the Java class for that look like?
    How is it mapped to the table?
    How is the foreign key mapped?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    Hi,

    I suppose my bug is in VorgangAugenpaar class. I use this code
    @EmbeddedId
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_augenpaar_id")
    protected VorgangAugenpaarPK vorgangAugenpaarPK;
    .......

    @PrimaryKeyJoinColumn(name = "VORGANG_ID", referencedColumnName = "ID")
    @ManyToOne
    private Vorgang vorgangId;
    Last edited by crystalclearwater; 02-06-2013 at 07:29 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    I don't download stuff/
    Copy/paste into the forum.
    If it's too much for that then it's too much for a forum to handle.

    Why do you have a PK class?
    Your PK is simply an ID field.

    When you create (and persist) your VorgangAugenpaar, does it have a valid Vorgang object for the vorgangId?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    Why do you have a PK class?
    I donīt know exactly why. Because I generated the Entity Class with Netbeans-Gui Designer and then I made some changes. So the PK class was automatically generated.

    When you create (and persist) your VorgangAugenpaar, does it have a valid Vorgang object for the vorgangId?
    Yes it have. When I put the VORGANG_ID into my table itīs the correct number. I think I made somethin wrong

    ok, so here it is the code for the Vorgang Class:
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package opticanuova.task;
    
    import java.beans.PropertyChangeListener;
    import java.beans.PropertyChangeSupport;
    import java.io.Serializable;
    import java.util.Collection;
    import java.util.Date;
    import javax.persistence.Basic;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.PrimaryKeyJoinColumn;
    import javax.persistence.SequenceGenerator;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    import javax.persistence.Transient;
    import javax.xml.bind.annotation.XmlRootElement;
    import opticanuova.task.TaskManager;
    /**
     *
     * @author User
     */
    @Entity
    @Table(name = "VORGANG")
    @SequenceGenerator(name="seq_vorgang_id", sequenceName="seq_vorgang_id", initialValue=1, allocationSize=1)
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Vorgang.findAll", query = "SELECT v FROM Vorgang v"),
        @NamedQuery(name = "Vorgang.findById", query = "SELECT v FROM Vorgang v WHERE v.id = :id"),
        @NamedQuery(name = "Vorgang.findByUserid", query = "SELECT v FROM Vorgang v WHERE v.userid = :userid"),
        @NamedQuery(name = "Vorgang.findByStatus", query = "SELECT v FROM Vorgang v WHERE v.status = :status"),
        @NamedQuery(name = "Vorgang.findByRefBrilleReSph", query = "SELECT v FROM Vorgang v WHERE v.refBrilleReSph = :refBrilleReSph"),
        @NamedQuery(name = "Vorgang.findByRefBrilleReCyl", query = "SELECT v FROM Vorgang v WHERE v.refBrilleReCyl = :refBrilleReCyl"),
        @NamedQuery(name = "Vorgang.findByRefBrilleReAchse", query = "SELECT v FROM Vorgang v WHERE v.refBrilleReAchse = :refBrilleReAchse"),
        @NamedQuery(name = "Vorgang.findByRefBrilleLiSph", query = "SELECT v FROM Vorgang v WHERE v.refBrilleLiSph = :refBrilleLiSph"),
        @NamedQuery(name = "Vorgang.findByRefBrilleLiCyl", query = "SELECT v FROM Vorgang v WHERE v.refBrilleLiCyl = :refBrilleLiCyl"),
        @NamedQuery(name = "Vorgang.findByRefBrilleLiAchse", query = "SELECT v FROM Vorgang v WHERE v.refBrilleLiAchse = :refBrilleLiAchse"),
        @NamedQuery(name = "Vorgang.findByRefBrilleDatum", query = "SELECT v FROM Vorgang v WHERE v.refBrilleDatum = :refBrilleDatum"),
        @NamedQuery(name = "Vorgang.findByBrilleStatus", query = "SELECT v FROM Vorgang v WHERE v.brilleStatus = :brilleStatus")
        })
    public class Vorgang implements Serializable {
        @Transient
        private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
        private static final long serialVersionUID = 1L;
        @Id
        @Basic(optional = false)
        @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_vorgang_id")
        @Column(name = "ID")
        private Integer id;
        @Basic(optional = false)
        @Column(name = "USERID")
        private String userid;
        @Basic(optional = false)
        @Column(name = "STATUS")
        private int status;
        // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
        @Column(name = "REF_BRILLE_RE_SPH")
        private Double refBrilleReSph;
        @Column(name = "REF_BRILLE_RE_CYL")
        private Double refBrilleReCyl;
        @Column(name = "REF_BRILLE_RE_ACHSE")
        private Double refBrilleReAchse;
        @Column(name = "REF_BRILLE_LI_SPH")
        private Double refBrilleLiSph;
        @Column(name = "REF_BRILLE_LI_CYL")
        private Double refBrilleLiCyl;
        @Column(name = "REF_BRILLE_LI_ACHSE")
        private Double refBrilleLiAchse;
        @Column(name = "REF_BRILLE_DATUM")
        @Temporal(TemporalType.DATE)
        private Date refBrilleDatum;
        @Column(name = "BRILLE_STATUS")
        private Integer brilleStatus;
        @Column(name = "BRILLE_PROTOKOLL")
        private String brilleProtokoll;
        @JoinColumn(name = "KUNDENNUMMER", referencedColumnName = "KUNDENNUMMER")
        //@PrimaryKeyJoinColumn(name = "KUNDENNUMMER", referencedColumnName = "KUNDENNUMMER")  
        @ManyToOne(optional = false)
        private Kunde kundennummer;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "vorgangId")
        private Collection<VorgangAugenpaar> vorgangAugenpaarCollection;
    
        public Vorgang() {
        }
    
        public Vorgang(Integer id) {
            this.id = id;
        }
    
        public Vorgang(Integer id, String userid, int status) {
            this.id = id;
            this.userid = userid;
            this.status = status;
        }
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            Integer oldId = this.id;
            this.id = id;
            changeSupport.firePropertyChange("id", oldId, id);
        }
    
        public String getUserid() {
            return userid;
        }
    
        public void setUserid(String userid) {
            String oldUserid = this.userid;
            this.userid = userid;
            changeSupport.firePropertyChange("userid", oldUserid, userid);
        }
    
        public int getStatus() {
            return status;
        }
    
        public void setStatus(int status) {
            int oldStatus = this.status;
            this.status = status;
            changeSupport.firePropertyChange("status", oldStatus, status);
        }
    
        public Double getRefBrilleReSph() {
            return refBrilleReSph;
        }
    
        public void setRefBrilleReSph(Double refBrilleReSph) {
            Double oldRefBrilleReSph = this.refBrilleReSph;
            this.refBrilleReSph = refBrilleReSph;
            changeSupport.firePropertyChange("refBrilleReSph", oldRefBrilleReSph, refBrilleReSph);
        }
    
        public Double getRefBrilleReCyl() {
            return refBrilleReCyl;
        }
    
        public void setRefBrilleReCyl(Double refBrilleReCyl) {
            Double oldRefBrilleReCyl = this.refBrilleReCyl;
            this.refBrilleReCyl = refBrilleReCyl;
            
            changeSupport.firePropertyChange("refBrilleReCyl", oldRefBrilleReCyl, refBrilleReCyl);
        }
    
        public Double getRefBrilleReAchse() {
            return refBrilleReAchse;
        }
    
        public void setRefBrilleReAchse(Double refBrilleReAchse) {
            Double oldRefBrilleReAchse = this.refBrilleReAchse;
            this.refBrilleReAchse = refBrilleReAchse;
            changeSupport.firePropertyChange("refBrilleReAchse", oldRefBrilleReAchse, refBrilleReAchse);
        }
    
        public Double getRefBrilleLiSph() {
            return refBrilleLiSph;
        }
    
        public void setRefBrilleLiSph(Double refBrilleLiSph) {
            Double oldRefBrilleLiSph = this.refBrilleLiSph;
            this.refBrilleLiSph = refBrilleLiSph;
            changeSupport.firePropertyChange("refBrilleLiSph", oldRefBrilleLiSph, refBrilleLiSph);
        }
    
        public Double getRefBrilleLiCyl() {
            return refBrilleLiCyl;
        }
    
        public void setRefBrilleLiCyl(Double refBrilleLiCyl) {
            Double oldRefBrilleLiCyl = this.refBrilleLiCyl;
            this.refBrilleLiCyl = refBrilleLiCyl;
            changeSupport.firePropertyChange("refBrilleLiCyl", oldRefBrilleLiCyl, refBrilleLiCyl);
        }
    
        public Double getRefBrilleLiAchse() {
            return refBrilleLiAchse;
        }
    
        public void setRefBrilleLiAchse(Double refBrilleLiAchse) {
            Double oldRefBrilleLiAchse = this.refBrilleLiAchse;
            this.refBrilleLiAchse = refBrilleLiAchse;
            changeSupport.firePropertyChange("refBrilleLiAchse", oldRefBrilleLiAchse, refBrilleLiAchse);
        }
    
        public Date getRefBrilleDatum() {
            return refBrilleDatum;
        }
    
        public void setRefBrilleDatum(Date refBrilleDatum) {
            Date oldRefBrilleDatum = this.refBrilleDatum;
            this.refBrilleDatum = refBrilleDatum;
            changeSupport.firePropertyChange("refBrilleDatum", oldRefBrilleDatum, refBrilleDatum);
        }
    
        public Integer getBrilleStatus() {
            return brilleStatus;
        }
    
        public void setBrilleStatus(Integer brilleStatus) {
            Integer oldBrilleStatus = this.brilleStatus;
            this.brilleStatus = brilleStatus;
            changeSupport.firePropertyChange("brilleStatus", oldBrilleStatus, brilleStatus);
        }
    
          
        public String getBrilleProtokoll() {
            return brilleProtokoll;
        }
    
        public void setBrilleProtokoll(String brilleProtkoll) {
            String oldBrilleProtokoll = this.brilleProtokoll;
            this.brilleProtokoll = brilleProtkoll;
            changeSupport.firePropertyChange("brilleProtokoll", oldBrilleProtokoll, brilleProtokoll);
        }
    
        
        public Kunde getKundennummer() {
            return kundennummer;
        }
    
        public void setKundennummer(Kunde kundennummer) {
            Kunde oldKundennummer = this.kundennummer;
            this.kundennummer = kundennummer;
            changeSupport.firePropertyChange("kundennummer", oldKundennummer, kundennummer);
        }
    
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        }
    
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Vorgang)) {
                return false;
            }
            Vorgang other = (Vorgang) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            }
            return true;
        }
    
        @Override
        public String toString() {
            return "opticanuova.Vorgang[ id=" + id + " ]";
        }
    
        public void addPropertyChangeListener(PropertyChangeListener listener) {
            changeSupport.addPropertyChangeListener(listener);
        }
    
        public void removePropertyChangeListener(PropertyChangeListener listener) {
            changeSupport.removePropertyChangeListener(listener);
        }
    
        public Collection<VorgangAugenpaar> getVorgangAugenpaarCollection() {
            return vorgangAugenpaarCollection;
        }
    
        public void setVorgangAugenpaarCollection(Collection<VorgangAugenpaar> vorgangAugenpaarCollection) {
            this.vorgangAugenpaarCollection = vorgangAugenpaarCollection;
        }
    
        }
    ok, so here it is the code for the VorgangAugenpaar Class:

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package opticanuova.task;
    
    import java.beans.PropertyChangeListener;
    import java.beans.PropertyChangeSupport;
    import java.io.Serializable;
    import java.util.Date;
    import javax.persistence.Column;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Id;
    import javax.persistence.Entity;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    import javax.persistence.Transient;
    import opticanuova.task.Vorgang;
    import javax.persistence.SequenceGenerator;
    import javax.persistence.OneToOne;
    import javax.persistence.PrimaryKeyJoinColumn;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import opticanuova.task.Kunde;
    
    /**
     *
     * @author User
     */
    @Entity
    @Table(name = "VORGANG_AUGENPAAR", catalog = "", schema = "")
    @SequenceGenerator(name="seq_augenpaar_id", sequenceName="seq_augenpaar_id", initialValue=1, allocationSize=1)
    @NamedQueries({
        @NamedQuery(name = "VorgangAugenpaar.findAll", query = "SELECT v FROM VorgangAugenpaar v"),
        @NamedQuery(name = "VorgangAugenpaar.findByVorgangId", query = "SELECT v FROM VorgangAugenpaar v WHERE v.vorgangAugenpaarPK.vorgangId = :vorgangId"),
        @NamedQuery(name = "VorgangAugenpaar.findByAugenpaarId", query = "SELECT v FROM VorgangAugenpaar v WHERE v.vorgangAugenpaarPK.augenpaarId = :augenpaarId"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseReSph", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseReSph = :refLinseReSph"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseReCyl", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseReCyl = :refLinseReCyl"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseReAchse", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseReAchse = :refLinseReAchse"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseReDia", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseReDia = :refLinseReDia"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseReBc", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseReBc = :refLinseReBc"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseLiSph", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseLiSph = :refLinseLiSph"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseLiCyl", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseLiCyl = :refLinseLiCyl"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseLiAchse", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseLiAchse = :refLinseLiAchse"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseLiDia", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseLiDia = :refLinseLiDia"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseLiBc", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseLiBc = :refLinseLiBc"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseDatum", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseDatum = :refLinseDatum"),
        @NamedQuery(name = "VorgangAugenpaar.findByLinseStatus", query = "SELECT v FROM VorgangAugenpaar v WHERE v.linseStatus = :linseStatus"),
        @NamedQuery(name = "VorgangAugenpaar.findByLinseProtokoll", query = "SELECT v FROM VorgangAugenpaar v WHERE v.linseProtokoll = :linseProtokoll"),
        @NamedQuery(name = "VorgangAugenpaar.findByProduktId", query = "SELECT v FROM VorgangAugenpaar v WHERE v.produktId = :produktId"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseReAdd", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseReAdd = :refLinseReAdd"),
        @NamedQuery(name = "VorgangAugenpaar.findByRefLinseLiAdd", query = "SELECT v FROM VorgangAugenpaar v WHERE v.refLinseLiAdd = :refLinseLiAdd")})
    public class VorgangAugenpaar implements Serializable {
        @Transient
        private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
        private static final long serialVersionUID = 1L;
        @EmbeddedId
        @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_augenpaar_id")
        protected VorgangAugenpaarPK vorgangAugenpaarPK;
        // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
        @Column(name = "REF_LINSE_RE_SPH")
        private Double refLinseReSph;
        @Column(name = "REF_LINSE_RE_CYL")
        private Double refLinseReCyl;
        @Column(name = "REF_LINSE_RE_ACHSE")
        private Double refLinseReAchse;
        @Column(name = "REF_LINSE_RE_DIA")
        private Double refLinseReDia;
        @Column(name = "REF_LINSE_RE_BC")
        private Double refLinseReBc;
        @Column(name = "REF_LINSE_LI_SPH")
        private Double refLinseLiSph;
        @Column(name = "REF_LINSE_LI_CYL")
        private Double refLinseLiCyl;
        @Column(name = "REF_LINSE_LI_ACHSE")
        private Double refLinseLiAchse;
        @Column(name = "REF_LINSE_LI_DIA")
        private Double refLinseLiDia;
        @Column(name = "REF_LINSE_LI_BC")
        private Double refLinseLiBc;
        @Column(name = "REF_LINSE_DATUM")
        @Temporal(TemporalType.DATE)
        private Date refLinseDatum;
        @Column(name = "LINSE_STATUS")
        private Integer linseStatus;
        @Column(name = "LINSE_PROTOKOLL")
        private String linseProtokoll;
        @Column(name = "PRODUKT_ID")
        private Integer produktId;
        @Column(name = "REF_LINSE_RE_ADD")
        private Double refLinseReAdd;
        @Column(name = "REF_LINSE_LI_ADD")
        private Double refLinseLiAdd;
        //@JoinColumn(name = "VORGANG_ID", referencedColumnName = "ID")
        @PrimaryKeyJoinColumn(name = "VORGANG_ID", referencedColumnName = "ID")
        @ManyToOne
        private Vorgang vorgangId;
           	
        public VorgangAugenpaar() {
        }
    
        public VorgangAugenpaar(VorgangAugenpaarPK vorgangAugenpaarPK) {
            this.vorgangAugenpaarPK = vorgangAugenpaarPK;
        }
    
        public VorgangAugenpaar(int vorgangId, int augenpaarId) {
            this.vorgangAugenpaarPK = new VorgangAugenpaarPK(vorgangId, augenpaarId);
        }
    
        public VorgangAugenpaarPK getVorgangAugenpaarPK() {
            return vorgangAugenpaarPK;
        }
    
        public void setVorgangAugenpaarPK(VorgangAugenpaarPK vorgangAugenpaarPK) {
            this.vorgangAugenpaarPK = vorgangAugenpaarPK;
        }
    
        public Double getRefLinseReSph() {
            return refLinseReSph;
        }
    
        public void setRefLinseReSph(Double refLinseReSph) {
            Double oldRefLinseReSph = this.refLinseReSph;
            this.refLinseReSph = refLinseReSph;
            changeSupport.firePropertyChange("refLinseReSph", oldRefLinseReSph, refLinseReSph);
        }
    
        public Double getRefLinseReCyl() {
            return refLinseReCyl;
        }
    
        public void setRefLinseReCyl(Double refLinseReCyl) {
            Double oldRefLinseReCyl = this.refLinseReCyl;
            this.refLinseReCyl = refLinseReCyl;
            changeSupport.firePropertyChange("refLinseReCyl", oldRefLinseReCyl, refLinseReCyl);
        }
    
        public Double getRefLinseReAchse() {
            return refLinseReAchse;
        }
    
        public void setRefLinseReAchse(Double refLinseReAchse) {
            Double oldRefLinseReAchse = this.refLinseReAchse;
            this.refLinseReAchse = refLinseReAchse;
            changeSupport.firePropertyChange("refLinseReAchse", oldRefLinseReAchse, refLinseReAchse);
        }
    
        public Double getRefLinseReDia() {
            return refLinseReDia;
        }
    
        public void setRefLinseReDia(Double refLinseReDia) {
            Double oldRefLinseReDia = this.refLinseReDia;
            this.refLinseReDia = refLinseReDia;
            changeSupport.firePropertyChange("refLinseReDia", oldRefLinseReDia, refLinseReDia);
        }
    
        public Double getRefLinseReBc() {
            return refLinseReBc;
        }
    
        public void setRefLinseReBc(Double refLinseReBc) {
            Double oldRefLinseReBc = this.refLinseReBc;
            this.refLinseReBc = refLinseReBc;
            changeSupport.firePropertyChange("refLinseReBc", oldRefLinseReBc, refLinseReBc);
        }
    
        public Double getRefLinseLiSph() {
            return refLinseLiSph;
        }
    
        public void setRefLinseLiSph(Double refLinseLiSph) {
            Double oldRefLinseLiSph = this.refLinseLiSph;
            this.refLinseLiSph = refLinseLiSph;
            changeSupport.firePropertyChange("refLinseLiSph", oldRefLinseLiSph, refLinseLiSph);
        }
    
        public Double getRefLinseLiCyl() {
            return refLinseLiCyl;
        }
    
        public void setRefLinseLiCyl(Double refLinseLiCyl) {
            Double oldRefLinseLiCyl = this.refLinseLiCyl;
            this.refLinseLiCyl = refLinseLiCyl;
            changeSupport.firePropertyChange("refLinseLiCyl", oldRefLinseLiCyl, refLinseLiCyl);
        }
    
        public Double getRefLinseLiAchse() {
            return refLinseLiAchse;
        }
    
        public void setRefLinseLiAchse(Double refLinseLiAchse) {
            Double oldRefLinseLiAchse = this.refLinseLiAchse;
            this.refLinseLiAchse = refLinseLiAchse;
            changeSupport.firePropertyChange("refLinseLiAchse", oldRefLinseLiAchse, refLinseLiAchse);
        }
    
        public Double getRefLinseLiDia() {
            return refLinseLiDia;
        }
    
        public void setRefLinseLiDia(Double refLinseLiDia) {
            Double oldRefLinseLiDia = this.refLinseLiDia;
            this.refLinseLiDia = refLinseLiDia;
            changeSupport.firePropertyChange("refLinseLiDia", oldRefLinseLiDia, refLinseLiDia);
        }
    
        public Double getRefLinseLiBc() {
            return refLinseLiBc;
        }
    
        public void setRefLinseLiBc(Double refLinseLiBc) {
            Double oldRefLinseLiBc = this.refLinseLiBc;
            this.refLinseLiBc = refLinseLiBc;
            changeSupport.firePropertyChange("refLinseLiBc", oldRefLinseLiBc, refLinseLiBc);
        }
    
        public Date getRefLinseDatum() {
            return refLinseDatum;
        }
    
        public void setRefLinseDatum(Date refLinseDatum) {
            Date oldRefLinseDatum = this.refLinseDatum;
            this.refLinseDatum = refLinseDatum;
            changeSupport.firePropertyChange("refLinseDatum", oldRefLinseDatum, refLinseDatum);
        }
    
        public Integer getLinseStatus() {
            return linseStatus;
        }
    
        public void setLinseStatus(Integer linseStatus) {
            Integer oldLinseStatus = this.linseStatus;
            this.linseStatus = linseStatus;
            changeSupport.firePropertyChange("linseStatus", oldLinseStatus, linseStatus);
        }
    
        public String getLinseProtokoll() {
            return linseProtokoll;
        }
    
        public void setLinseProtokoll(String linseProtokoll) {
            String oldLinseProtokoll = this.linseProtokoll;
            this.linseProtokoll = linseProtokoll;
            changeSupport.firePropertyChange("linseProtokoll", oldLinseProtokoll, linseProtokoll);
        }
    
        public Integer getProduktId() {
            return produktId;
        }
    
        public void setProduktId(Integer produktId) {
            Integer oldProduktId = this.produktId;
            this.produktId = produktId;
            changeSupport.firePropertyChange("produktId", oldProduktId, produktId);
        }
    
        public Double getRefLinseReAdd() {
            return refLinseReAdd;
        }
    
        public void setRefLinseReAdd(Double refLinseReAdd) {
            Double oldRefLinseReAdd = this.refLinseReAdd;
            this.refLinseReAdd = refLinseReAdd;
            changeSupport.firePropertyChange("refLinseReAdd", oldRefLinseReAdd, refLinseReAdd);
        }
    
        public Double getRefLinseLiAdd() {
            return refLinseLiAdd;
        }
    
        public void setRefLinseLiAdd(Double refLinseLiAdd) {
            Double oldRefLinseLiAdd = this.refLinseLiAdd;
            this.refLinseLiAdd = refLinseLiAdd;
            changeSupport.firePropertyChange("refLinseLiAdd", oldRefLinseLiAdd, refLinseLiAdd);
        }
    
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (vorgangAugenpaarPK != null ? vorgangAugenpaarPK.hashCode() : 0);
            return hash;
        }
    
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof VorgangAugenpaar)) {
                return false;
            }
            VorgangAugenpaar other = (VorgangAugenpaar) object;
            if ((this.vorgangAugenpaarPK == null && other.vorgangAugenpaarPK != null) || (this.vorgangAugenpaarPK != null && !this.vorgangAugenpaarPK.equals(other.vorgangAugenpaarPK))) {
                return false;
            }
            return true;
        }
    
        @Override
        public String toString() {
            return "opticanuova.ui.VorgangAugenpaar[ vorgangAugenpaarPK=" + vorgangAugenpaarPK + " ]";
        }
    
        public Vorgang getVorgangId() {
            return vorgangId;
        }
    
        public void setVorgangId(Vorgang vorgangId) {
            Vorgang oldVorgangId = this.vorgangId;
            this.vorgangId = vorgangId;
            changeSupport.firePropertyChange("vorgangId", oldVorgangId, vorgangId);
        }
    
        public void addPropertyChangeListener(PropertyChangeListener listener) {
            changeSupport.addPropertyChangeListener(listener);
        }
    
        public void removePropertyChangeListener(PropertyChangeListener listener) {
            changeSupport.removePropertyChangeListener(listener);
        }
    
       
    }
    ok, so here it is the code for the VorgangAugenpaarPK Class:
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package opticanuova.task;
    
    import java.io.Serializable;
    import javax.persistence.Basic;
    import javax.persistence.Column;
    import javax.persistence.Embeddable;
    
    /**
     *
     * @author User
     */
    @Embeddable
    public class VorgangAugenpaarPK implements Serializable {
        @Basic(optional = false)
        @Column(name = "VORGANG_ID")
        private int vorgangId;
        @Basic(optional = false)
        @Column(name = "AUGENPAAR_ID")
        private int augenpaarId;
    
        public VorgangAugenpaarPK() {
        }
    
        public VorgangAugenpaarPK(int vorgangId, int augenpaarId) {
            this.vorgangId = vorgangId;
            this.augenpaarId = augenpaarId;
        }
    
        public int getVorgangId() {
            return vorgangId;
        }
    
        public void setVorgangId(int vorgangId) {
            this.vorgangId = vorgangId;
        }
    
        public int getAugenpaarId() {
            return augenpaarId;
        }
    
        public void setAugenpaarId(int augenpaarId) {
            this.augenpaarId = augenpaarId;
        }
    
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (int) vorgangId;
            hash += (int) augenpaarId;
            return hash;
        }
    
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof VorgangAugenpaarPK)) {
                return false;
            }
            VorgangAugenpaarPK other = (VorgangAugenpaarPK) object;
            if (this.vorgangId != other.vorgangId) {
                return false;
            }
            if (this.augenpaarId != other.augenpaarId) {
                return false;
            }
            return true;
        }
    
        @Override
        public String toString() {
            return "opticanuova.ui.VorgangAugenpaarPK[ vorgangId=" + vorgangId + ", augenpaarId=" + augenpaarId + " ]";
        }
        
    }
    So, then I try to insert values with "new" Button. Maybe its somethin wrong with this code:
    Java Code:
        private void newDetailButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
            int index = masterTable.getSelectedRow();
            opticanuova.task.Vorgang V = list.get(masterTable.convertRowIndexToModel(index));
            Collection<opticanuova.task.VorgangAugenpaar> vs = V.getVorgangAugenpaarCollection();
            if (vs == null) {
                vs = new LinkedList<opticanuova.task.VorgangAugenpaar>();
                V.setVorgangAugenpaarCollection((List) vs);
            }
            opticanuova.task.VorgangAugenpaar v = new opticanuova.task.VorgangAugenpaar();
            entityManager.persist(v);
            v.setVorgangId(V);
            vs.add(v);
            masterTable.clearSelection();
            masterTable.setRowSelectionInterval(index, index);
            int row = vs.size() - 1;
            detailTable.setRowSelectionInterval(row, row);
            detailTable.scrollRectToVisible(detailTable.getCellRect(row, 0, true));
        }

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    Java Code:
        opticanuova.task.VorgangAugenpaar v = new opticanuova.task.VorgangAugenpaar();
        entityManager.persist(v);
    You are persisting the new entity before setting any values.
    You should set the values then persist.
    That's why the foreign key is null.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    Hi,

    thank you for your question why I use "Augenpaar_Vorgang_PK". I made some changes with the constraints in my database, and now it works also without "Augenpaar_Vorgang_PK" class.
    But now I have another problem/question. I use three tables that are in correlation to each other

    KUNDE.KUNDENNUMMER -> VORGANG.KUNDENNUMMER
    VORGANG.ID -> VORGANG_AUGENPAAR.VORGANG_ID

    First I choose my customer in the masterTable, then the detailTable show me all the rows from VORGANG to this customer = OK.
    Now my subTable shows me all the rows from VORGANG_AUGENPAAR to this VORGANG = OK

    But I have a logic problem, if I want to insert a new VORGANG_AUGENPAAR row. For the insert is it necessary to get the right VORGANG.ID.
    In my detailTable the VORGANG.ID is printed out in the right way.
    So could you please help my to made my code correct. At the time I use this:

    Java Code:
    int index = detailTable.getSelectedRow();
            opticanuova.task.Vorgang vo = vorgangList.get(detailTable.convertRowIndexToModel(index));
            Collection<opticanuova.task.VorgangAugenpaar> vs = vo.getVorgangAugenpaarCollection();
            System.out.println(vo + "collection");
    The bug is, that "index" give me the selected row back (already filtered by the customernumber). But vorgangList give me the "index-numbers" of all rows from VORGANG in the database back.
    So what can I do, that this work? How do I have to change my code?
    The right "value" of the "VORGANG_AUGENPAAR.VORGANG.ID" is already stored in my detailTable. So is it possible, that I donīt need to go accross selectedRow(index) and could for example: selectedRow(third column.value)?

    Do you understand my explanations?
    You could see the image with my red circle. The ID = 650 (detailTable) and the ID if I go accross index = 550

    Persistance-API / Entity Class-forum.png
    Last edited by crystalclearwater; 02-06-2013 at 03:18 PM.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    I'm guessing that detailTable contains some List of VorgangAugenpaar as it's TableModel?
    So why not get the value out of that list?

    I suppose it comes down to how are you populating the tableModel for that JTable?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    Hi,

    yes you are right. But how could I get the value for the selected row - 3rd column with java? Or it would be better if I could have the value of the selected row, where the name of column = ID (see picture above)
    I guess I have to use something like this detailTable.getSelectedRow();

    Please give me your advise.

    kind regards

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    You need to read up on tables and table models.
    The table will give you the selected row, which will allow you to access the actual data held in the table model.
    But for that to work properly you should have a table model that works with your classes.

    Here's the Oracle tutorial for JTable which covers all of this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    Hi guys

    I am to be at a loss. I read the tutorial but as a newbe to Java I coultnīt solve my problem. So I try to explain my problem well defined. In my gui I work with 3 tables:
    - masterTable
    - detailTable
    - subTable

    The masterTable contains customers (with unique ID). In my detailTable I also have the field customer-ID. So I made a binding (java-persistance api). If I select one row in the masterTable then the values of the customer is shown me in my detail Table.
    Now my problem is to get new data in my third Table (subTable). Please see my post on this topic from 02-06-2013, 03:00 PM. In the subTable a need a value from the detailTable.

    If I work with (detailTable):
    Java Code:
    int index1 = detailTable.convertRowIndexToModel(detailTable.getSelectedRow());
    int index = detailTable.getSelectedRow();
    opticanuova.task.Vorgang vo = vorgangList.get( detailTable.convertRowIndexToModel( index ) );
    then I have following issue:
    For Example I get value "2" on index back
    Then I put this value to vorgangList. But I get the "2" value of the complete vorgangList Model and this is wrong because in vorgangList Model there is the data without filtering. So the "2" row in vorgangList is different to the "2" row that print in the detail table.

    I have read that normally this is why you should use "convertRowIndexToModel" (see index and index1).

    Please give my your advices.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    You need to use the TableModel.
    Get the data you are interested in from there.
    Use that data to find (and this will involve searching) the correct value in your main List.
    All the indexes in the detailTable relate to the List used by that table's model, and are not related to the main List.

    You will have to write code to get the relevant id(s) from the detailTable and use that to search in the vorgangList for the relevant entry.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    Ok, so please help me to do my next step.
    Now I have following code:

    Java Code:
            int selectedRowIndex = detailTable.getSelectedRow();
            int selectedColumnIndex = 2;
            int selectedObject = (int) detailTable.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
    Within the "selectedObject" I have my unique ID of the detailTable. How could I find the correct ID within my main list (vorgangList). In the vorgangList there are stored all entries of this model.
    Could you tell me the correct java syntax?

    Best regards

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    Well, you seem to be trying to find it in the List, so you have to loop through the List looking for the one with that ID.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  15. #15
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    But how could I compare the vorgangList with detailTable Model ?

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    OK, I'll try and describe what I think it is you are trying to do.
    You have GUI-Table X.
    GUI-Table X represents data from DB-Table X which has a one-to-many with DB-Table Y.
    Select something on GUI-Table X and it populates data into GUI-Table Y based on that relationship.
    You now want to add something to GUI-Y, which has to have the right X-ID in it.

    In order to get that ID you can simply find the selected row GUI-X, and extract the ID.

    The code you have in post #13 seems to extract that ID (assuming that's what's in column 2).
    I just don't see where the problem lies now?
    Surely you can just create your Y-row using that ID?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  17. #17
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    Hi, my problem ist that I find the correct index number of vorgangList. I dont know exactly how to loop threw. So please help me.
    with this code:
    Java Code:
    for (int len = vorgangList.size(), i = 0; i < len; i++) {
      Vorgang s = vorgangList.get(i);
      System.out.println("Index " + i + " = " + s);
    }
    I get this result:
    Index 0 = opticanuova.Vorgang[ id=400 ]
    Index 1 = opticanuova.Vorgang[ id=450 ]
    Index 2 = opticanuova.Vorgang[ id=500 ]
    Index 3 = opticanuova.Vorgang[ id=550 ]
    Index 4 = opticanuova.Vorgang[ id=600 ]
    Index 5 = opticanuova.Vorgang[ id=650 ]
    Index 6 = opticanuova.Vorgang[ id=700 ]

    and so on...

    with this code:
    Java Code:
    opticanuova.task.Vorgang match = vorgangList.get(selectedRowIndexInModel);
            int selectedObject = (int) detailTable.getModel().getValueAt(selectedRowIndexInModel, idColumnIndex);
    I get this results:
    opticanuova.Vorgang[ id=550 ] = list (this would be index #3 in vorgangLIst and index #3 in detailTable Model)
    600 = selectedRowIndexInModel (this would be index #4 in vorgangList and index #3 in detailTable Model)

    So I get the correct ID Number (=600) but the wrong index. So I have to find the correct index number to ID 600 in vorgangList.

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Persistance-API / Entity Class

    Java Code:
    opticanuova.task.Vorgang match = vorgangList.get(selectedRowIndexInModel);
            int selectedObject = (int) detailTable.getModel().getValueAt(selectedRowIndexInModel, idColumnIndex);
    OK.
    That first line is wrong, as you are using the index in the table model to access the value from some other List.
    The second is correct in order to get the ID of the thing you then want to find.
    Presumably 'selectedObject' is 600?
    If so then you need to loop through the List and find the Vorgang whose ID is 600.
    I mean your first code bit in post #17 is looping over the list.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  19. #19
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Persistance-API / Entity Class

    Hi tolls,

    now I have find the correct solution. Thanks for your efforts.
    So actually this is my code:
    Java Code:
    //find selected value
            int selectedObject = (int) detailTable.getModel().getValueAt(selectedRowIndexInModel, idColumnIndex);
            //find ID:
            for(int i = 0; i < vorgangList.size(); i++) {
                Vorgang vorgangs = vorgangList.get(i);
                if (vorgangs.getId().equals(selectedObject) == true) {
                System.out.println(vorgangs.getId() + " getId " + vorgangList.get(i));    
                }
                }
    Well, now I know how it works and it looks so simple. lol
    best regards
    rf
    DarrylBurke likes this.

Similar Threads

  1. Replies: 4
    Last Post: 06-09-2012, 09:30 PM
  2. I can't use Entity Class (JPA) in Netbeans7.0 .
    By mmc01 in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-19-2011, 10:56 AM
  3. error in creating the entity class by netbeans
    By javastuden in forum NetBeans
    Replies: 2
    Last Post: 07-22-2011, 01:29 PM
  4. Replies: 4
    Last Post: 05-13-2011, 10:04 PM
  5. persistance error
    By videanuadrian in forum New To Java
    Replies: 5
    Last Post: 12-09-2010, 10:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •