请好心人一定帮忙看下jboss+mysql测试一个entitybean倒底错误在哪?

03-06-20 MafiaCat
请大家帮忙看下我的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>

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

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

jd2bs
2003-06-22 15:41
艾,我的问题几乎跟你相同.折腾两天了,没戏.

我是jboss3.0.7+eclipse+lomboz+mysql3.23.x

3.21里是mysql-ds.xml啊,我是mysql-service.xml

我按照banq推荐的文章配置,就是告诉我数据源找不到.

都快吐血了.

我在csdn的类似问题

bad_bird
2003-06-23 11:30
个人感觉应该是在几个配置文件中配置出错了。

尤其是conf下的两个文件,都是配置在各个数据库中,数据库变量类型所对应的java数据类型,最好不要改name标签的默认值。

应该不是程序的问题。

猜你喜欢