Using 2.0 CMP, how do I map the fields of my compound primary key to fields in the database?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alex_Chaffee
Posted On:   Wednesday, December 12, 2001 03:21 PM

Here's a partial answer: In your DD, declare the element com.wombat.empl.EmployeeID If you do this, and use a compound key, then you must not declare a element (which you would do with a simple (primitive) primary key). Instead, according to the DTD: The primkey-field element is not used if the primary key maps to multiple container-managed fields (i.e. the key is a compound key). In this case, the fields of the primary key class must be public, and their names must correspond to the field names of the entity bean class that comprise the key. I think this means that the EJB Container is going to use reflection to find out the names of you   More>>

Here's a partial answer:


In your DD, declare the element

			
com.wombat.empl.EmployeeID

If you do this, and use a compound key, then you must not declare a element (which you would do with a simple (primitive) primary key). Instead, according to the DTD:

The primkey-field element is not used if the primary key maps to
multiple container-managed fields (i.e. the key is a compound key). In
this case, the fields of the primary key class must be public, and
their names must correspond to the field names of the entity bean
class that comprise the key.

I think this means that the EJB Container is going to use reflection to find out the names of your compound key's getX and setX methods (like a real JavaBeans Introspector), and assume that your compound key's public fields have a one-to-one correspondence to real persistent fields in your main bean class.

   <<Less

Re: Using 2.0 CMP, how do I map the fields of my compound primary key to fields in the database?

Posted By:   Alex_Chaffee  
Posted On:   Wednesday, December 12, 2001 03:46 PM

The above should say, "your compound key's public instance variables" (instead of "getX and setX methods (like a real JavaBeans Introspector)") -- I've now verified that it works that way.
About | Sitemap | Contact