Solved

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

Posted on 2004-09-07
9
618 Views
Last Modified: 2008-02-01
thanks!
  i study ejb,can any experts give me  a opensource or demo ejb ,with some cmp,bmp or session bean .. thanks!
0
Comment
Question by:hgbdelphi
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 50 total points
ID: 12003840
0
 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 50 total points
ID: 12004668
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
 
LVL 12

Expert Comment

by:Giant2
ID: 12005349
Do you have seen on JBoss site?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 21

Expert Comment

by:MogalManic
ID: 12011161
?
0
 

Author Comment

by:hgbdelphi
ID: 12012510
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
 

Author Comment

by:hgbdelphi
ID: 12012517
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
 

Author Comment

by:hgbdelphi
ID: 12012607
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
 

Author Comment

by:hgbdelphi
ID: 12012745
ha,now i deplayed cmp successful!i make a wrong in jbosscmp-jdbc.xml  <datasource-mapping>
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 12016218
glad with you. :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question