File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes business logic on cmp field (Entity bean) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "business logic on cmp field (Entity bean)" Watch "business logic on cmp field (Entity bean)" New topic

business logic on cmp field (Entity bean)

Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
App Server: Weblogic 6.1 (CMP2.0)
DB: Oracle 9i
Hi everybody,
I need some clearification on cmp fields. I really appreciate if you can help me on this.
Cmp getXXX and setXXX method can be declared as abstract method. That's what I thgouht. But is this an requirement? For example, suppose a row contains a column called "password", and there is a specific rule, such as at least 8 letter long, or have to include both character and number. abstract method doesn't contain anything that validates the data.
I am design an entity bean, and I need to set valification based on business rule on almost all setXXX getXXX methods. If I want to implement data validation logic on cmp fields, then I have to implement the setXXX getXXX methods by myself and connect to DB directly in ejbStore and ejbLoad methods? If so,it sounds like BMP.
Is it pretty much a requirement for cmp2.0 not to include validation logic? And if I want to, I have to code everything with bmp?
Or there is a way I can set data validation and still get away with coding ejbStore, ejbLoad, or any other methods?
Or you usually do data validation at somewhere else? (client that uses the bean, dd, etc.)

I think it's highly possible that some system just doesn't let anything go into DB due to some business rules. In those situations, what do you do?

Thank you in advance.
Shin Hashitani

/*<br /> * Quants Inc.<br /> * Engineer<br /> *<br /> * Shin Hashitani<br /> *<br /> * <a href="" target="_blank" rel="nofollow"></a><br />*/
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

It's generally considered cleaner to place the business logic in a Session EJB and not in the Entitiy beans (BMP or CMP).
However, there's nothing actually forbidding it and I do regularly include "business" methods that do bulk data transfers in order to avoid the overhead of individual field set/get operations, which can be especially expensive over RMI.

An IDE is no substitute for an Intelligent Developer.
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi Tim,
thank you for your posting.
I just moved business logic to Session Beans that use the EJB. That makes a lot of sense, and code is much cleaner.
I will look into more about Value Object approach you mentioned.
Thank you
I agree. Here's the link:
subject: business logic on cmp field (Entity bean)
It's not a secret anymore!