File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB-QL help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB-QL help" Watch "EJB-QL help" New topic
Author

EJB-QL help

J Waldinger
Greenhorn

Joined: Sep 05, 2003
Posts: 12
Hi - I am upgrading an EJB 1.0 application to EJB 2.0, and am having some difficulty getting my EJB-QL to compile for my additional finder methods. I'm using WSAD 5, and am getting an error: "TABLE_NAME does not have a field COLUMN_NAME". I know for a fact that it does have this column, but how do I let the compiler know this? Here is my query:
<ejb-ql>select object(up) from table_name as up where up.column_name = ?1 and up.other_column = ?2</ejb-ql>
Thanks for the help,
Jamie
jwaldinger@comcast.net
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Jamie, could you post the parts of your ejb-jar.xml and the vendor-specific deployment descriptor which relate to this particular entity bean?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
J Waldinger
Greenhorn

Joined: Sep 05, 2003
Posts: 12
Sure thing. It's a bit long, but here is the section from the ejb-jar.xml:
<entity id="ContainerManagedEntity_1061575772906">
<ejb-name>ProfilePromotionMap</ejb-name>
<home>com.bostoncoach.gtx.ProfilePromotionMapHome</home>
<remote>com.bostoncoach.gtx.ProfilePromotionMap</remote>
<ejb-class>com.bostoncoach.gtx.ProfilePromotionMapBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.bostoncoach.gtx.ProfilePromotionMapKey</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>CO_USER_PROMO</abstract-schema-name>
<cmp-field id="CMPAttribute_1061575892234">
<field-name>sequenceNo</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1061575892235">
<field-name>profileID</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1061575892236">
<field-name>memberCode</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1061575892237">
<field-name>promotionProgram</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1061575892238">
<field-name>lastUpdateKey</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1061575892239">
<field-name>promotionProgramMemberID</field-name>
</cmp-field>
<query>
<description>Converted from IBM version 1.1 extensions.</description>
<query-method>
<method-name>findPromotions</method-name>
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>select object(up) from CO_USER_PROMO up where up.MEM_C=?1 AND up.USER_ID=?2</ejb-ql>
</query>
<query>
<description>Converted from IBM version 1.1 extensions.</description>
<query-method>
<method-name>findForUpdate</method-name>
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
<method-param>char</method-param>
</method-params>
</query-method>
<ejb-ql>MEM_C=? AND USER_ID=? AND SEQ_N=?-1</ejb-ql>
</query>
<query>
<description>Converted from IBM version 1.1 extensions.</description>
<query-method>
<method-name>findPromotionsForUpdate</method-name>
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>MEM_C=? AND USER_ID=? FOR UPDATE</ejb-ql>
</query>
</entity>
Not that these ejb-ql methods were auto-generated from 1.1 finder methods. The first one is the only one I have tried to fix so far - the second two still give vanilla syntax errors - I imagine because the don't have a select clause, etc.
Is the following what you mean by 'vendor-specific' files? The following came from ibm-ejb-jar-ext.xmi. I am not very familiar with this file.
<ejbExtensions xmi:type="ejbext:ContainerManagedEntityExtension" xmi:id="ContainerManagedEntityExtension_18">
<runAsSettings xmi:id="SecurityIdentity_28">
<methodElements xmi:id="MethodElement_72" name="*" type="Unspecified">
<enterpriseBean xmi:type="ejb:ContainerManagedEntity" href="META-INF/ejb-jar.xml#ContainerManagedEntity_1061575772906"/>
</methodElements>
<runAsMode xmi:type="ejbext:UseSystemIdentity" xmi:id="UseSystemIdentity_28"/>
</runAsSettings>
<enterpriseBean xmi:type="ejb:ContainerManagedEntity" href="META-INF/ejb-jar.xml#ContainerManagedEntity_1061575772906"/>
</ejbExtensions>
Thanks very much for your help.
Jamie
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You could try the following EJB-QL instead:

This is because your EJB-QL should use the field names listed in the ejb-jar.xml instead of the actual database column names. Let us know whether that worked or not.
J Waldinger
Greenhorn

Joined: Sep 05, 2003
Posts: 12
Lasse,
That worked just fine. (Or, at least, it compiles...)
Thanks very much for your help - I hadn't realized you were supposed to use the EJB field names in the query as opposed to the column names. It strikes me as odd, then, that you still use the table name in the 'from' clause...
Jamie
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209

It strikes me as odd, then, that you still use the table name in the 'from' clause...

that's because the abstract schema name is same as the table name in your descriptor.

EJBQL can refer only to the cmp fields, cmr field sand the abstract schema name present in your descriptors.
J Waldinger
Greenhorn

Joined: Sep 05, 2003
Posts: 12
Thanks for the help. I have but one remaining error in my new 2.0 compliant ejb-jar file. The error is:
"unknown EJB or ASN name: com.bostoncoach.gtx.AFReceiptRegistryKey"
Here is the query:
<query>
<description>Converted from IBM version 1.1 extensions.</description>
<query-method>
<method-name>findByReservationReferenceNumber</method-name>
<method-params>
<method-param>com.bostoncoach.gtx.AFReceiptRegistryKey</method-param>
</method-params>
</query-method>
<ejb-ql>select object(rr) from AFReceiptRegistry rr where rr.reservationReferenceNumber = ?1</ejb-ql>
</query>
I thought perhaps this was due to a change in the EJB 2.0 spec, however when I created a new query using WSAD's tools, using the same class as a method parameter, it created a query that looked identical to this one. Given that this class (AFReceiptRegistryKey) is located within this project's EJB module, why am I getting this error?
Thanks,
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB-QL help