Jump to content

Java Ee Help


Sparda
 Share

Recommended Posts

I have been trying to get a set of CMP entity beans to try and work together for a couple days. I am having particular trouble with a many to many relation ship.

Lets say there are two entity classes Class1 and ClassA. These have a many to many relation ship.

Let's say I create a list of Class1 objects then place it in to the list in ClassA (using the method ClassA.setClass1List(class1List)). This is populated in to the database fine. I can also call ClassA.getClass1List and that works as expected. However, if I call Class1.getClassAList the entity manager throws an exception saying that the relation ship is not populated.

It also seems that the table that creates the many to many relationship only populates when the set method on Class1 is called, populating the tables from ClassA does not work.

Am I missing something? I bet it's some thing stupid and obvious.

Does any one actually use Java EE?

Link to comment
Share on other sites

  • 2 weeks later...

Well, if any one is interested I sort of figured this out. Basically the entity manager doesn't get the relational objects unless you try to do some thing with the list of objects (performance++ makes_sense++ causes_weird_problems ++).

So for example, if you do the following:

return Class1.getClassAList();

That returns a empty list. If on the other hand you do this:

List<ClassA> classAList = Class1.getClassAList();

classAList.iterator(); // the does nothing but has to be here function call

return classAList;

It should work every time. I think it's rather mad in that way. I suspect the reason behind this is that Java EE expects you do do stuff with the objects when they are in the EJB and controlled by the entity manager. So if you return a object that is controlled by the entity manager to a servlet they loss there 'connection' to the entity manager, and when you call there methods you get all sorts of exceptions.

I'm still probably doing some thing wrong though.

Link to comment
Share on other sites

  • 3 weeks later...

I'm sure no one cares at this point but any way. Basically all these problems I was having are down to caching (quite obviously). However, I have previously not looked into it because it's supposed to be more or less automatic*. Well, that's sort of true. Since this was only a small program and I didn't care about performance even slightly I just disabled caching all together (every document I read said not to do this for obvious reasons, but it fixed the problems). For anyone who cares (I assume no one because Java EE is rather not fun to work with when it goes wrong) basically you need to consider the purpose of each class that goes in to the database and apply different caching rules to each class for it to work properly with decent performance (or turn off caching and have no performance but it slowly works perfectly).

*Java EE is supposed apply suitable automatic caching rules to each class based on what links it has to other classes and how they propagate. Apparently it doesn't work or my program was confusing it (some of the classes had three relationships) or glassfish is slow (true regardless) and the caching process takes longer than it takes the next page to load... several times... over a period of minuets while pressing F5.

tl;dr: I think I'd much rather write a CORBA program that has a web based front end that is driven by Java EE sessions beans than have to write another Java EE program that uses entity beans.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...