ejb@glassfish.java.net

RE: printing composite/foreign keys in the client

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Tue, 14 Aug 2007 09:50:34 +0100

Marina,

I have attached the Iteamdetailsent and Department in a zip file.
And I have also attached CollOrdline with the client. Please, feel free
to edit them. Or maybe I didn't make use of 'bidirectional entity persistence relations'. How do I specified this type of relation in my entities? Or maybe I
did not map my getmethods well. Whatever, the reason, I would appreciate any help.

There is an IdClass in my composite entity CollOrderline. I have attached this as well. There was an issue about this some time ago and I do believe I have done it right but maybe I'm wrong. Please, feel free to edit this as well.

here is an example:




StUDENTsidfnamesurname


Coursecid



discription




ENROLMENTsidcid
















Thanks

eve

> Date: Mon, 13 Aug 2007 10:14:46 -0700
> From: Marina.Vatkina_at_Sun.COM
> To: persistence_at_glassfish.dev.java.net
> CC: ejb_at_glassfish.dev.java.net
> Subject: Re: printing composite/foreign keys in the client
>
> Eve,
>
> I do not see getDeptID() method on Iteamdetailsent. Do you map the FK twice,
> once as a relationship and another time as a field?
>
> Also, CollOrdline does not define an @IdClass - is it a typo?
>
> thanks,
> -marina
>
> Eve Pokua wrote:
> > Hello everyone,
> >
> > I wonder if somebody could provide me with some help.
> >
> > First of all I have two entities relating to each other:
> >
> > public class Iteamdetailsent implements Serializable{
> > ....................
> > @ManyToOne()
> > @JoinColumn(name='DeptID')
> > private Departmentent departmentent;
> > }
> >
> >
> > relating to:
> >
> >
> > public class Departmentent implements java.io.Serializable{
> > ...
> > @OneToMany(mappedBy='departmentent')
> > private Collection <Iteamdetailsent> iteamdetailsent;
> >
> > ...
> > }
> >
> > In the client when I print details as follows:
> >
> > for(Iteamdetailhlp itemlist: iteamdetailhlp){
> >
> > out.println('<TR>');
> >
> >
> > out.println('<td>');out.println(itemlist.getitmid());out.println('</td>');
> >
> > out.println('<td>');out.println(itemlist.getitmname());out.println('</td>');
> >
> > out.println('<td>');out.println(itemlist.getdescription());out.println('</td>');
> >
> > out.println('<td>');out.println(itemlist.getitemsize());out.println('</td>');
> >
> > out.println('<td>');out.println(itemlist.getcolour());out.println('</td>');
> >
> > out.println('<td>');out.println(itemlist.getprice());out.println('</td>');
> >
> > out.println('<td>');out.println( itemlist.getDeptID());out.println('</td>');
> >
> >
> > ...........}
> >
> > The Iteamdetailhlp is a helper class
> >
> > But this last column gives me a null:
> >
> > out.println('<td>');out.println(itemlist.getprice());out.println('</td>');
> >
> > out.println('<td>');out.println( itemlist.getDeptID());out.println('</td>');
> >
> >
> > Itemcode Name Description Size Colour Price
> > 4547887 iris table 17in red 1.20 null
> > 5456865 protey asdf 52in sdf 5.00 null
> > 5468679 opara table 16in pink 12.00 null
> > 5475686 asdf asdf 12inch white 1.02 null
> >
> >
> >
> > Why is this?
> >
> > In the log file I get this:
> >
> > [#|2007-08-13T15:50:10.603+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=15;_ThreadName=httpWorkerThread-8080-1;|All
> > Items:|#]
> >
> >
> > Secondly, i have 3 entities relating to each other. To resolve many to
> > many relationship and from my understanding of DB, I created and entity
> > for composition, containing all the primary keys of all three entities
> > as follows:
> >
> > public class Iteamdetailsent implements Serializable{
> >
> > @Id
> > @Column(name='ITMID', nullable=false)
> > private String itmid;
> >
> > ................
> >
> > }
> >
> >
> >
> > public class Customerent implements Serializable {
> >
> > @Id
> > @Column(name='CUSID', nullable=false)
> > private String cusid;
> >
> > ..................
> > }
> >
> > public class CollOrdersrement implements java.io.Serializable{
> >
> >
> > @Id
> > @Column(name='CollORDID', nullable=false)
> > private String collOrdID;
> >
> > ............
> > }
> >
> > with the composite keys defined in the following class:
> >
> > public class CollOrdline implements java.io.Serializable{
> >
> > private String itmid;
> > private String cusid;
> > private String collOrdID;
> >
> > public CollOrdline(){}
> >
> >
> > @Id
> > public String getitmid(){
> > return itmid;}
> >
> > public void setitmid(String itmid){
> > this.itmid=itmid;}
> >
> > @Id
> > //_at_Column(name = 'CollORDID', nullable = false, insertable = false,
> > updatable = false)
> > public String getcollOrdID(){
> > return collOrdID;}
> >
> > public void setcollOrdID(String collOrdID){
> > this.collOrdID=collOrdID;}
> >
> >
> > @Id
> > public String getcusid()
> > {return cusid;}
> >
> > public void setcusid(String cusid){
> > this.cusid=cusid;
> > }
> >
> >
> >
> > Now when I try to retrieve data from CollOrdline as below:
> >
> > try{
> > InitialContext ctx=new InitialContext();
> > //call the interface
> >
> > collOrdlinerem=(CollOrdlinerem)ctx.lookup('CollOrdersrementJNDI');
> > String sbc='1';
> > String rest;
> > collOrdline=collOrdlinerem.Collpoinordid(sbc);
> > rest=collOrdline.getcollOrdID();
> >
> > System.out.print(rest);
> >
> >
> > }catch(Exception ex){
> > System.err.println('Can not
> > show the collection point order');
> > }
> >
> >
> >
> > I get a null with the following message in my log file:
> >
> > [#|2007-08-13T16:18:36.993+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=15;_ThreadName=httpWorkerThread-8080-1;|
> > null|#]
> >
> > I believe, this has something to do with the way I have specified the
> > relationships. How do I resolve this issue?
> >
> > Any suggestion will be greatly appreciated.
> >
> > Thanks
> >
> > eve
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ------------------------------------------------------------------------
> > Email straight to your blog, upload jokes, photos and more. Windows Live
> > Spaces, it's FREE! <http://specials.uk.msn.com/spaces/default.aspx >

_________________________________________________________________
The next generation of MSN Hotmail has arrived - Windows Live Hotmail
http://www.newhotmail.co.uk