just kidding with cmp...

A

Andrea Sansottera

Hi all guys,
I'm looking for a few suggestions on ejb cmp. I'm using j2ee sdk 1.4,
pointbase database server.
1) I have too check for the values of a few properties of an entity bean
before they are stored on the database. For example, I have in my bean
class:

public abstract void setAcidity(double acidity);

but I want, for instance, acidity to be greater than -4... how can I do
this? Should I use bean managed persistance and write jdbc code for *all*
the properties of my entity bean class?

2) Again... I want to allow some method calls only to the users which have
the "employer" role, but they should also have a certain value on certain
field of a column (editable=true), otherwise the operation should not be
done... shall I do this only with bean managed persistance?

Thanks a lot, any suggestion is appreciated.

Andrea
 
P

Phillip Mills

Andrea Sansottera said:
but I want, for instance, acidity to be greater than -4... how can I do
this?

What you are describing are business rules. Normally, those would be
implemented in a layer above the persistence level.

For example, some session bean might have an addItem() or updateItem()
method that took a number of parameters and validated them before
setting entity bean properties.

The same design can be applied to your second example, possibly combined
with a finder method that checks the appropriate column using EJB QL.
 
A

Andrea Sansottera

Thanks for the good advice... so I'm going to create a new tier:

web tier (user interface)
session beans (business rules)
entity beans
database tables (automatically generated)

Is it right?

Another question: why should I not create a cmp ejb with no persistance
fields? It has to have only two foreign keys (that is, relationship fields)...
 
S

Sudsy

Andrea said:
Thanks for the good advice... so I'm going to create a new tier:

web tier (user interface)
session beans (business rules)
entity beans
database tables (automatically generated)

Is it right?

Congrats! You have arrived at the architecture most commonly used and
recommended. Mr. Mills offered sagacious advice.
I like this approach as it removes dependency on the underlying data
store. Things like stored procedures and triggers are non-portable.
Ever try to port Progress triggers to Oracle PL/SQL? :-(
 
A

Andrea Sansottera

Congrats! You have arrived at the architecture most commonly used and
recommended. Mr. Mills offered sagacious advice.
I like this approach as it removes dependency on the underlying data
store. Things like stored procedures and triggers are non-portable.

I'm happy what I'm learning is right :)
Ever try to port Progress triggers to Oracle PL/SQL? :-(

I'm not very found on SQL's advanced features and I've never used Oracle
(too expansive)...
 
P

Phillip Mills

Andrea Sansottera said:
Another question: why should I not create a cmp ejb with no persistance
fields? It has to have only two foreign keys (that is, relationship
fields)...

If you mean for many-to-many relationships, usually you can let CMR take
care of that for you.

For example:
A BooksEB can return a Collection from a getReaders() method and a
ReadersEB can have getBooks() and the right CMR descriptors will just
make it work. However, I'm always a bit nervous when I do this because
some day I may want to know the date that Reader X first borrowed Book
Y. That information would belong in the connecting table, which --
unless someone knows some interesting tricks -- would mean replacing the
CMR with an explicit table/entity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top