ejb@glassfish.java.net

RE: Recommendation - on Id/Embedable ID classes

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Fri, 18 Jan 2008 23:40:46 +0000

Thank you Gordon,
 
this works.
 
eve


Date: Thu, 17 Jan 2008 08:11:27 -0500From: gordon.yorke_at_oracle.comTo: persistence_at_glassfish.dev.java.netCC: ejb_at_glassfish.dev.java.netSubject: Re: Recommendation - on Id/Embedable ID classes
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{_at_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 setIteamdetailsent(Iteamdetailsent iteamdetailsent){ this.iteamdetailsent = iteamdetailsent; this.itmid = iteamdetailsent.getItmid();}..................}-- GordonEve 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 isCollectionpointent and Self_serveent are the only items within theIteamdetailsent 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 IdAnd as you can see I do not need the it within these entities as I amtrying to create it as if Iteamdetailsent is the parent class where Collectpointitems is developed from it; because, Collectpointitems whouldhave all the attributes of Iteamdetailsent and it's own attributes.To explain myself further, the Collectpointitems and Self_serent areall items kept in a warehouse. And as a result, customers requires thelocation to pick these items up. Whereas, all the other items as storewithin the shop floor. and do not need the Location attribute.My question is should I include the location attribute in Iteamdetailsentso 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 aboutthe 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!
_________________________________________________________________
Share what Santa brought you
https://www.mycooluncool.com