Enterprise JavaBeans - Primary key class in ejbCreate method
Dear all,
In an entity bean class (either cmp or bmp), consider the following two ejbCreate methods:
public CustomerPK ejbCreate(CustomerPK pk,String custName) {...}
public CustomerPK ejbCreate(int pk,String custName) {...}
Sometimes I saw people directly passing an instance of the primary key class and sometimes pass an int although they both return an instance of the primary key class.
Which one is recommended and what are their differences?
Thanks in advance.
[509 byte] By [
HELLOOOOa] at [2007-11-26 23:13:28]

# 1
There's no requirement that the arguments to the create method have any specific type association
with the bean's defined primary key.The requirement is just that the return type have the type of
the primary key.The component developer has complete freedom to decide what pieces of information
need to be passed in to the create method to produce the primary key.As such, there isn't really
a recommended one. It's just a matter of how best to expose the entity bean creation to the
entity bean clients, which is largely application-dependent.
--ken
ksaksa at 2007-7-10 14:11:38 >

# 3
Depends on what you want to expose to the client. If you have a complex primary key you might
not want to force the client to conjure up one of them just to call the create method. You might
also have some derived information you use for the primary key that doesn't need to be passed
in directly.
ksaksa at 2007-7-10 14:11:38 >
