Thanks a lot for your answer.
>The problem is that bestFriend is *not* a CMP field but rather a CMR field.
Using a 1:N CMR field, I managed to get examples running. In fact, the official
JBoss 3.2.1 docu had a partial example for this, and on
http://www.jboss.org/thread.jsp?forum=147&thread=37442
I posted the completion of this examples, giving the missing parts
(not the Xdoclet parts).
My problem is exactly to get an example for 1:1. On http://www.jboss.org/thread.jsp?forum=46&thread=37412 I asked for support on a query where I try to use a 1:1 CMR.
Since I got no answer, I tried to do something even simpler, using a CMP field for that.
Now, after reading your email, I remember that the CMP fields whose value is an object,
are in fact serialized versions of this objects, right? Thus my example makes no sense.
I propose, I post the previous problem "using 1:1 CMR field with EJBQL" to the list.
Best, Philipp
Philipp Kutter A4M applied formal methods AG www.a4m.biz
On Harkness, David wrote:
Hi Philipp,
The problem is that bestFriend is *not* a CMP field but rather a CMR field. You need to code your finder query to use the WHERE clause to find the Gangster that is the best friend and then traverse the relationship to get the Gangsters you want in the first place. I'm making a few assumptions, so let's start there.
1. Gangster is an entity bean. 2. Gangster has a 1:N relationship to itself. Each G has a BF, and thus also has many Gs that consider them a BF. Therefore, your query will return a Collection 3. The gangster table has a PK column called id. 4. The gangster table has a FK column called friend.
If those are all correct, then you need to change your xdoclet tags to specify a relationship instead of a field. For example, for User <-- 1:N --> Phones, here are the tags I use in UserEJB.java:
/** * @ejb.interface-method * @ejb.transaction type="Supports" * @ejb.relation * name="User-Phone" * role-name="User-has-many-Phones" * cascade-delete="no" */ public abstract Collection getPhones ( ) ; public abstract void setPhones ( Collection phones ) ;
And in PhoneEJB.java:
/** * @ejb.interface-method * view-type="local" * @ejb.transaction type="Supports" * @ejb.relation * name="User-Phone" * role-name="Phones-have-a-User" * cascade-delete="yes" * @weblogic.column-map * foreign-key-column="user_id" * key-column="id" */ public abstract UserLocal getUser ( ) ;
/** */ public abstract void setUser ( UserLocal user ) ;
This is for a bidirectional relationship, so both beans know about and can find each other via relationships and in finder queries. I also added a helper method so I could hook a Phone up to a User given only the User's ID:
/** * Attaches this phone to the user with the given ID. * * @param userId unique ID of the owning user */ protected void setLocalUserId ( Integer userId ) { try { setUser(UserUtil.getLocalHome().findByPrimaryKey(userId)); } catch ( NamingException e ) { throw new ServiceException("Failure looking up user home", e); } catch ( FinderException e ) { throw new ServiceException("Failure finding a user", e); } }
First of all, is this where you were going with this? Or did I miss it and you really intended bestFriend to be a String holding the Gangster's friend's name? If that's the case, change its type to String and you should be good to go. Otherwise, look at the relationship examples (another assumption, that there *are* CMR examples) and ask more questions.
Good luck!
David Harkness Sony Pictures Digital Networks (310) 482-4756
-----Original Message-----
From: Philipp W. Kutter [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 05, 2003 9:54 AM
To: [EMAIL PROTECTED]
Subject: [Xdoclet-user] using CMP field with EJBQL
Hi. I work with the Gangster CMP example and reengineered the Xdoclet tags. Everything works great, and without Xdoclet, I do not know how I could have managed to do anything useful...
Problem is that this example does not cover some of the interesting cases.
I describe the simplest here. If someone is interested I can as well deliver full Eclipse projects with Xdoclet.
Problem:
(JBoss 3.2.1-tomcat, CMP Gangster Example of 3.2.1 Documentation)
I try to use a simple CMP field in an EJB query, and I get a
"org.jboss.deployment.DeploymentException: Error compiling EJB-QL statement
'SELECT OBJECT(u) FROM gangster u WHERE u.bestFriend = ?1';
- nested throwable: (java.lang.NullPointerException)"
Is it not possible to use CMP fields in EJB queries?
I did this as close to the JBoss 3.2.1 documentation as possible: 1) added setter/getter for 'bestFriend' to bean, 2) added declarations to local interface, 3) added finderdeclaration to local home 4) added CMP-field and query-definition of finder to ejb-jar.xml
My query is SELECT OBJECT(u) FROM gangster u WHERE u.bestFriend = ?1 and I get the Error compiling EJB-QL statement error.
What do I wrong?
One more info: it must be in the "WHERE u.bestFriend = ?1" part, if I leave that
away, everything works perfectly.
Best, Philipp
Details:
-------
I add the getter and setter for a new field bestFriend to the GansterBean.java:
/**
* @return
* @ejb.persistence
* column-name = "friend"
* @ejb.interface-method
*/
public abstract Gangster getBestFriend();
/**
* @param u
* @ejb.interface-method
*/ public abstract void setBestFriend(Gangster u);
Xdoclet adds them to the local interface Gangster.java: //new: Gangster getBestFriend(); void setBestFriend(Gangster u);
Xdoclet adds the CMP-field definition to ejb-jar.xml: <cmp-field> <description><![CDATA[]]></description> <field-name>bestFriend</field-name> </cmp-field>
I add the finder Xdoclet to the GangsterBean:
* @ejb.finder
* signature = "java.util.Collection findBestFriend(org.jboss.cmp2.crimeportal.Gangster g)"
* query = "SELECT OBJECT(u) FROM gangster u WHERE u.bestFriend = ?1"
Xdoclets adds to the ejb-jar.xml:
<query>
<query-method>
<method-name>findBestFriend2</method-name>
<method-params>
<method-param>org.jboss.cmp2.crimeportal.Gangster</method-param>
</method-params>
</query-method>
<ejb-ql><![CDATA[
SELECT OBJECT(u) FROM gangster u WHERE u.bestFriend = ?1
]]></ejb-ql>
</query>
Xdoclet adds the corresponding declaration to the local home interface GanagsterHome.java:
//new:
java.util.Collection findBestFriend2(org.jboss.cmp2.crimeportal.Gangster g) throws FinderException;
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user
smime.p7s
Description: S/MIME Cryptographic Signature
