Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-07
9
Medium Priority
?
622 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Accepted Solution

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

Assisted Solution

by:MogalManic
MogalManic earned 150 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Files go missing when using DFS (Distributed File System) Replication and how to recover them and fix it.
Check out what's been happening in the Experts Exchange community.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

718 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