persistence@glassfish.java.net

Re: printing composite/foreign keys in the client

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 15 Aug 2007 19:38:58 -0700

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_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,
> >
> > 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_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
> > > > >
>
> ------------------------------------------------------------------------
> Are you the Quizmaster? Play BrainBattle with a friend now!
> <http://specials.uk.msn.com/brainbattle>