Solved

Entity EJB Design question

Posted on 2004-08-29
8
270 Views
Last Modified: 2013-11-24
I'm creating an Entity EJB using Bean Managed Persistence, which could be fairly complex.  It's would represent an object whose data spans multiple DB tables and the fields consist of some potentially large objects (input streams). The cost of storing and loading this info to and from the DB would be fairly high.  This object is essentially representing a program whose code and associated include files are stored in the DB. There are certain attributes that will be used quite a bit more often than others, for example the name, description etc. will be looked up often to generate a list of these programs available to the end-user. Where as the large program files and include files will be used less often only when a user chooses to run the program.  All the attributes will need to be modifiable. I want to avoid having to do the expensive reads and writes of the large attributes every time the ejbLoad and ejbStore methods are called, and only do them when needed. I have a few ideas but I wanted expert input:

1. Create two Entity Beans to model the object. One will contain the commonly used display attributes and the other will contain the less commonly used functional attributes. This will give an easy separation of the object and allow the expensive read/write calls to be used only when needed.  I’m not sure if this will lead to integrity issues since a remove of one will necessitate a removal of the other, and this might cause problems.

2. Use only one Entity EJB and instead of having all the fields in the DB be instance variables of the EJB and be loaded and stored with each call of the ejbStore or ejbLoad. For the large and expensive fields I would create methods that pull and load those fields only when explicitly asked for or changed. To me this seems like the best solution but it doesn’t seem to fit in with the idea of Entity Beans but I’m not too sure, I’m very new to EJBs.

I’m sure there are other possible approaches too. Any input is greatly appreciated.

Thanks
David
0
Comment
Question by:NHBFighter
8 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11929075
We had a similar problem though not using EJBs but Hibernate. We did something similar to your first approach, we had one bean represent the commonest/less expensive data and a second bean representing the *all* data. Then it was matter of what we needed to load. The whole data represented binary stuff which was expensive to load up and most of the time we did not need to load it. So we were mainly calling the less expensive bean (the one that represented mainly primitive type data) and only called the "expensive" bean when we really had to. This was a good approach and saved us processing power and memory. The only drawback was that we had to write a separate class and a separate XML mapping for the "less expensive" bean, which was not a big deal if you think about it.

With regards to your approach two, you could do that but indeed it does break the concept of entity beans. If you want to strictly follow the EJB specification better avoid it, but if you really think it is the solution then you might as well go for it.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11929092
Even I would say that the first approach sounds good to me. The idea of dividing the roles amongst two beans is more acceptible, mainly because:

>> allow the expensive read/write calls to be used only when needed

Do have a good hands-on with EJBs or do you also want some links to the EJB specification, tutorials, etc?
0
 
LVL 4

Author Comment

by:NHBFighter
ID: 11932284
Thankks for the input, I'm just learning EJBs but I'm getting a fairly good handle on it and I've done lots of reading on them but any links would help.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 35

Accepted Solution

by:
girionis earned 84 total points
ID: 11933146
I'd say the best place is this one: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 83 total points
ID: 11939314
You can also try: http://www.ejbtut.com
0
 
LVL 6

Assisted Solution

by:valipotor
valipotor earned 83 total points
ID: 11951320

The best book on ejbs i'v ever read is Mastering EJB, now second edition, available here
http://www.theserverside.com/

valipotor
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ArrayIndexOutOfBoundException 9 80
egit plugin on eclipse 8 62
HashTable highest marks enumeration alternative 9 37
MySQL  on Tomcat 8 43
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question