This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes EJB - Sum of a Column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB - Sum of a Column" Watch "EJB - Sum of a Column" New topic
Author

EJB - Sum of a Column

Ajit Kumar
Ranch Hand

Joined: Jan 27, 2001
Posts: 81
hi,
I am using CMP for EJB beans in my project. I would like to get the sum of a particular column in my EJB.
how do i do that.
It cannot be in the entity bean i guess.
My reasoning is based on the fact that each entity bean instance corresponds to a row in the database table.
Hence a method like getSumOfxxx() cannot be part of the behaviour of one particular row.
Should i have to use JDBC from a session EJB?

any ideas?
thanks in advance
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

"My reasoning is based on the fact that each entity bean instance corresponds to a row in the database table."
That's a common misconception. An entity EJB need not be associated with a database at all. It is a requirement that an Entity bean be persistable but the mechanism itself is not that narrowly defined. Just about all CMP beans are persisted via a DBMS, but BMP beans can choose their persistence method.
A SUM() operation by definition is a read-only operation, so you'd have to make your beans read-only as well, but that's a minor detail. In a complex situation or one where the underlying data are going to be accessed in other ways as well you might want to have a session bean act as a facade for a summation of entity beans, but in a simpler case it might be easier to have the entity bean present the sum directly.
But yes, you could do JDBC in a Session bean as well - just be careful - you don't want session database logic colliding with entity database logic.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Don't get me started about those stupid light bulbs.
 
subject: EJB - Sum of a Column
 
Similar Threads
Lifecycle of EJB Objects
[JPA] merge() is inserting instead of updating
How to tell it is EJB 1.1 or EJB 2.0
updates to table
JTable and getValueAt(int, int)