persistence@glassfish.java.net

Re: Recommendation - on Id/Embedable ID classes

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Thu, 17 Jan 2008 08:11:27 -0500

The spec requires that each entity has an ID field. In this case you
can add a field that drives its value from the FK.

*_at_Entity
@Table(name="COLLECTPOINTITEMS")*
*public class Collectpointitems implements java.io.Serializable{

@Id
    @ Column (name = "ITMID"**, insertable=false, updateable=false)*
* private String itmid;
* **
* @OneToOne()
 @JoinColumn(name="ITMID")
        private Iteamdetailsent iteamdetailsent;
 @Column(name="LOCATION", nullable=true, length=20)
 private String location;

public void set**Iteamdetailsent(**Iteamdetailsent **iteamdetailsent){
    this.iteamdetailsent = **iteamdetailsent;
     this.itmid = iteamdetailsent.getItmid();
}
**..................}*

-- Gordon

Eve Pokua wrote:
>
> Hello everyone,
> I have an entity:
>
> *public class Iteamdetailsent implements Serializable{
> //
> @Id
> @Column(name="ITMID", nullable=false, length=8)
> private String itmid;
> @Column(name="ITMNAME", nullable=true, length=40)
> private String itmname;
> @Column(name="DESCRIPTION", nullable=true, length=200)*
> *..................}*
>
> OUt of this entity, I would like to create other entities
> (Collectpointitems and Self_serveent)
> which would have the Id 'String itmid' from Iteamdetailsent as a
> foriegn key. reason why is
> Collectionpointent and Self_serveent are the only items within the
> Iteamdetailsent entity which requires extra attributes. e.g.
>
> *_at_Entity
> @Table(name="COLLECTPOINTITEMS")*
> *public class Collectpointitems implements java.io.Serializable{*
> **
> * @OneToOne()
> @JoinColumn(name="ITMID")
> private Iteamdetailsent iteamdetailsent;
> @Column(name="LOCATION", nullable=true, length=20)
> private String location;*
> *..................}*
>
> Now when I try to compile build or deploy it, it's no surprising, it
> ask for an Id
> And as you can see I do not need the it within these entities as I am
> trying to create it as if Iteamdetailsent is the parent class where
> Collectpointitems is developed from it; because, Collectpointitems whould
> have all the attributes of Iteamdetailsent and it's own attributes.
> To explain myself further, the Collectpointitems and Self_serent are
> all items kept in a warehouse. And as a result, customers requires the
> location to pick these items up. Whereas, all the other items as store
> within the shop floor. and do not need the Location attribute.
> My question is should I include the location attribute in Iteamdetailsent
> so that there would be no need to create the other entities
> (Collectpointitems)
> i.e:
>
> *public class Iteamdetailsent implements Serializable{
> //
> @Id
> @Column(name="ITMID", nullable=false, length=8)
> private String itmid;
> @Column(name="ITMNAME", nullable=true, length=40)
> private String itmname;
> @Column(name="DESCRIPTION", nullable=true, length=200)
> @Column(name="LOCATION", nullable=true, length=20)
> private String location;*
> * *
> *..................}*
>
> Or should I separate them? And if so, what do I do about
> the ID issue? Should I just generate ID when data is entered,
> but make not use of it? What should I do?
>
> eve
>
>
> ------------------------------------------------------------------------
> Everything in one place. All new Windows Live!
> <http://www.windowslive.co.uk/get-live>