• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Composite Primary Key in CMP.....?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

Can anybody suggest me a link where can i find a complete source code for CMP using composite primary key. Also give (if anybody has) nice tips to do the same

Thanks in Advance

 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you downloaded the J2EE 1.3/1.4 SDK? I'm assuming that you had. And while downloading the SDK, did you see that link for J2EE 1.3/1.4 tutorial? Inside that tutorial (HTML/PDF), there's a section that contains what you're looking for.
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chengwei ,

Chandu wants the source code. I would suggest Jboss app server. www.jboss.org
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chandu,

Create a Primary Key class with all the fields that it constitutes. The class must implement the serializable interface and the methods in java.lang.Object interface. It must contain an empty constructor too.

Example :
import java.io.Serializable;
public class AdvancedReportingPK implements Serializable {
public Long sequenceNumber;
public String hostName;
public AdvancedReportingPK(Long sequenceNumber, String hostName) {
this.sequenceNumber = sequenceNumber;
this.hostName = hostName;
}
public AdvancedReportingPK() {
}

public String toString() {
return sequenceNumber.toString() + hostName;
}
public int hashCode() {
return sequenceNumber.hashCode();
}

public boolean equals(Object log) {
return ((AdvancedReportingPK) log).sequenceNumber
.equals(sequenceNumber)
&& ((AdvancedReportingPK) log).hostName.equals(hostName);
}
}

Later you have to add the entry of this primary key class in your ejb-jar.xml in the following way:

<entity>
<display-name>AEJB</display-name>
<ejb-name>A</ejb-name>
<local-home>AHome</local-home>
<local>A</local>
<ejb-class>ABean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>AdvancedReportingPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>A</abstract-schema-name>
<cmp-field>
<field-name>sequenceNumber</field-name>
</cmp-field>
<cmp-field>
<field-name>hostName</field-name>
</cmp-field>
<cmp-field>
<field-name>originationTime</field-name>
</cmp-field>
<cmp-field>
<field-name>QID</field-name>
</cmp-field>
</entity>

Hope this helps you.

Thanks
Kala Praveen
 
Chandu Dharmadhikari
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kala Praveen
I was expecting the same response as you have given. But i didn't
understand few things.

1. What is the function of hashCode().
2. How to use findByPrimeryKey with the same.

Please explain me these few things.Thanks all for their prompt
response.

Thanks in Advance
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pradeep,

Originally posted by Pradeep Bhat:
Chengwei ,

Chandu wants the source code. I would suggest Jboss app server. www.jboss.org



Have you checked out the tutorial? Last time that I check it out, the source code example for composite primary key was there.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chandu,

Originally posted by Chandu Dharmadhikari:
1. What is the function of hashCode().
2. How to use findByPrimeryKey with the same.



Perhaps you might wish to consider reading up some tutorials/books that could help you lay a solid foundation.

To find out more of the hashCode & equals method (they come together, in a pair), check this book, Effective Java out. It explains to you what these methods are for & even tells you how to implement them.

As for EJBs, try the J2EE tutorial from Sun. Its free & they've source codes that you could try it out on the application server. Alternatively, there's a free ebook Mastering Enterprise JavaBeans by Ed Roman. Or, there's always Head First EJB. Not forgeting the free EJB specifications.

These are the materials that could get you up in shape & time.
 
kala praveen
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi chandu,

findByPrimaryKey method will be implemented by the container when you mention it in ejb-jar.xml.

you have to implement hashCode & equals method to let the container know how exactly it has to maintain and differentiate between different entity beans internally.

Please refer to the following link:

http://dev2dev.bea.com/pub/a/2002/03/196.html

Thanks
Kala Praveen
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic