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
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).]
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Aug 13, 2001
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