1. Diese Seite verwendet Cookies. Wenn du dich weiterhin auf dieser Seite aufhältst, akzeptierst du unseren Einsatz von Cookies. Weitere Informationen

Finder methods + JBoss + Was expecting one of: "CONCAT" "SUBSTRING" ... "(" ... <STRI

Dieses Thema im Forum "Enterprise Java (JEE, J2EE, Spring & Co.)" wurde erstellt von cengizhdde, 27. Mai 2005.

  1. cengizhdde

    cengizhdde Mitglied

    Hallo zusammen,

    ich arbeite mit Container Managed Persistence-Beans in der Version 2.0 unter JBoss 4.0 auf Windows XP Prof. Beim Deployment auf den Server erhalte ich folgende Fehlermeldung:

    2005-05-27 10:30:13,316 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.parentTraceEnabled=true
    2005-05-27 10:30:13,316 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.nestedTraceEnabled=false
    2005-05-27 10:30:13,316 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.detectDuplicateNesting=true
    2005-05-27 10:30:13,316 ERROR [org.jboss.ejb.EntityContainer] Starting failed jboss.j2ee:jndiName=CmpL001PcDeEjb,service=EJB
    org.jboss.deployment.DeploymentException: Error compiling EJB-QL statement 'SELECT OBJECT(a) FROM CmpL003PcTrSchema as a WHERE LENGTH(a.level003_pc_id) = ?1 AND a.level003_pc_id LIKE ?2'; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "a.level003_pc_id" at line 1, column 61.
    Was expecting one of:
    "CONCAT" ...
    "SUBSTRING" ...
    "(" ...
    <STRING_LITERAL> ...
    <STRING_VALUED_PARAMETER> ...
    <STRING_VALUED_PATH> ...
    )
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.<init>(JDBCEJBQLQuery.java:52)
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBCCommandFactory.java:60)
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:272)
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:490)
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:381)
    at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:157)
    at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:340)
    at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:272)
    at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:222)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    ...............
    ...............

    Folgende Einträge wurden von mir vorgenommen:

    In der Home-Schnittstelle:

    public java.util.Collection findByRequirements(int length,java.lang.String flag)
    throws javax.ejb.FinderException,java.rmi.RemoteException;

    Im ejb-jar.xml-Deskriptor:

    <query>
    <query-method>
    <method-name>findByRequirements</method-name>
    <method-params>
    <method-param>int</method-param>
    <method-param>java.lang.String</method-param>
    </method-params>
    </query-method>
    <ejb-ql><![CDATA[SELECT OBJECT(a) FROM CmpL003PcDeSchema as a WHERE LENGTH(a.level003_pc_id) = ?1 AND a.level003_pc_id LIKE ?2]]></ejb-ql>
    </query>

    Soweit ich weiss gibt es in der Home-Schnittstelle mit der Übergabe von primitiven Datentypen (int) keine Probleme.

    Eine mögliche Lösung die ich in den Foren gefunden habe ist die Implementierung von Declared-SQL statt der Query die ich im Deskriptor verwende.

    Beispiel:

    <declared-sql>
    <select><alias>a</alias></select>
    <where>WHERE LENGTH(a.level003_pc_id = {0}) AND a.level003_pc_id LIKE {1}</where>
    <order></order>
    </declared-sql>

    Ich setze als Datenbank MySQL v4.0 ein.

    Kann jemand helfen? Danke im Voraus.
     
  2. cengizhdde

    cengizhdde Mitglied

    sorry, habe vergessen zu schreiben, das die Declared-SQL-Methode nicht funktioniert hat. Beim Deployment kommt die Fehlermeldung, das kein Bezug zwischen der Methode und dem Deskriptor bestehen würde.
     
  3. Thomas Darimont

    Thomas Darimont Premium-User

    Re: Finder methods + JBoss + Was expecting one of: "CONCAT" "SUBSTRING" ... "(" ... <

    Hallo!

    Code (Text):
    1. SELECT OBJECT(a) FROM CmpL003PcTrSchema as a WHERE LENGTH(a.level003_pc_id) = ?1 AND a.level003_pc_id LIKE ?2
    Ist a.level003_pc_id auch ein String kompatibler Typ?

    Gruß Tom
     
  4. Thomas Darimont

    Thomas Darimont Premium-User

    Re: Finder methods + JBoss + Was expecting one of: "CONCAT" "SUBSTRING" ... "(" ... <

    Hallo!

    Also unter JBoss 3.2.7 funktioniert folgendes einwandfrei:

    PersonBean -> Local CMP EntityBean
    Code (Text):
    1. /*
    2.  * Created on 27.05.2005@12:20:20 by Darimont
    3.  *
    4.  * TODO Licence info
    5.  */
    6. package de.tutorials.ejb.domain;
    7.  
    8. import java.rmi.RemoteException;
    9.  
    10. import javax.ejb.CreateException;
    11. import javax.ejb.EJBException;
    12. import javax.ejb.EntityBean;
    13. import javax.ejb.EntityContext;
    14. import javax.ejb.RemoveException;
    15.  
    16. /**
    17.  * @author Darimont
    18.  *
    19.  * TODO Explain me
    20.  * @ejb.bean description="PersonBean"
    21.  *           display-name="PersonBean"
    22.  *           local-jndi-name="PersonHomeLocal"
    23.  *           name="Person"
    24.  *           primkey-field="id"
    25.  *           type="CMP"
    26.  *           view-type="local" cmp-version = "2.x"
    27.  * @ejb.value-object generatePKConstructor = "true"
    28.  *
    29.  * @ejb.finder signature = "Person findPersonByName(java.lang.String name)"
    30.  *             description = "Find Person by Name" query = "SELECT OBJECT(p) FROM Person AS p WHERE p.lastName=?1"
    31.  * @ejb.finder signature = "Person findPersonByNameWithLen(java.lang.String name,int len)"
    32.  *             description = "Find Person by Name" query = "SELECT OBJECT(p) FROM Person AS p WHERE p.lastName=?1 AND LENGTH(p.lastName)=?2"
    33.  *
    34.  *
    35.  * @jboss.persistence create-table = "true" datasource = "java:/MySqlDS" datasource-mapping = "mySQL"  table-name = "Person"
    36.  * @jboss.entity-command name = "mysql-get-generated-keys"
    37.  * @jboss.unknown-pk auto-increment = "true" column-name = "id"
    38.  */
    39. public abstract class PersonBean implements EntityBean {
    40.  
    41.     /**
    42.      * @ejb.create-method view-type = "local"
    43.      *
    44.      * @param id
    45.      * @return
    46.      * @throws CreateException
    47.      */
    48.     public Integer ejbCreate() throws CreateException {
    49.         return null;
    50.     }
    51.    
    52.     public void ejbPostCreate() throws CreateException {}
    53.  
    54.     /**
    55.      * @ejb.interface-method
    56.      * @ejb.pk-field
    57.      * @ejb.persistence column-name = "id"
    58.      * @return
    59.      */
    60.     public abstract Integer getId();
    61.  
    62.     /**
    63.      * @ejb.interface-method
    64.      * @return
    65.      */
    66.     public abstract void setId(Integer id);
    67.  
    68.     /**
    69.      * @ejb.interface-method
    70.      * @ejb.persistence column-name = "lastname"
    71.      * @return
    72.      */
    73.     public abstract String getLastName();
    74.  
    75.     /**
    76.      * @ejb.interface-method
    77.      * @return
    78.      */
    79.     public abstract void setLastName(String lastName);
    80.  
    81.     public void ejbActivate() throws EJBException, RemoteException {
    82.     }
    83.  
    84.     public void ejbLoad() throws EJBException, RemoteException {
    85.     }
    86.  
    87.     public void ejbPassivate() throws EJBException, RemoteException {
    88.     }
    89.  
    90.     public void ejbRemove() throws RemoveException, EJBException,
    91.             RemoteException {
    92.     }
    93.  
    94.     public void ejbStore() throws EJBException, RemoteException {
    95.     }
    96.  
    97.     public void setEntityContext(EntityContext arg0) throws EJBException,
    98.             RemoteException {
    99.     }
    100.  
    101.     public void unsetEntityContext() throws EJBException, RemoteException {
    102.     }
    103.  
    104. }
    Hier das passende ejb-jar.xml:
    Code (Text):
    1. <?xml version="1.0" encoding="UTF-8"?>
    2.  
    3. <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    4.  
    5. <ejb-jar >
    6.  
    7.    <description><![CDATA[No Description.]]></description>
    8.    <display-name>Generated by XDoclet</display-name>
    9.  
    10.    <enterprise-beans>
    11.  
    12.       <!-- Session Beans -->
    13.       <session >
    14.          <description><![CDATA[PersonServiceBean]]></description>
    15.          <display-name>PersonServiceBean</display-name>
    16.  
    17.          <ejb-name>PersonService</ejb-name>
    18.  
    19.          <home>de.tutorials.ejb.generated.PersonServiceHome</home>
    20.          <remote>de.tutorials.ejb.generated.PersonService</remote>
    21.          <ejb-class>de.tutorials.ejb.service.PersonServiceBean</ejb-class>
    22.          <session-type>Stateless</session-type>
    23.          <transaction-type>Container</transaction-type>
    24.  
    25.       </session>
    26.  
    27.      <!--
    28.        To add session beans that you have deployment descriptor info for, add
    29.        a file to your XDoclet merge directory called session-beans.xml that contains
    30.        the <session></session> markup for those beans.
    31.      -->
    32.  
    33.       <!-- Entity Beans -->
    34.       <entity >
    35.          <description><![CDATA[PersonBean]]></description>
    36.          <display-name>PersonBean</display-name>
    37.  
    38.          <ejb-name>Person</ejb-name>
    39.  
    40.          <local-home>de.tutorials.ejb.generated.PersonLocalHome</local-home>
    41.          <local>de.tutorials.ejb.generated.PersonLocal</local>
    42.  
    43.          <ejb-class>de.tutorials.ejb.domain.PersonBean</ejb-class>
    44.          <persistence-type>Container</persistence-type>
    45.          <prim-key-class>java.lang.Integer</prim-key-class>
    46.          <reentrant>False</reentrant>
    47.          <cmp-version>2.x</cmp-version>
    48.          <abstract-schema-name>Person</abstract-schema-name>
    49.          <cmp-field >
    50.             <description><![CDATA[]]></description>
    51.             <field-name>id</field-name>
    52.          </cmp-field>
    53.          <cmp-field >
    54.             <description><![CDATA[]]></description>
    55.             <field-name>lastName</field-name>
    56.          </cmp-field>
    57.          <primkey-field>id</primkey-field>
    58.  
    59.          <query>
    60.             <description><![CDATA[Find Person by Name]]></description>
    61.             <query-method>
    62.                <method-name>findPersonByName</method-name>
    63.                <method-params>
    64.                   <method-param>java.lang.String</method-param>
    65.                </method-params>
    66.             </query-method>
    67.             <ejb-ql><![CDATA[SELECT OBJECT(p) FROM Person AS p WHERE p.lastName=?1]]></ejb-ql>
    68.          </query>
    69.          <query>
    70.             <description><![CDATA[Find Person by Name]]></description>
    71.             <query-method>
    72.                <method-name>findPersonByNameWithLen</method-name>
    73.                <method-params>
    74.                   <method-param>java.lang.String</method-param>
    75.                   <method-param>int</method-param>
    76.                </method-params>
    77.             </query-method>
    78.             <ejb-ql><![CDATA[SELECT OBJECT(p) FROM Person AS p WHERE p.lastName=?1 AND LENGTH(p.lastName)=?2]]></ejb-ql>
    79.          </query>
    80.       <!-- Write a file named ejb-finders-PersonBean.xml if you want to define extra finders. -->
    81.  
    82.       </entity>
    83.  
    84.      <!--
    85.        To add entity beans that you have deployment descriptor info for, add
    86.        a file to your XDoclet merge directory called entity-beans.xml that contains
    87.        the <entity></entity> markup for those beans.
    88.      -->
    89.  
    90.       <!-- Message Driven Beans -->
    91.      <!--
    92.        To add message driven beans that you have deployment descriptor info for, add
    93.        a file to your XDoclet merge directory called message-driven-beans.xml that contains
    94.        the <message-driven></message-driven> markup for those beans.
    95.      -->
    96.  
    97.    </enterprise-beans>
    98.  
    99.    <!-- Relationships -->
    100.  
    101.    <!-- Assembly Descriptor -->
    102.    <assembly-descriptor >
    103.      <!--
    104.        To add additional assembly descriptor info here, add a file to your
    105.        XDoclet merge directory called assembly-descriptor.xml that contains
    106.        the <assembly-descriptor></assembly-descriptor> markup.
    107.      -->
    108.  
    109.    <!-- finder permissions -->
    110.  
    111.    <!-- finder permissions -->
    112.  
    113.    <!-- transactions -->
    114.  
    115.    <!-- finder transactions -->
    116.    </assembly-descriptor>
    117.  
    118. </ejb-jar>
    Gruß Tom
     
  5. cengizhdde

    cengizhdde Mitglied

    Hallo Tom,

    danke für die schnelle Antwort. Ja, das Attribut level003_pc_id ist vom Typ java.lang.String.

    Der Unterschied zu Deinem Quelltext liegt innnerhalb der Entity-Bean. Ich arbeite mit dem XDoclet-Klassengenerator und verwende Ant für das Deployment.

    Sind in CMP v2.0 die Signatur von Finder-Methoden innerhalb der Entity Bean erforderlich? Falls ja, werden - kann ich mir denken - die Einträge in der die ejb-jar.xml-Datei überschrieben?

    Soweit ich sehen konnte ist Deine ejb-jar.xml mit meiner identisch.

    Danke und Gruss

    Cengiz
     
  6. Thomas Darimont

    Thomas Darimont Premium-User

    Re: Finder methods + JBoss + Was expecting one of: "CONCAT" "SUBSTRING" ... "(" ... <

    Hallo!

    Ich arbeite auch mit XDoclet... siehe @ejb.bla ;)

    Innerhalb der EntityBean nicht ... finder-Methoden werden an den Home/LocalHome- Interfaces angegeben.
    Über
    * @ejb.finder signature = "Person findPersonByName(java.lang.String name)"
    * description = "Find Person by Name" query = "SELECT OBJECT(p) FROM Person AS p WHERE p.lastName=?1"

    generiere ich mit Xdoclet diese Methode am LocalHome:
    Code (Text):
    1.    public de.tutorials.ejb.generated.PersonLocal findPersonByNameWithLen(java.lang.String name,int len)
    2.       throws javax.ejb.FinderException;

    Gruß Tom
     
  7. cengizhdde

    cengizhdde Mitglied

    Re: Finder methods + JBoss + Was expecting one of: "CONCAT" "SUBSTRING" ... "(" ... <

    Hallo,

    also meine Home-Schnittstelle der CMP sieht wie folgt aus:

    public com.de.ibais.viuna.cmp.pc.CmpL002PcDe create(java.lang.Long id , java.sql.Timestamp lastModify , java.lang.String pc , java.lang.String valid , java.lang.String description)
    throws javax.ejb.CreateException,java.rmi.RemoteException;

    public java.util.Collection findAll()
    throws javax.ejb.FinderException,java.rmi.RemoteException;

    public java.util.Collection findByRequirements(int length,java.lang.String flag)
    throws javax.ejb.FinderException,java.rmi.RemoteException;

    public com.de.ibais.viuna.cmp.pc.CmpL002PcDe findByPrimaryKey(java.lang.Long pk)
    throws javax.ejb.FinderException,java.rmi.RemoteException;

    Die ejb-jar.xml kennst du. Hier nochmal der Auszug:

    <query>
    <query-method>
    <method-name>findByRequirements</method-name>
    <method-params>
    <method-param>int</method-param>
    <method-param>java.lang.String</method-param>
    </method-params>
    </query-method>
    <ejb-ql><![CDATA[SELECT OBJECT(a) FROM CmpL003PcDeSchema as a WHERE LENGTH(a.level003_pc_id) = ?1 AND a.level003_pc_id LIKE ?2]]></ejb-ql>
    </query>

    Soweit ich weiss sind keine weiteren Einstellungen erforderlich. Die Fehlermeldung besteht leider wie bisher.

    Idee(n) ?

    Gruss und schönes Wochenende.

    Cengiz