請好心人一定幫忙看下jboss+mysql測試一個entitybean倒底錯誤在哪?

MafiaCat發表於2003-06-20
請大家幫忙看下我的jboss+mysql測試一個entitybean倒底錯誤在哪?

偶改了個JBOSS練習書裡一個entity bean來測試。

這是StudentBean建一個最最簡單的表,帶有id,name,email。
預設用jboss內建的資料庫Hypersonic
在 <datasource>java:/DefaultDS</datasource>
<type-mapping>Hypersonic SQL</type-mapping>
<debug>false</debug>
完全可以正確完成。資訊如下:

17:46:21,796 INFO [MainDeployer] Starting deployment of package: file:/D:/jboss/server/default/deploy/test.jar
17:46:21,812 INFO [EJBDeployer] looking for nested deployments in : file:/D:/jboss/server/default/deploy/test.jar
17:46:22,546 INFO [EjbModule] Creating
17:46:22,593 INFO [EjbModule] Deploying StudentEJB
17:46:22,843 INFO [EntityContainer] Creating
17:46:22,859 INFO [EntityInstancePool] Creating
17:46:22,859 INFO [EntityInstancePool] Created
17:46:22,875 INFO [EntityContainer] Created
17:46:22,875 INFO [EjbModule] Created
17:46:22,890 INFO [EjbModule] Starting
17:46:22,890 INFO [EntityContainer] Starting
17:46:25,234 INFO [StudentEJB] Created table 'STUDENTEJB' successfully.
17:46:25,265 INFO [EntityInstancePool] Starting
17:46:25,265 INFO [EntityInstancePool] Started
17:46:25,281 INFO [EntityContainer] Started
17:46:25,281 INFO [EjbModule] Started
17:46:25,312 INFO [MainDeployer] Deployed package: file:/D:/jboss/server/default/deploy/test.jar

***************************************************
***************************************************

但是把D:\jboss\server\default\conf下的2個檔案standardjaws.xml
standardjbosscmp-jdbc.xml如下修改:

<datasource>java:/MySqlDS</datasource>
<type-mapping>mySQL</type-mapping>


並且把D:\jboss\server\default\deploy下的mysql-ds.xml設定成:

<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://192.168.0.1:3306/test_db</connection-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<user-name>test</user-name>
<password>test</password>
</local-tx-datasource>

</datasources>

然後測試是否能在mysql上建表時缺就出錯如下:

17:58:40,906 INFO [MainDeployer] Starting deployment of package: file:/D:/jboss/server/default/deploy/test.jar
17:58:40,937 INFO [EJBDeployer] looking for nested deployments in : file:/D:/jboss/server/default/deploy/test.jar
17:58:41,593 INFO [EjbModule] Creating
17:58:41,625 INFO [EjbModule] Deploying StudentEJB
17:58:41,953 INFO [EntityContainer] Creating
17:58:41,953 INFO [EntityInstancePool] Creating
17:58:41,953 INFO [EntityInstancePool] Created
17:58:42,000 INFO [EntityContainer] Created
17:58:42,000 INFO [EjbModule] Created
17:58:42,000 INFO [EjbModule] Starting
17:58:42,000 INFO [EntityContainer] Starting
17:58:43,218 ERROR [EntityContainer] Starting failed
java.lang.NullPointerException
at org.jboss.ejb.plugins.cmp.jdbc.JDBCTypeFactory.createTypeSimple(JDBCTypeFactory.java:115)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCTypeFactory.getJDBCType(JDBCTypeFactory.java:77)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.<init>(JDBCAbstractCMPFieldBridge.java:71)

**********************************************************

偶把具體bean的程式碼,script的設定貼下面,大家幫忙看看到底錯哪裡?

使用:
jboss-3.2.1_tomcat-4.1.24
DS:mysql-4.0.12-win
JDBC:mysql-connector-java-3.0.8-stable-bin.jar

*******************************
StudentBean.java
package test.ejb;

import javax.ejb.*;
import java.rmi.*;

public abstract class StudentBean
implements javax.ejb.EntityBean
{

public Integer ejbCreate(Integer id) throws CreateException
{
this.setId(id);
return null; // TODO is this right!?
}
public void ejbPostCreate(Integer id)
{
}

public abstract void setId(Integer id);
public abstract Integer getId();

public abstract void setName(String name);
public abstract String getName();

public abstract void setEmail(String email);
public abstract String getEmail();

public void setEntityContext(EntityContext ctx)
{
// Not implemented.
}
public void unsetEntityContext()
{
// Not implemented.
}
public void ejbActivate()
{
// Not implemented.
}
public void ejbPassivate()
{
// Not implemented.
}
public void ejbLoad()
{
// Not implemented.
}
public void ejbStore()
{
// Not implemented.
}
public void ejbRemove()
{
// Not implemented.
}
}
************************************

************************************
StudentHomeRemote.java

package test.ejb;

import javax.ejb.*;
import java.rmi.*;

public interface StudentHomeRemote extends javax.ejb.EJBHome
{
public StudentRemote create(Integer id)
throws CreateException, RemoteException;

public StudentRemote findByPrimaryKey(Integer pk)
throws FinderException, RemoteException;
}
*********************************************

*********************************************
StudentRemote.java

package test.ejb;

import javax.ejb.EJBObject;
import java.rmi.*;

public interface StudentRemote extends javax.ejb.EJBObject
{
public String getName() throws RemoteException;
public void setName(String str) throws RemoteException;

public String getEmail() throws RemoteException;
public void setEmail(String str) throws RemoteException;
}

****************************************+

下面開始是scripts

**************************************************
ejb-jar.xml:

<?xml version="1.0"?>

<!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>
<enterprise-beans>
<entity>
<ejb-name>StudentEJB</ejb-name>
<home>test.ejb.StudentHomeRemote</home>
<remote>test.ejb.StudentRemote</remote>
<ejb-class>test.ejb.StudentBean</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>Student</abstract-schema-name>
<cmp-field><field-name>id</field-name></cmp-field>
<cmp-field><field-name>name</field-name></cmp-field>
<cmp-field><field-name>email</field-name></cmp-field>
<primkey-field>id</primkey-field>
<security-identity><use-caller-identity/></security-identity>
</entity>
</enterprise-beans>

<assembly-descriptor>
<security-role>
<description>
This role represents everyone who is allowed full access to the Student EJB.
</description>
<role-name>everyone</role-name>
</security-role>
<method-permission>
<role-name>everyone</role-name>
<method>
<ejb-name>StudentEJB</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>

<container-transaction>
<method>
<ejb-name>StudentEJB</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>

</assembly-descriptor>
</ejb-jar>

*****************************************************
*****************************************************

jboss.xml:

<?xml version="1.0"?>

<jboss>
<secure>false</secure>
<container-configurations />
<resource-managers />
<enterprise-beans>
<entity>
<ejb-name>StudentEJB</ejb-name>
<jndi-name>StudentHomeRemote</jndi-name>
</entity>
</enterprise-beans>
</jboss>

***********************************************
***********************************************
jbosscmp-jdbc.xml:

<jbosscmp-jdbc>

<datasource>java:/MySqlDS</datasource>
<type-mapping>mySQL</type-mapping>

<enterprise-beans>
<entity>
<ejb-name>StudentEJB</ejb-name>
<table-name>student</table-name>
<create-table>false</create-table>
<cmp-field>
<field-name>id</field-name>
<column-name>id</column-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
<column-name>name</column-name>
</cmp-field>
<cmp-field>
<field-name>email</field-name>
<column-name>email</column-name>
</cmp-field>
</entity>
</enterprise-beans>
</jbosscmp-jdbc>

*****************************************+
******************************************

相關文章