查看:1978|回复:0
Xdoclet如何生成EntityBean代码发表时间:2013-01-14 15:21:26

洗心、革面。

0分享0主题0帖子

学徒一级

(初出茅庐)

首先创建一个entitybean,名称为User,如下图所示,需要注意,包名必须最后是.ejb结尾,否则xdoclet不认

创建完成后,检查生成的代码,User.java,会发现在类的上方,会出现如下的tag:

* @ejb.bean name="User"

* display-name="Name for User"

* description="Description for User"

* jndi-name="ejb/User"

* type="CMP"

* cmp-version="2.x"

* view-type="both"

这些是默认生成的tag,不能完全的符合我们的要求,我们修改成为如下,红色为增加的部分:

* @ejb.bean name = "User"

* type = "CMP"

* cmp-version = "2.x"

* display-name = "User"

* description = "User"

* view-type = "both"

* jndi-name = "ejb/UserHome"

* local-jndi-name = "ejb/UserLocalHome"

* primkey-field = "userId"

* @ejb.persistence table-name = "systemuser"

* @jboss.persistence table-name = "systemuser"

* @ejb:util

* generate="physical"

然后,需要为user entity增加它的几个相关的方法

在相关的地方修改这个抽象的类,修改后,红色为增加的部分:

public abstract class User implements EntityBean {

/** The entity context */

private EntityContext context;

/**

* @ejb.interface-method view-type = "both"

* @ejb.persistence column-name = "userId"

* @ejb.pk-field

*

* @return

*/

public abstract String getUserId();

/**

* @ejb.interface-method view-type = "both"

*

* @param userId

*/

public abstract void setUserId(String userId);

/**

* @ejb.interface-method view-type = "both"

* @ejb.persistence column-name = "userName"

*

* @return

*/

public abstract String getUserName();

/**

* @ejb.interface-method view-type = "both"

*

* @param userName

*/

public abstract void setUserName(String userName);

/**

* @ejb.interface-method view-type = "both"

* @ejb.persistence column-name = "Password"

*

* @return

*/

public abstract String getPassword();

/**

* @ejb.interface-method view-type = "both"

*

* @param password

*/

public abstract void setPassword(String Password);

好了,entitybean修改成为这样以后就可以生成相关的接口和实现类了

如果运行正常,在控制台窗口中会出现如下提示:

Buildfile: F:workspaceMyEJB.xdoclet-build.tmp.xml

N65540:

[ejbdoclet] (XDocletMain.start 47 ) Running <remoteinterface/>

[ejbdoclet] Generating Remote interface for 'com.mycom.myejb.entity.ejb.User'.

[ejbdoclet] (XDocletMain.start 47 ) Running <localinterface/>

[ejbdoclet] Generating Local interface for 'com.mycom.myejb.entity.ejb.User'.

[ejbdoclet] (XDocletMain.start 47 ) Running <homeinterface/>

[ejbdoclet] Generating Home interface for 'com.mycom.myejb.entity.ejb.User'.

[ejbdoclet] (XDocletMain.start 47 ) Running <localhomeinterface/>

[ejbdoclet] Generating Local Home interface for 'com.mycom.myejb.entity.ejb.User'.

[ejbdoclet] (XDocletMain.start 47 ) Running <dataobject/>

[ejbdoclet] Generating Data Object class for 'com.mycom.myejb.entity.ejb.User'.

[ejbdoclet] (XDocletMain.start 47 ) Running <valueobject/>

[ejbdoclet] (XDocletMain.start 47 ) Running <entitypk/>

[ejbdoclet] (XDocletMain.start 47 ) Running <entitycmp/>

[ejbdoclet] Generating CMP class for 'com.mycom.myejb.entity.ejb.User'.

[ejbdoclet] (XDocletMain.start 47 ) Running <entitybmp/>

[ejbdoclet] (XDocletMain.start 47 ) Running <session/>

[ejbdoclet] (XDocletMain.start 47 ) Running <dao/>

[ejbdoclet] (XDocletMain.start 47 ) Running <utilobject/>

[ejbdoclet] Generating Util class for 'com.mycom.myejb.entity.ejb.User'.

[ejbdoclet] (XDocletMain.start 47 ) Running <deploymentdescriptor/>

[ejbdoclet] Generating EJB deployment descriptor (ejb-jar.xml).

[ejbdoclet] (XDocletMain.start 47 ) Running <jboss/>

[ejbdoclet] Generating jboss.xml.

[ejbdoclet] Generating jbosscmp-jdbc.xml.

_xdoclet_generation_:

BUILD SUCCESSFUL

Total time: 8 seconds

如果你在运行中,出现了

N65540:

BUILD FAILED

java.lang.UnsupportedClassVersionError: xjavadoc/ant/XJavadocTask (Unsupported major.minor version 49.0)

的异常,建议你更换以下eclipse的jre环境。例如当我用jdk1.4.2的时候就出现上述异常,更换为jdk1.5后即正常运行。

您需要登录以后才可以回帖    登录|注册