• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB - Sum of a Column

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic