• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compound Keys in EJB

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to implement compound keys in a CMP bean. Is it sufficient to define the two primary key fields in the ejb-jar.xml file ? How do I use the hashcode methods for creating a record using the compound key.
VIKI
 
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A compound key is implemented by defining a Primary Key class which contains the two (or more) key fields as public member variables. The exact hashcode algorithm is up to you - you'll want to create an algorithm that gives a good spread over the hash range and has minimal collisions. It's used by the bean server to rapidly determine if the bean is in cache and, if so, return it - it's not used by the create functions except to add the bean to the cache hashtable.
A quick way of creating a compound key EJB is to use the EJBWizard tool at http://www.mousetech.com/EJBWizard.html - on the panel where you define the persistent data, there's a column named "key". Non-key-fields have a key value of 0. Set the first key component to "1", the second to "2", and so forth. It generates a fairly basic generic hash algorithm which should suffice for many cases.
[This message has been edited by Tim Holloway (edited August 14, 2001).]
 
VIKI AG
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi TIM,
Thanks for the same. I have already implemented the compound key with the same approach as U have referred to.
I'm facing a different problem right now. I'm able to add data into the database, but the browser throws an error.
"Error 500--Internal Server Error
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.5.1 500 Internal Server Error
The server encountered an unexpected condition which prevented it from fulfilling the request."
I'm using Weblogic 5.1, SQL 7.0 (sorry for not mentioning it earlier)
I'm using one int variable and the other is String variable(which I have converted into int before using the composite hashcode value)
The problem that is happening is that, the same value of the int variable is being picked again when I try to insert another record with the same variable value set.
Get back, if you could find it.
Thanks
VIKI
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic