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 Grünschnabel

    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 Grünschnabel

    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 Administrator

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

    Hallo!

    Code (Text):
    1.  
    2. 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 Administrator

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

    cengizhdde Grünschnabel

    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 Administrator

    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.  
    2.    public de.tutorials.ejb.generated.PersonLocal findPersonByNameWithLen(java.lang.String name,int len)
    3.       throws javax.ejb.FinderException;
    4.  

    Gruß Tom
  7. cengizhdde

    cengizhdde Grünschnabel

    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

Diese Seite empfehlen