Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 625
  • Last Modified:

hi,experts,can experts give me a opensource or demo about ejb with cmp,bmp ?

thanks!
  i study ejb,can any experts give me  a opensource or demo ejb ,with some cmp,bmp or session bean .. thanks!
0
hgbdelphi
Asked:
hgbdelphi
  • 4
  • 2
  • 2
  • +1
2 Solutions
 
MogalManicCommented:
The famous (or infamous) pet store appliction has examples of all bean types and many enterprise patterns.
http://sourceforge.net/projects/xpetstore/ - using xDoclet
http://sourceforge.net/projects/ibatisjpetstore/ - Competitive .net implementation
http://java.sun.com/developer/releases/petstore/ - The original sun implementation
0
 
Giant2Commented:
Do you have seen on JBoss site?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
MogalManicCommented:
?
0
 
hgbdelphiAuthor Commented:
sorry for my dally over,now i have a demo about cmp,but it hava some error,please help me:
jboss4.0,sqlserver2000,win2000

error like this:

09:28:30,296 ERROR [MainDeployer] could not create deployment: file:/G:/jboss/se
rver/default/deploy/ejbmod.jar
org.jboss.deployment.DeploymentException: Error in ejb-jar.xml for Entity Bean T
Account: primkey-field Account is not a cmp-field
        at org.jboss.metadata.ApplicationMetaData.importEjbJarXml(ApplicationMet
aData.java:305)
        at org.jboss.metadata.XmlFileLoader.load(XmlFileLoader.java:151)
        at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:484)
        at org.jboss.deployment.MainDeployer.create(MainDeployer.java:817)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:673)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:637)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatch
er.java:141)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.
java:230)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
        at $Proxy7.deploy(Unknown Source)
        at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymen
tScanner.java:304)
        at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentS
canner.java:478)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
doScan(AbstractDeploymentScanner.java:201)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
loop(AbstractDeploymentScanner.java:212)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
run(AbstractDeploymentScanner.java:191)

mycmpbean:

/*
 * Created on 2004-9-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.beltino;

import javax.ejb.EntityBean;

/**
 *
 * <!-- begin-user-doc --> You can insert your documentation for '<em><b>TAccountBean</b></em>'. <!-- end-user-doc --> *
 <!--  begin-lomboz-definition -->
 <?xml version="1.0" encoding="UTF-8"?>
 <lomboz:EJB xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:lomboz="http://lomboz.objectlearn.com/xml/lomboz">
 <lomboz:entity>
 <lomboz:entityEjb>
 <j2ee:display-name>TAccount</j2ee:display-name>
 <j2ee:ejb-name>TAccount</j2ee:ejb-name>
 <j2ee:ejb-class>com.beltino.TAccountBean</j2ee:ejb-class>
 <j2ee:persistence-type>Container</j2ee:persistence-type>
 <j2ee:prim-key-class>java.lang.String</j2ee:prim-key-class>
 <j2ee:cmp-version>2.x</j2ee:cmp-version>
 <j2ee:abstract-schema-name>mySchema</j2ee:abstract-schema-name>
 <j2ee:primkey-field>Account</j2ee:primkey-field>
 </lomboz:entityEjb>
 <lomboz:fieldMappings>
 <lomboz:fieldName>Account</lomboz:fieldName>
 <lomboz:fieldType>java.lang.String</lomboz:fieldType>
 <lomboz:columnName>Account</lomboz:columnName>
 <lomboz:jdbcType>VARCHAR</lomboz:jdbcType>
 <lomboz:sqlType>varchar</lomboz:sqlType>
 <lomboz:readOnly>false</lomboz:readOnly>
 <lomboz:primaryKey>true</lomboz:primaryKey>
 </lomboz:fieldMappings>
 <lomboz:fieldMappings>
 <lomboz:fieldName>UserName</lomboz:fieldName>
 <lomboz:fieldType>java.lang.String</lomboz:fieldType>
 <lomboz:columnName>UserName</lomboz:columnName>
 <lomboz:jdbcType>VARCHAR</lomboz:jdbcType>
 <lomboz:sqlType>varchar</lomboz:sqlType>
 <lomboz:readOnly>false</lomboz:readOnly>
 <lomboz:primaryKey>false</lomboz:primaryKey>
 </lomboz:fieldMappings>
 <lomboz:tableName>TAccount</lomboz:tableName>
 <lomboz:dataSourceName>java:/MSSQLDS</lomboz:dataSourceName>
 </lomboz:entity>
 </lomboz:EJB>
 <!--  end-lomboz-definition -->
 *
 * <!-- begin-xdoclet-definition -->
 * @ejb.bean name="TAccount"
 *      jndi-name="TAccount"
 *      type="CMP"
 *  primkey-field="Account"
 *  schema="mySchema"
 *  cmp-version="2.x"
 *  data-source="java:/MSSQLDS"
 *--
 * This is needed for JOnAS.
 * If you are not using JOnAS you can safely remove the tags below.
 * @jonas.bean ejb-name="TAccount"
 *   jndi-name="TAccount"
 * @jonas.jdbc-mapping  jndi-name="java:/MSSQLDS" jdbc-table-name="TAccount"
 * --
 *
 *  @ejb.persistence
 *   table-name="TAccount"
 *
 * @ejb.finder
 *    query="SELECT OBJECT(a) FROM mySchema as a"  
 *    signature="java.util.Collection findAll()"  
 *
 *--
 * This is needed for JOnAS.
 * If you are not using JOnAS you can safely remove the tags below.
 * @jonas.finder-method-jdbc-mapping  method-name="findAll"
 *      jdbc-where-clause=""
 * @jonas.jdbc-mapping  jndi-name="java:/MSSQLDS"
 *      jdbc-table-name="TAccount"
 *
 *--
 * <!-- end-xdoclet-definition -->
 * @generated
 **/
public abstract class TAccountBean implements javax.ejb.EntityBean {

  /**
   *
   * <!-- begin-user-doc -->
   * The  ejbCreate method.
   * <!-- end-user-doc -->
   *
   * <!-- begin-xdoclet-definition -->
   * @ejb.create-method
   * <!-- end-xdoclet-definition -->
   * @generated
   */
  public java.lang.String ejbCreate(String account,String userName) throws javax.ejb.CreateException {
    // EJB 2.0 spec says return null for CMP ejbCreate methods.
    // TODO: YOU MUST INITIALIZE THE FIELDS FOR THE BEAN HERE.
    // setMyField("Something");
    // begin-user-code
        setAccount(account);
        setUserName(userName);
    return null;
    // end-user-code
  }

  /**
   * <!-- begin-user-doc -->
   * The container invokes this method immediately after it calls ejbCreate.
   * <!-- end-user-doc -->
   *
   * @generated
   */
  public void ejbPostCreate() throws javax.ejb.CreateException {
    // begin-user-code
    // end-user-code
  }

  /**
   *
   *
   * <!-- begin-user-doc -->
   * CMP Field Account
   *
   * Returns the Account
   * @return the Account
   *
   * <!-- end-user-doc -->
   *
   * <!-- begin-xdoclet-definition -->
   *
   * @ejb.persistent-field
   * @ejb.persistence
   *    column-name="Account"
   *     jdbc-type="VARCHAR"
   *     sql-type="varchar"
   *     read-only="false"
   * @ejb.pk-field
   *
   * @ejb.interface-method
   *
   * --
   * This is needed for JOnAS.
   * If you are not using JOnAS you can safely remove the tags below.
   * @jonas.cmp-field-jdbc-mapping  field-name="Account"
   *      jdbc-field-name="Account"
   *
   * --
   * <!-- end-xdoclet-definition -->
   * @generated
   */
  public abstract java.lang.String getAccount();

  /**
   * <!-- begin-user-doc -->
   * Sets the Account
   *
   * @param java.lang.String the new Account value
   * <!-- end-user-doc -->
   *
   * <!-- begin-xdoclet-definition -->
   * @ejb.interface-method
   * <!-- end-xdoclet-definition -->
   * @generated
   */
  public abstract void setAccount(java.lang.String Account);

  /**
   *
   *
   * <!-- begin-user-doc -->
   * CMP Field UserName
   *
   * Returns the UserName
   * @return the UserName
   *
   * <!-- end-user-doc -->
   *
   * <!-- begin-xdoclet-definition -->
   *
   * @ejb.persistent-field
   * @ejb.persistence
   *    column-name="UserName"
   *     jdbc-type="VARCHAR"
   *     sql-type="varchar"
   *     read-only="false"
   *  
   *
   * @ejb.interface-method
   *
   * --
   * This is needed for JOnAS.
   * If you are not using JOnAS you can safely remove the tags below.
   * @jonas.cmp-field-jdbc-mapping  field-name="UserName"
   *      jdbc-field-name="UserName"
   *
   * --
   * <!-- end-xdoclet-definition -->
   * @generated
   */
  public abstract java.lang.String getUserName();

  /**
   * <!-- begin-user-doc -->
   * Sets the UserName
   *
   * @param java.lang.String the new UserName value
   * <!-- end-user-doc -->
   *
   * <!-- begin-xdoclet-definition -->
   * @ejb.interface-method
   * <!-- end-xdoclet-definition -->
   * @generated
   */
  public abstract void setUserName(java.lang.String UserName);

}
0
 
hgbdelphiAuthor Commented:
this is my dbconn,i use this dbconn,it can get data:

package com.beltino.util;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2004
 * </p>
 * <p>
 * Company:
 * </p>
 *
 * @author not attributable
 * @version 1.0
 */
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.*;

public class DBConn {
    private Connection conn;
    private Statement stmt;
    private DataSource ds;
    public DBConn() {
        try {
            Context ctx = new InitialContext();
            ds = (javax.sql.DataSource) ctx.lookup("java:/MSSQLDS");
            conn = ds.getConnection();
            stmt = conn.createStatement();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public ResultSet executeQuery(String sql) {
        try {
            ResultSet rs = stmt.executeQuery(sql);
            return rs;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public boolean execute(String sql) {
        try {
            stmt.execute(sql);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean executeUpdate(String sql) {
        try {
            stmt.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public PreparedStatement getPreparedStmt(String sql) {
        PreparedStatement prepStmt = null;
        try {
            prepStmt = conn.prepareStatement(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return prepStmt;
    }
   

    public void close() {
        if (conn != null) {
            try {
                conn.close();
                conn = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
                stmt = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
0
 
hgbdelphiAuthor Commented:
this is my testjsp page:

<%@ page contentType="text/html; charset=gb2312" %>
<% request.setCharacterEncoding("gb2312"); %>
<%@ page import="java.sql.*" %>

<%@ page import="com.beltino.util.*" %>
<html>
<body>
<%

     DBConn dbConn=new DBConn();
     try{

     ResultSet rs=dbConn.executeQuery("select * from TAccount");
     while(rs.next()){
         out.println(rs.getString("Account")+"<br>");
         out.println(rs.getString("UserName"));
     }

     }catch(Exception e){

       e.printStackTrace();

     }

     finally{

       dbConn.close();

     }
     out.println("ok!");
 
%>
</body>
</html>
0
 
hgbdelphiAuthor Commented:
ha,now i deplayed cmp successful!i make a wrong in jbosscmp-jdbc.xml  <datasource-mapping>
0
 
sompol_kiatkamolchaiCommented:
glad with you. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now