Hi Guys,

I am pretty new to EJBs and jBoss - we are currently evaluating jBoss as a
possible alternative for our
current BizObj / OR mapper middle tier.

My configuration is jBoss2.0 Prod Final against PostgreSQL on RH7.0. I
started playing with EntityBeans 
and CMP - here are my questions after taking EntityBeans in JBoss for a
first spin:

1) Where are all the queries from?
----------------------------------

I code a very simple bean with 2 CMP managed fields (the Ship bean from ch5
in RMH). The following code 

code: ...
code:   Ship s = home.findByPrimaryKey(pk);
code:   System.out.println(s.getPrimaryKey() + s.getName() + s.getCode());
code:   ...

works but produces the following SQL queries (from the postgres log):

query: SELECT COUNT(*) FROM ShipBean WHERE id=2
query: SELECT tonnage,capacity,name,id FROM ShipBean WHERE id=2
query: UPDATE ShipBean SET tonnage=80000.0,capacity=3000,name='Utopia',id=2
WHERE id=2
query: UPDATE ShipBean SET tonnage=80000.0,capacity=3000,name='Utopia',id=2
WHERE id=2

The first query is useless - if it is a PK values lookup, it should only
come back with 0 or 1.
The second query is what's needed. Where are the queries 3 and 4 from? There
is no set called
anywhere in my code at all - in fact the output in the code above is all the
app is doing.

It get's worse when looking at finder methods which return collections. Here
is an example:

code: ...
code:   Collection c = home.findByCapacity(3000);
code: ... looping over collection, narrowing of each item to s, and 
code:   System.out.println(s.getPrimaryKey() + s.getName() + s.getCode());
code:   ...

agains works as described, but the queries generated are:

query: SELECT id FROM ShipBean WHERE capacity=3000
query: SELECT tonnage,capacity,name,id FROM ShipBean WHERE id=1
query: UPDATE ShipBean SET
tonnage=100000.0,capacity=3000,name='Paradise',id=1 WHERE id=1
query: UPDATE ShipBean SET
tonnage=100000.0,capacity=3000,name='Paradise',id=1 WHERE id=1
query: SELECT tonnage,capacity,name,id FROM ShipBean WHERE id=2
query: UPDATE ShipBean SET tonnage=80000.0,capacity=3000,name='Utopia',id=2
WHERE id=2
query: UPDATE ShipBean SET tonnage=80000.0,capacity=3000,name='Utopia',id=2
WHERE id=2

In other words 1 + 3*#elements in collection. For any real app, this will
kill your database.
I am particularly interested where the UPDATES are coming from.
The way this should work is ONE query

 SELECT * FROM ShipBean WHERE capacity = 3000

and then a loop over the result set to populate the objects. I can see why
for large collections
pulling all the ids in first and then objects by id might be better, but one
should be able
to control this behaviour in jaws.xml.

Any comments anyone? Am I doing stuff wrong?

2) Complex Finder Problem
-------------------------

Also defined a non-standard query method in the home interface 

code: public Collection findCapacityAndName(int capacity, String name)
code:                                        throws RemoteException,
FinderException;

and added a jaws.xml as explained on the web site:

deploy:<jaws>
deploy:  <enterprise-beans>
deploy:    <entity>
deploy:      <ejb-name>ShipBean</ejb-name>
deploy:      <finder>
deploy:        <name>findCapacityAndName</name>
deploy:        <query>capacity = {0} AND name = {1}</query>
deploy:        <order>name DESC</order>
deploy:      </finder>
deploy:    </entity>
deploy:  </enterprise-beans>
deploy:</jaws>

but the query generated when calling the method is 

query: SELECT id,name DESC FROM ShipBean WHERE capacity = 3000 AND name =
'Utopia' ORDER BY name DESC

Pretty close, but not quite. What am I doing wrong? Is this a bug?

3) One to One / One to Many Relationships in EJB
------------------------------------------------

Anybody any experiences / suggestions on how to implement / persist EJB
relationships? One 
could implement them all as "finder" methods, but this is a real pain ...

Mhmm, I guess this is a longish post - but, hey, maybe you can answer all
questions with a 
shortish answer ;-)

Cheers,

Robert.


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to