jboss中非关键字段的finder方法的ejb-ql句子应该写在哪个文件中?我写在findAll下面好像没用

03-07-03 jd2bs
我的环境是jboss3.0.7+lomboz2.1+Eclipse;我的sessionbean是用remote接口调用Entity bean的,jsp再调用sessionbean.我的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 >

   <description><![CDATA[No Description.]]></description>
   <display-name>Generated by XDoclet</display-name>

   <enterprise-beans>

      <!-- Session Beans -->
     <!--
       To add session beans that you have deployment descriptor info for, add
       a file to your XDoclet merge directory called session-beans.xml that contains
       the <session></session> markup for those beans.
     -->
	 <session >
         <description><![CDATA[]]></description>

         <ejb-name>UserManager</ejb-name>

         <home>com.webex.testj2ee.UserManagerHome</home>
         <remote>com.webex.testj2ee.UserManager</remote>
         <local-home>com.webex.testj2ee.UserManagerLocalHome</local-home>
         <local>com.webex.testj2ee.UserManagerLocal</local>
         <ejb-class>com.webex.testj2ee.UserManagerSession</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Container</transaction-type>

	 </session>

      <!-- Entity Beans -->
      <entity >
         <description><![CDATA[]]></description>

         <ejb-name>Users</ejb-name>

         <home>com.webex.testj2ee.UsersHome</home>
         <remote>com.webex.testj2ee.Users</remote>
         <local-home>com.webex.testj2ee.UsersLocalHome</local-home>
         <local>com.webex.testj2ee.UsersLocal</local>

         <ejb-class>com.webex.testj2ee.UsersCMP</ejb-class>
         <persistence-type>Container</persistence-type>
         <prim-key-class>java.lang.Integer</prim-key-class>
         <reentrant>False</reentrant>
         <cmp-version>2.x</cmp-version>
         <abstract-schema-name>mySchema1</abstract-schema-name>
         <cmp-field >
            <description><![CDATA[Returns the userid]]></description>
            <field-name>userid</field-name>
         </cmp-field>
         <cmp-field >
            <description><![CDATA[Returns the name]]></description>
            <field-name>name</field-name>
         </cmp-field>
         <cmp-field >
            <description><![CDATA[Returns the pass]]></description>
            <field-name>pass</field-name>
         </cmp-field>
         <primkey-field>userid</primkey-field>

         <query>
            <query-method>
               <method-name>findAll</method-name>
               <method-params>
               </method-params>
            </query-method>
            <ejb-ql><![CDATA[SELECT OBJECT(a) FROM mySchema1 as a]]></ejb-ql>
         </query>
	  <!-- Write a file named ejb-finders-UsersBean.xml if you want to define extra finders. -->
      </entity>

      <entity >
         <description><![CDATA[]]></description>

         <ejb-name>Orders</ejb-name>

         <home>com.webex.testj2ee.OrdersHome</home>
         <remote>com.webex.testj2ee.Orders</remote>
         <local-home>com.webex.testj2ee.OrdersLocalHome</local-home>
         <local>com.webex.testj2ee.OrdersLocal</local>

         <ejb-class>com.webex.testj2ee.OrdersCMP</ejb-class>
         <persistence-type>Container</persistence-type>
         <prim-key-class>java.lang.Integer</prim-key-class>
         <reentrant>False</reentrant>
         <cmp-version>2.x</cmp-version>
         <abstract-schema-name>mySchema2</abstract-schema-name>
         <cmp-field >
            <description><![CDATA[Returns the orderid]]></description>
            <field-name>orderid</field-name>
         </cmp-field>
         <cmp-field >
            <description><![CDATA[Returns the userid]]></description>
            <field-name>userid</field-name>
         </cmp-field>
         <primkey-field>orderid</primkey-field>

         <query>
            <query-method>
               <method-name>findAll</method-name>
               <method-params>
               </method-params>
            </query-method>
            <ejb-ql><![CDATA[SELECT OBJECT(a) FROM mySchema2 as a]]></ejb-ql>
         </query>
	  <!-- Write a file named ejb-finders-OrdersBean.xml if you want to define extra finders. -->

	     

     <!--
       To add entity beans that you have deployment descriptor info for, add
       a file to your XDoclet merge directory called entity-beans.xml that contains
       the <entity></entity> markup for those beans.
     -->

      <!-- Message Driven Beans -->
     <!--
       To add message driven beans that you have deployment descriptor info for, add
       a file to your XDoclet merge directory called message-driven-beans.xml that contains
       the <message-driven></message-driven> markup for those beans.
     -->

   </enterprise-beans>
<!-- Relationships-->
<!-- Assembly Descriptor -->
</ejb-jar>
<p>

jd2bs
2003-07-03 13:51
中间那个注释说写到ejb-finders-OrdersBean.xml,我写了根本没用,部署后还是说找不到方法findByUserId.

ejb-finders-OrdersBean.xml:

<?xml version="1.0" encoding="UTF-8"?>
<query>
            <query-method>
               <method-name>findByUserId</method-name>
               <method-params>java.lang.Integer</method-params>
            </query-method>
            <ejb-ql><![CDATA[SELECT OBJECT(a) FROM mySchema2 as a where a.userid=?1]]></ejb-ql>
</query>
<p>

以上问题我在jboss console中只是看到个warning,看起来部署好像还是成功的,只不过该findByUserId方法有问题.但我在jsp页面调用另一个方法getUsers,页面一直在load,很长时间都load不出来结果?jboss console也没抛出错误,真奇怪.

index.jsp:

<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<%@page import="com.webex.testj2ee.*,java.util.*,javax.naming.*"
%>
<html>
	<head>
		<title>Welcome</title>
	</head>
	<body>
	<table width=60% border=1>	
	<%
	try{
	Hashtable props = new Hashtable();
	props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
			"org.jnp.interfaces.NamingContextFactory");
	props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
	InitialContext initialContext = new InitialContext(props);
	UserManagerHome umhome=(UserManagerHome)initialContext.lookup(UserManagerHome.JNDI_NAME);
    UsersData[] ud=umhome.create().getUsers();
	for(int i=0;i<ud.length;i++){
	%>
	<tr>
	<td><%=(ud[i].getUserid().toString())%></td>
	<td><%=(ud[i].getName())%></td>
	<td><%=(ud[i].getPass())%></td>
	</tr>
	<%}
	}
	catch(NamingException ex){
	ex.printStackTrace();
	}
	%>
	</table>	 
	</body>
</html>

<p>

getUsers方法:

public UsersData[] getUsers(){ 
 try{
	ArrayList userList = new ArrayList(50);
	Collection c=UsersUtil.getHome().findAll();
	Iterator it = c.iterator();
	while(it.hasNext()){
						Users u=(Users)it.next();
						UsersData ud=new UsersData(u.getUserid(),u.getName(),u.getPass());
						userList.add(ud);
					}
    return (UsersData[])userList.toArray(new UsersData[userList.size()]);
	}
	catch(FinderException e){
		e.printStackTrace();
	}
	catch(RemoteException ex){
			ex.printStackTrace();
		}
	catch(NamingException ex){
	
		}
  return null;
}
<p>

bad_bird
2003-07-03 15:53
为什么不把该方法定义在ejb-jar.xml中?

jd2bs
2003-07-03 15:59
兄弟,你看我的标题;我开始就是写在ejb-jar.xml中findAll下面的;控制台报warning找不到啊

bluegirl
2003-07-03 16:56
跟我遇到的一样,我现在用findall方法可是报错:

accountsUnknown
query: public abstract java.util.Collection com.bank.ProtonAccountHome.findAllAccounts() throws javax.ejb.FinderException,java.rmi.RemoteException 

可是在jaws.xml文件中已经定义过了。

 <finder>
                <name>findByID</name>
                <query><![CDATA[where account_number = {0}]]></query>
                <order></order>
            </finder>


顺便问一句为什么不在jaws文件中定义?
我用的是jboss4和db2



            
                <order></order>
           </finder>
           <finder>
                <name>findAllAcounts</name>                         
                        <query />
                <order/>         
           </finder>

猜你喜欢
2Go 1 2 下一页