Thanks for your reply

  but how to edit the row using this Composite-id, i am not worked on this
please suggest me...



Alistair Bush wrote:
> 
>> Hi Matt,
>> 
>>   presently i'm working with appfuse 2.0 (struts2) application. i have
>> one
>> problem how to use composite primary key using hibernate in this
>>  application
> 
> I would suggest using the @EmeddedId
> 
> e.g.
> 
> -- PeriodRegion.java
> 
> package com.app.model;
> 
> import java.io.Serializable;
> import javax.persistence.Basic;
> import javax.persistence.Column;
> import javax.persistence.EmbeddedId;
> import javax.persistence.Entity;
> import javax.persistence.NamedQueries;
> import javax.persistence.NamedQuery;
> import javax.persistence.Table;
> 
> /**
>  *
>  * @author alistair
>  */
> @Entity
> @Table(name = "period_region", catalog = "myproject", schema = "")
> @NamedQueries({...@namedquery(name = "PeriodRegion.findAll", query = "SELECT
> p 
> FROM PeriodRegion p"), @NamedQuery(name = "PeriodRegion.findByPersonid",
> query 
> = "SELECT p FROM PeriodRegion p WHERE p.periodRegionPK.personid =
> :personid"), 
> @NamedQuery(name = "PeriodRegion.findByRegionid", query = "SELECT p FROM 
> PeriodRegion p WHERE p.periodRegionPK.regionid = :regionid"),
> @NamedQuery(name 
> = "PeriodRegion.findByPaid", query = "SELECT p FROM PeriodRegion p WHERE
> p.paid 
> = :paid")})
> public class PeriodRegion implements Serializable {
>     private static final long serialVersionUID = 1L;
>     @EmbeddedId
>     protected PeriodRegionPK periodRegionPK;
>     @Basic(optional = false)
>     @Column(name = "paid", nullable = false)
>     private boolean paid;
> 
>     public PeriodRegion() {
>     }
> 
>     public PeriodRegion(PeriodRegionPK periodRegionPK) {
>         this.periodRegionPK = periodRegionPK;
>     }
> 
>     public PeriodRegion(PeriodRegionPK periodRegionPK, boolean paid) {
>         this.periodRegionPK = periodRegionPK;
>         this.paid = paid;
>     }
> 
>     public PeriodRegion(long personid, long regionid) {
>         this.periodRegionPK = new PeriodRegionPK(personid, regionid);
>     }
> 
>     public PeriodRegionPK getPeriodRegionPK() {
>         return periodRegionPK;
>     }
> 
>     public void setPeriodRegionPK(PeriodRegionPK periodRegionPK) {
>         this.periodRegionPK = periodRegionPK;
>     }
> 
>     public boolean getPaid() {
>         return paid;
>     }
> 
>     public void setPaid(boolean paid) {
>         this.paid = paid;
>     }
> 
>     @Override
>     public int hashCode() {
>         int hash = 0;
>         hash += (periodRegionPK != null ? periodRegionPK.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 PeriodRegion)) {
>             return false;
>         }
>         PeriodRegion other = (PeriodRegion) object;
>         if ((this.periodRegionPK == null && other.periodRegionPK != null)
> || 
> (this.periodRegionPK != null && 
> !this.periodRegionPK.equals(other.periodRegionPK))) {
>             return false;
>         }
>         return true;
>     }
> 
>     @Override
>     public String toString() {
>         return "PeriodRegion[periodRegionPK=" + periodRegionPK + "]";
>     }
> 
> }
> 
> -- PeriodRegionPK.java
> 
> package com.app.model;
> 
> import java.io.Serializable;
> import javax.persistence.Basic;
> import javax.persistence.Column;
> import javax.persistence.Embeddable;
> 
> /**
>  *
>  * @author alistair
>  */
> @Embeddable
> public class PeriodRegionPK implements Serializable {
>     @Basic(optional = false)
>     @Column(name = "personid", nullable = false)
>     private long personid;
>     @Basic(optional = false)
>     @Column(name = "regionid", nullable = false)
>     private long regionid;
> 
>     public PeriodRegionPK() {
>     }
> 
>     public PeriodRegionPK(long personid, long regionid) {
>         this.personid = personid;
>         this.regionid = regionid;
>     }
> 
>     public long getPersonid() {
>         return personid;
>     }
> 
>     public void setPersonid(long personid) {
>         this.personid = personid;
>     }
> 
>     public long getRegionid() {
>         return regionid;
>     }
> 
>     public void setRegionid(long regionid) {
>         this.regionid = regionid;
>     }
> 
>     @Override
>     public int hashCode() {
>         int hash = 0;
>         hash += (int) personid;
>         hash += (int) regionid;
>         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 PeriodRegionPK)) {
>             return false;
>         }
>         PeriodRegionPK other = (PeriodRegionPK) object;
>         if (this.personid != other.personid) {
>             return false;
>         }
>         if (this.regionid != other.regionid) {
>             return false;
>         }
>         return true;
>     }
> 
>     @Override
>     public String toString() {
>         return "com.counties.app.model.PeriodRegionPK[personid=" +
> personid + 
> ", regionid=" + regionid + "]";
>     }
> 
> }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net
> For additional commands, e-mail: users-h...@appfuse.dev.java.net
> 
> 
> 


-----
---
Sudhakar
-- 
View this message in context: 
http://www.nabble.com/Composite-primary-key-problem-in-appfuse-2.0-%28struts2%29-tp25506686s2369p25508115.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net
For additional commands, e-mail: users-h...@appfuse.dev.java.net

Reply via email to