Hello everyone,
I believe I have identitied where this problem lies especailly between my
and
In my client, I am using my helper class (Iteamdetailhlp) to print details from the database.
try{ InitialContext ctx=new InitialContext(); Iteamdetails iteamdetails=(Iteamdetails)ctx.lookup("IteamdetailsBeanJNDI"); iteamdetailhlp=iteamdetails.BargainCornItems(barconr); out.println("<TABLE BORDER='1' CELLPADDING='3' CELLSPACING='1'>"); out.println("<TR>"); out.println("<td>" +"Itemcode");out.println("<td>" +"Name"); out.println("<td>" +"Description"); out.println("<td>" +"Size"); out.println("<td>" +"Colour");out.println("<td>" +"Price");out.println("</td>"); out.println("</TR>"); for(Iteamdetailhlp itemlist: iteamdetailhlp){ out.println("<TR>"); out.println("<form method='get' action='AllItemsser'>"); 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>"); out.println("</td>");
But I was having issues linking the helper class to the my Departmentent,
So this would not work:
public String toString() { String s = itmid + " " + itmname +" " + description + " "+ itemsize + " " + colour + " " + price + " " + departmentent;
return s; }
This is why the departmentent above in the toString() does not work because, there is
no relationship between this class the related class. However, my entity class (Iteamdetailsent)
is mapped and related to the Departmentent entity.
How do I go about this? Any ideas?
Thanks
eve
From: gorgeous65_at_msn.comTo: persistence_at_glassfish.dev.java.netCC: ejb_at_glassfish.dev.java.netDate: Thu, 16 Aug 2007 15:52:11 +0100Subject: RE: printing composite/foreign keys in the client
Hello everyone,I have made changes to methods of my classes. I understand this mistake was causing someconfusion. Please, see attached.Thankseve
From: gorgeous65@msn.comTo: persistence@glassfish.dev.java.netCC: ejb@glassfish.dev.java.netDate: Thu, 16 Aug 2007 12:38:59 +0100Subject: RE: printing composite/foreign keys in the clienthi,> Iteamdetailsent.toString()I believe this is what you are talking about: public String toString() { String s = itmid + ' ' + itmname +' ' + description + ' '+ itemsize + ' ' + colour + ' ' + price + ' ' + departmentent; return s; }it is mapped at the being of the class: @ManyToOne() @JoinColumn(name='DeptID') private Departmentent departmentent;although, I am not sure if I should map these as well:public Departmentent getDeptID(){ return departmentent;} public void setDeptID(Departmentent departmentent){ this.departmentent=departmentent;}This is all in the Iteamdetailsent classI will make more changes and see if it works.Thanks eve> Date: Wed, 15 Aug 2007 19:38:58 -0700> From: Marina.Vatkina@Sun.COM> To: persistence@glassfish.dev.java.net> CC: ejb@glassfish.dev.java.net> Subject: Re: printing composite/foreign keys in the client> > Eve,> > Eve Pokua wrote:> > Thanks Marina,> > > > I will try and clean them up as much as possible. I have commented most > > out for testing. Just a few questions:> > > > b) You current example prints the departmentent object ref. Does it > > print null?> > > > Are you refering this to the client AllItem??> > Iteamdetailsent.toString()> > > > > > d) Your properties are not capitalized in CollOrdline - that's not a > > JavaBean style.> > > > Sorry! Do you mean I have to state the mothods or variable? capital? > > Please, explain yourself. I am still learning or I might have ignore > > certain java styles.> > Bear with me please.> > JavaBean style properties mean having getFoo/setFoo methods to represent > property named 'foo'.> > > > > e) 'iteamdetailsent' is not initialized - are you sure you set it up?> > > > which of the client are you refering to?? AllItem?/> > Departmentent. It's not only that the client will be creating new instances, but > the JPA provider as well.> > HTH,> -marina> > > > Thanks> > > > eve> > > > > > > > > Date: Tue, 14 Aug 2007 12:52:40 -0700> > > From: Marina.Vatkina@Sun.COM> > > To: persistence@glassfish.dev.java.net> > > CC: ejb@glassfish.dev.java.net> > > Subject: Re: printing composite/foreign keys in the client> > >> > > Eve,> > >> > > Can you cleanup your example? This is a quick list of things that can > > or cannot> > > affect the results, but will make the example(s) easier to read:> > >> > > a) There are too many commented out lines so it's not clear if you > > used them for> > > testing or not.> > > b) You current example prints the departmentent object ref. Does it > > print null?> > > c) Your CollOrdlinementKey has other fields besides ids - if they are > > not used,> > > please remove them.> > > d) Your properties are not capitalized in CollOrdline - that's not a > > JavaBean style.> > > e) 'iteamdetailsent' is not initialized - are you sure you set it up? > > TLE caches> > > objects as-is, so if you didn't set that relationship, it will be > > null until you> > > refresh the instance.> > >> > > thanks,> > > -marina> > >> > > Eve Pokua wrote:> > > > 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:> > > >> > > >> > > > StUDENT> > > >> > > >> > > > sid> > > >> > > >> > > > fname> > > >> > > >> > > > surname> > > >> > > >> > > > Course> > > >> > > >> > > > cid> > > >> > > > discription> > > >> > > >> > > > ENROLMENT> > > >> > > >> > > > sid> > > >> > > >> > > > cid> > > >> > > >> > > >> > > >> > > > Thanks> > > >> > > > eve> > > >> > > > > Date: Mon, 13 Aug 2007 10:14:46 -0700> > > > > From: Marina.Vatkina@Sun.COM> > > > > To: persistence@glassfish.dev.java.net> > > > > CC: ejb@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> > > > > > //@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> > > > > >> > > > ------------------------------------------------------------------------> > Are you the Quizmaster? Play BrainBattle with a friend now! > > <
http://specials.uk.msn.com/brainbattle>
The next generation of MSN Hotmail has arrived - Windows Live Hotmail
Play Movie Mash-up and win BIG prizes!
_________________________________________________________________
The next generation of MSN Hotmail has arrived - Windows Live Hotmail
http://www.newhotmail.co.uk