[nbusers] Re: Detail Table with composite primary key

  • From: "Salwa H. Shams" < >
  • To:
  • Subject: [nbusers] Re: Detail Table with composite primary key
  • Date: Sat, 31 Mar 2012 16:10:24 +0300

This is the generated code for Takenservice entity class 
------------------------------------------------------------------------------------------------------------------------------------------
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
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.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author princess
 */
@Entity
@Table(name = "takenservice")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Takenservice.findAll", query = "SELECT t FROM Takenservice t"),
    @NamedQuery(name = "Takenservice.findByResvID", query = "SELECT t FROM Takenservice t WHERE t.takenservicePK.resvID = :resvID"),
    @NamedQuery(name = "Takenservice.findByServID", query = "SELECT t FROM Takenservice t WHERE t.takenservicePK.servID = :servID"),
    @NamedQuery(name = "Takenservice.findByServUsedDate", query = "SELECT t FROM Takenservice t WHERE t.takenservicePK.servUsedDate = :servUsedDate"),
    @NamedQuery(name = "Takenservice.findByPayStat", query = "SELECT t FROM Takenservice t WHERE t.payStat = :payStat"),
    @NamedQuery(name = "Takenservice.findByServRecBy", query = "SELECT t FROM Takenservice t WHERE t.servRecBy = :servRecBy"),
    @NamedQuery(name = "Takenservice.findByPayRecBy", query = "SELECT t FROM Takenservice t WHERE t.payRecBy = :payRecBy"),
    @NamedQuery(name = "Takenservice.findByQuantity", query = "SELECT t FROM Takenservice t WHERE t.quantity = :quantity")})
public class Takenservice implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TakenservicePK takenservicePK;
    @Basic(optional = false)
    @Column(name = "PayStat")
    private String payStat;
    @Basic(optional = false)
    @Column(name = "ServRecBy")
    private String servRecBy;
    @Column(name = "PayRecBy")
    private String payRecBy;
    @Basic(optional = false)
    @Column(name = "Quantity")
    private short quantity;
    @JoinColumn(name = "ServID", referencedColumnName = "ServiceID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Service service;
    @JoinColumn(name = "ResvID", referencedColumnName = "ResvID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Reservation reservation;

    public Takenservice() {
    }

    public Takenservice(TakenservicePK takenservicePK) {
        this.takenservicePK = takenservicePK;
    }

    public Takenservice(TakenservicePK takenservicePK, String payStat, String servRecBy, short quantity) {
        this.takenservicePK = takenservicePK;
        this.payStat = payStat;
        this.servRecBy = servRecBy;
        this.quantity = quantity;
    }

    public Takenservice(int resvID, int servID, Date servUsedDate) {
        this.takenservicePK = new TakenservicePK(resvID, servID, servUsedDate);
    }

    public TakenservicePK getTakenservicePK() {
        return takenservicePK;
    }

    public void setTakenservicePK(TakenservicePK takenservicePK) {
        this.takenservicePK = takenservicePK;
    }

    public String getPayStat() {
        return payStat;
    }

    public void setPayStat(String payStat) {
        this.payStat = payStat;
    }

    public String getServRecBy() {
        return servRecBy;
    }

    public void setServRecBy(String servRecBy) {
        this.servRecBy = servRecBy;
    }

    public String getPayRecBy() {
        return payRecBy;
    }

    public void setPayRecBy(String payRecBy) {
        this.payRecBy = payRecBy;
    }

    public short getQuantity() {
        return quantity;
    }

    public void setQuantity(short quantity) {
        this.quantity = quantity;
    }

    public Service getService() {
        return service;
    }

    public void setService(Service service) {
        this.service = service;
    }

    public Reservation getReservation() {
        return reservation;
    }

    public void setReservation(Reservation reservation) {
        this.reservation = reservation;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (takenservicePK != null ? takenservicePK.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 Takenservice)) {
            return false;
        }
        Takenservice other = (Takenservice) object;
        if ((this.takenservicePK == null && other.takenservicePK != null) || (this.takenservicePK != null && !this.takenservicePK.equals(other.takenservicePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "desktopapplication1.Takenservice[ takenservicePK=" + takenservicePK + " ]";
    }
    
}

-----------------------------------------------------------------------------------------------------------------------------------------------

and this is the code of TakensesrvicePK class 

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author princess
 */
@Embeddable
public class TakenservicePK implements Serializable {
    @Basic(optional = false)
    @Column(name = "ResvID")
    private int resvID;
    @Basic(optional = false)
    @Column(name = "ServID")
    private int servID;
    @Basic(optional = false)
    @Column(name = "ServUsedDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date servUsedDate;

    public TakenservicePK() {
    }

    public TakenservicePK(int resvID, int servID, Date servUsedDate) {
        this.resvID = resvID;
        this.servID = servID;
        this.servUsedDate = servUsedDate;
    }

    public int getResvID() {
        return resvID;
    }

    public void setResvID(int resvID) {
        this.resvID = resvID;
    }

    public int getServID() {
        return servID;
    }

    public void setServID(int servID) {
        this.servID = servID;
    }

    public Date getServUsedDate() {
        return servUsedDate;
    }

    public void setServUsedDate(Date servUsedDate) {
        this.servUsedDate = servUsedDate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) resvID;
        hash += (int) servID;
        hash += (servUsedDate != null ? servUsedDate.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 TakenservicePK)) {
            return false;
        }
        TakenservicePK other = (TakenservicePK) object;
        if (this.resvID != other.resvID) {
            return false;
        }
        if (this.servID != other.servID) {
            return false;
        }
        if ((this.servUsedDate == null && other.servUsedDate != null) || (this.servUsedDate != null && !this.servUsedDate.equals(other.servUsedDate))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "desktopapplication1.TakenservicePK[ resvID=" + resvID + ", servID=" + servID + ", servUsedDate=" + servUsedDate + " ]";
    }
    
}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Other related classes are :

Class Reservation and Class Service, the codes are in the attached file. Thank you so much for your response. 

On Sat, Mar 31, 2012 at 12:08 AM, Javier Ortiz < "> > wrote:

You are not following me. I need the Java code that you use to create entries in the tables.

 

 

Senior Software Quality Engineer

ArthroCare Corporation

7000 William Cannon Drive

Austin, TX 78735

Phone: 512-358-5996

email: " target="_blank">

 

From: Salwa H. Shams [mailto: " target="_blank"> ]
Sent: Friday, March 30, 2012 4:00 PM
To: " target="_blank">
Subject: [nbusers] Re: Detail Table with composite primary key

 

This is my SQL script 

 

CREATE TABLE takenservice (

 ResvID INT UNSIGNED NOT NULL, 

ServID INT UNSIGNED DEFAULT 0 NOT NULL, 

ServUsedDate DATETIME NOT NULL
, PayStat VARCHAR(6) DEFAULT Unpaid NOT NULL,

 ServRecBy VARCHAR(7) NOT NULL,
PayRecBy VARCHAR(7),

 Quantity SMALLINT DEFAULT 1 NOT NULL, 

PRIMARY KEY
(ResvID, ServID, ServUsedDate));

 

 Alter table takenservice add constraint
foreign key (ResvId) references reservation (ResvID);

 

 Alter table
takenservice add constraint foreign key (ResvId) references reservation (ResvID); 

I have generated the entity classes and then created the master detail table with netbeans 7.0. 

 

thanks, 

On Fri, Mar 30, 2012 at 11:44 PM, Javier Ortiz < " target="_blank"> > wrote:

Still we need to see the code used to create the entities.



Senior Software Quality Engineer
ArthroCare Corporation
7000 William Cannon Drive
Austin, TX 78735
Phone: 512-358-5996
email: " target="_blank">



-----Original Message-----
From: Sasha Shams [mailto: " target="_blank"> ]
Sent: Thursday, March 29, 2012 11:24 PM
To: " target="_blank">
Subject: [nbusers] Detail Table with composite primary key

I am working on a project with MySQL database Java GUI.

This is my SQL script CREATE TABLE takenservice ( ResvID INT UNSIGNED NOT NULL, ServID INT UNSIGNED DEFAULT 0 NOT NULL, ServUsedDate DATETIME NOT NULL , PayStat VARCHAR(6) DEFAULT Unpaid NOT NULL, ServRecBy VARCHAR(7) NOT NULL, PayRecBy VARCHAR(7), Quantity SMALLINT DEFAULT 1 NOT NULL, PRIMARY KEY (ResvID, ServID, ServUsedDate)); Alter table takenservice add constraint foreign key (ResvId) references reservation (ResvID); Alter table takenservice add constraint foreign key (ResvId) references reservation (ResvID);

I created the entity classes with Netbeans 7.0 and created 4 classes:

Service Reservation ServiceTaken ServiceTakenPK

but I cant enter values to the table and it gives me an error that I am trying to enter null values in as primary keys.

I have found the bug actually in Netbeans forum which is http://netbeans.org/bugzilla/show_bug.cgi?id=105084.

and accordingly I have added the following methods to the class ServiceTaken

public int getResvID() {
   return takenservicePK.resvID;
}

public int getServID() {
   return takenservicePK.servID;
}

public Date getServUsedDate() {
   return takenservicePK.servUsedDate;
upon inserting a new entry in the table I get this error :

Error Code: 1048 Call: INSERT INTO takenservice (PayRecBy, ServRecBy, Quantity, PayStat, ServUsedDate, ResvID, ServID) VALUES (?, ?, ?, ?, ?, ?,
?) bind => [ddd, ddd, 0, ddd, null, null, null]

What I can do to fix this ? Please help me with this I am running out of time =/

--
View this message in context: http://netbeans-org.1045718.n5.nabble.com/Detail-Table-with-composite-primary-key-tp5605660p5605660.html
Sent from the Netbeans IDE Users mailing list archive at Nabble.com.

**********

The information contained in this e-mail message, together with any
attachments thereto, is intended only for the personal and confidential
use of the addressee named above. The message and the attachments
 are or may be privileged or protected communication. If you are not the
intended recipient of this message, or authorized to receive it for the
intended recipient, you have received this message in error, and you
are not to review, use, disseminate, distribute or copy this message,
any attachments thereto, or their contents. If you have received this
message in error, please immediately notify us by return e-mail
message, and delete the original message.

Pursuant to Circular 230 issued by the United States Treasury
Department and relating to practice before the Internal Revenue
Services, any comment or opinion in this communication relating to a
federal tax issue is not intended to be used, and cannot be used, by a
taxpayer for the purpose of avoiding tax-related penalties that may be
imposed on the taxpayer.

 

**********

The information contained in this e-mail message, together with any
attachments thereto, is intended only for the personal and confidential
use of the addressee named above. The message and the attachments
are or may be privileged or protected communication. If you are not the
intended recipient of this message, or authorized to receive it for the
intended recipient, you have received this message in error, and you
are not to review, use, disseminate, distribute or copy this message,
any attachments thereto, or their contents. If you have received this
message in error, please immediately notify us by return e-mail
message, and delete the original message.

Pursuant to Circular 230 issued by the United States Treasury
Department and relating to practice before the Internal Revenue
Services, any comment or opinion in this communication relating to a
federal tax issue is not intended to be used, and cannot be used, by a
taxpayer for the purpose of avoiding tax-related penalties that may be
imposed on the taxpayer.

Attachment: ReservationandService.txt
Description: Text document



[nbusers] Detail Table with composite primary key

Sasha Shams 03/30/2012

<Possible follow-up(s)>

[nbusers] Detail Table with composite primary key

Sasha Shams 03/30/2012

[nbusers] Re: Detail Table with composite primary key

Javier Ortiz 03/30/2012

[nbusers] Re: Detail Table with composite primary key

Salwa H. Shams 03/30/2012

[nbusers] Re: Detail Table with composite primary key

Javier Ortiz 03/30/2012

[nbusers] Re: Detail Table with composite primary key

Salwa H. Shams 03/31/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close