findByPrimaryKey signature

Is it mandatory thatfindByPrimaryKeymethod has only one parameter?

I would like to implement something like this in a BMP Entity Bean:

TestLocal findByPrimaryKey(String table, Long primaryKey)throws FinderException;

wheretable is the name of the table in where to look for theprimaryKey value.

Thanks!

[391 byte] By [q8989989a] at [2007-10-2 5:50:48]
# 1

> Is it mandatory that findByPrimaryKey method

> has only one parameter?

Yes, it's required to have one parameter -- the primary key.

>

> I would like to implement something like this in a

> BMP Entity Bean:

> TestLocal findByPrimaryKey(String table, Long

> primaryKey) throws FinderException;

> where table is the name of the table in where

> to look for the primaryKey value.

You can pass that information in when you create the entity bean.Or, configure it using an env-entry within the bean's component environment (java:comp/env).

>

> Thanks!

ksaksa at 2007-7-16 2:00:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

ksaks , thank you for your answer.

In my scenario, different users may have to retrieve data from different tables simultaneously so the second approach (table name 'hard-coded' in the deployment descriptor) can't be used.

The first approach seems more interesting to me. Here the problem is that users almost never insert new records in the database so the create function is almost never called. I'm thinking not to provide any implementation for the default findByPrimaryKey method (the one with one parameter) and to overload it with a findByPrimaryKey method that takes two parameters.

What do you think about this workaround? Are there better solutions?

q8989989a at 2007-7-16 2:00:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

>

> I'm thinking not to provide

> any implementation for the default

> findByPrimaryKey method (the one with one

> parameter) and to overload it with a

> findByPrimaryKey method that takes two

> parameters.

>

> What do you think about this workaround?

Sounds fine, except you should name it something other than "findByPrimaryKey". The EJB spec assigns certain semantics to a method of that name and expects only a single PK param. You can define as many of your own finders as you'd like, so any other findBy<METHOD> query with any number of parameters will work.

--ken

>Are there

> better solutions?

ksaksa at 2007-7-16 2:00:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
can you guys please read the ejb specs for entity beans.if this is what you wish to achieve then why use entity beans at all.why not use a some java class or include JDBC data access in session beans.
waliva at 2007-7-16 2:00:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Waliv maybe you're right. Maybe I shouldn't try to use entity beans at all. It's the first time I'm playing with EJBs and I thought that since this class does everything an entity bean does (create/update/delete/find records in the db) it may be implemented as an entity bean. The only difference from a 'regular' entity bean (CMP bean) is that it does all this actions each time on a different table (all the tables are identical) and this is why I thought it would be a BMP bean and not a CMP bean. Please tell me if I'm wrong.

Now I have some more questions about how this class can be implemented as a BMP bean. I can specify the table where to create/search for a record in ejbCreate/ejbFind methods. How can I specify the table where to search/delete/update the record in ejbLoad/ejbRemove/ejbStore since these methods are invoked by the container? I抳e tried making table name a private member of the bean class but this doesn抰 seem to work.

Can you please give me some nontrivial examples of BMP beans implementations?

Thanks!

q8989989a at 2007-7-16 2:00:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

i suggest you give a try to CMP.

little code , better configuration options and above all the biggest advantage is that data access layer becomes the full responsibility of the ejb container and not of programmers.

You will be surprised to find out how much more you can achieve in a efficient thread safe and synchronised way with about less than 60% of code that you type in CMp as comapred to BMP.

I can send you over some CMP code for running in Jboss if u intrested.

waliva at 2007-7-16 2:00:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
> I can send you over some CMP code for running in> Jboss if u intrested.Thank youy waliv. You can email me those examples.
q8989989a at 2007-7-16 2:00:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
ok ......you will find my cod ein ur mail soon.
waliva at 2007-7-16 2:00:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...