SELECT OBJECT(a)FROM PRODUCTBEAN AS a WHERE a.name= ?1 ^加个空格试试
最后一着,如果再不行,就换换编译环境再试。SELECT OBJECT(a)FROM PRODUCTBEAN a WHERE a.name=?1 ^ 把AS去掉!
去掉也一样select object(a) from productbean as a where basePrice=?1 报错 但是 select object(a) from productbean as a where basePrice<?1 select object(a) from productbean as a where basePrice>?1 都没有报错这是我的ejb-jar.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd"> <ejb-jar> <display-name>EJBModulecmp</display-name> <enterprise-beans> <entity> <display-name>Product</display-name> <ejb-name>Product</ejb-name> <home>cmpb.ProductRemoteHome</home> <remote>cmpb.ProductRemote</remote> <local-home>cmpb.ProductHome</local-home> <local>cmpb.Product</local> <ejb-class>cmpb.ProductBean</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>cmpb.ProductPK</prim-key-class> <reentrant>False</reentrant> <cmp-version>2.x</cmp-version> <abstract-schema-name>ProductBean</abstract-schema-name> <cmp-field> <field-name>productID</field-name> </cmp-field> <cmp-field> <field-name>name</field-name> </cmp-field> <cmp-field> <field-name>description</field-name> </cmp-field> <cmp-field> <field-name>basePrice</field-name> </cmp-field> <query> <query-method> <method-name>findByName</method-name> <method-params> <method-param>java.lang.String</method-param> </method-params> </query-method> <ejb-ql>SELECT OBJECT FROM PRODUCTBEAN WHERE name=?1</ejb-ql> </query> <query> <query-method> <method-name>findByDescription</method-name> <method-params> <method-param>java.lang.String</method-param> </method-params> </query-method> <ejb-ql>select object(a)from productbean as a where description=?1</ejb-ql> </query> <query> <query-method> <method-name>findByBasePrice</method-name> <method-params> <method-param>double</method-param> </method-params> </query-method> <ejb-ql>select object(a) from productbean as a where basePrice=?1</ejb-ql> </query> <query> <query-method> <method-name>findExpensiveProducts</method-name> <method-params> <method-param>double</method-param> </method-params> </query-method> <ejb-ql>select object(a) from productbean as a where baseprice>?1</ejb-ql> </query> <query> <query-method> <method-name>findCheapProducts</method-name> <method-params> <method-param>double</method-param> </method-params> </query-method> <ejb-ql> <![CDATA[select object(a) from productbean as a where baseprice<?1]]> </ejb-ql> </query> <query> <query-method> <method-name>findAllProducts</method-name> <method-params /> </query-method> <ejb-ql>select object(a) from productbean as a where productID is not null</ejb-ql> </query> </entity> </enterprise-beans> <assembly-descriptor> <container-transaction> <method> <ejb-name>Product</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> </assembly-descriptor> </ejb-jar>
注意这里: <abstract-schema-name>ProductBean</abstract-schema-name> 所以你的ql里应该是: select object(a) from ProductBean as a where basePrice=?1
楼主你的ejb-ql语句在where后的属性处全部都没有加上a.*,如:SELECT OBJECT(a)FROM PRODUCTBEAN AS a WHERE a.name=?1 ^在这里 select object(a)from productbean as a where a.description=?1 ^在这里
^加个空格试试
^
把AS去掉!
但是
select object(a) from productbean as a where basePrice<?1
select object(a) from productbean as a where basePrice>?1
都没有报错这是我的ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<display-name>EJBModulecmp</display-name>
<enterprise-beans>
<entity>
<display-name>Product</display-name>
<ejb-name>Product</ejb-name>
<home>cmpb.ProductRemoteHome</home>
<remote>cmpb.ProductRemote</remote>
<local-home>cmpb.ProductHome</local-home>
<local>cmpb.Product</local>
<ejb-class>cmpb.ProductBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>cmpb.ProductPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>ProductBean</abstract-schema-name>
<cmp-field>
<field-name>productID</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<cmp-field>
<field-name>description</field-name>
</cmp-field>
<cmp-field>
<field-name>basePrice</field-name>
</cmp-field>
<query>
<query-method>
<method-name>findByName</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>SELECT OBJECT FROM PRODUCTBEAN WHERE name=?1</ejb-ql>
</query>
<query>
<query-method>
<method-name>findByDescription</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>select object(a)from productbean as a where description=?1</ejb-ql>
</query>
<query>
<query-method>
<method-name>findByBasePrice</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
</query-method>
<ejb-ql>select object(a) from productbean as a where basePrice=?1</ejb-ql>
</query>
<query>
<query-method>
<method-name>findExpensiveProducts</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
</query-method>
<ejb-ql>select object(a) from productbean as a where baseprice>?1</ejb-ql>
</query>
<query>
<query-method>
<method-name>findCheapProducts</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[select object(a) from productbean as a where baseprice<?1]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findAllProducts</method-name>
<method-params />
</query-method>
<ejb-ql>select object(a) from productbean as a where productID is not null</ejb-ql>
</query>
</entity>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Product</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
<abstract-schema-name>ProductBean</abstract-schema-name>
所以你的ql里应该是:
select object(a) from ProductBean as a where basePrice=?1
^在这里
select object(a)from productbean as a where a.description=?1
^在这里
要和<abstract-schema-name>ProductBean</abstract-schema-name>
中的ProductBean保持一致