Thanks, timkk.
Indeed it works fine when you just put in the <query-method> stuff into
jbosscmp-jdbc.xml by hand. For some reason XDoclet does not generate this for you
with ejbSelect methods, while it does so for ejbFind. (Could this be a bug in XDoclet?
or am I using the wrong tags?)
If you're using Eclipse as your IDE you could use the Lomboz and/or JBoss IDE plugins.
They both user XDoclet under the hood. It shields you somewhat from the daunting
XDoclet and ANT configs you would need otherwise and they both integrate nicely with
Eclipse. For an J2EE starter like me Lomboz/Eclipse makes for a good pair.
On the Double / Integer issue I must correct myself; you are right! JBoss *does* seem
to map a Double java type on the SQL INT type configured in the deployment descriptor
and EJB class. Really anoying.
I did not notice this until now since I had not proceeded yet to the point that I
actually received a valid object back from the ejbSelect without JBoss throwing
exceptions at me about my EJB-QL. And in the Lomboz/XDoclet generated interfaces and
deployment descriptors all seemed fine. The last exception I had to fix was a
ClasscastException at the point where the ejbSelect was called ; - ) The returned type
indeed was Double instead of Integer.
I solves this by casting the Double returned by the ejbSelect into an Integer in my
wrapper home method, which I need anyway, since the ejbSelect is only visible to EJB's
and normally you'd like it exposed to the outside world:
/**
| * @ejb.select
| * query="SELECT MAX(m.myPrimKey) FROM MyTable AS m"
| * @jboss.query
| * query="SELECT MAX(m.myPrimKey) FROM MyTable AS m"
| */
| abstract public Double ejbSelectMyPrimKey() throws FinderException;
|
| /**
| * @ejb.home-method
| * view-type="local"
| */
| public static Integer ejbHomeGetNextPrimKey() throws Exception {
| int nextKey = 1 + ejbSelectMyPrimKey().intValue();
| return new Integer(nextKey);
| }
Now the method getNextPrimKey() can be called on the (local) home object of the EJB to
find the next primary key to be used in the create() method. Ofcourse you need to wrap
getNextPrimKey() and create() in a user transaction to ensure concurrent inserts into
your database succeed.
I guess all this pretty much answer your question too, Ben!
Cheers,
Frank
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3834098#3834098
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3834098
-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to
deliver higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development