EJBPostCreate

My major problem in container managed persistence is whether EjbpostCreate() populates relationships automatically without one witing codes for them.

Hi
If I remember correctly it is called after the container has created the DB row for a CMP entity bean. That means that when ejbPostCrate is called the entity bean exists, when the ejbCreate is called the entity does not exist.
OK this was not wery clear, hopefully someone else can clear it up for you.
//Samuel

Similar Messages

  • What is use of ejbPostCreate(), what it returns, where exactly can it be in

    what is use of ejbPostCreate(), what it returns, where exactly can it be invoked?

    Why don't you try reading or googling or something, rather than asking every question that pops into your head?

  • EjbPostCreate being ignored

    I have a CMP entity bean, and I am having problems creating it:
    I get :
    cannot insert NULL into ("BEAKER"."COMPANIES"."PROFILE_ID")
    ...which means that the ejbPostCreate is being ignored and nothing is being inserted for COMPANIES and PROFILE_ID
    My ejbCreate and ejbPostCreate have identical paramater headers so I am confused why it is not being called. I am using Sun One Application Server 7 which I think could be part of the problem.
    My two methods are as follows :
    * @ejb.create-method
    public LongIdentifier ejbCreate(Profile profile,
    String name,
    Country country,
    Currency currency,
    String userName) throws javax.ejb.CreateException
    try
    setKeyValue(new Long(getSequenceGenerator().getNextCompanyId()));
    catch (SQLException e)
    throw new CreateException(e.getMessage());
    catch (NamingException e)
    throw new CreateException(e.getMessage());
    this.setName(name);
    this.setUpdatedBy(userName);
    this.setUpdatedDate(new Date());
    this.setCreatedBy(userName);
    this.setCreatedDate(new Date());
    this.setActive(true);
    // EJB 2.0 spec says return null for CMP ejbCreate methods.
    return null;
    * Set all CMR fields for the CMP bean
    * @param profile
    * @param name
    * @param country
    * @param currency
    * @throws javax.ejb.CreateException
    public void ejbPostCreate(Profile profile,
    String name,
    Country country,
    Currency currency,
    String userName) throws javax.ejb.CreateException
    //the following print statements are not showing in the log trace
    System.out.println("in ejbPostCreate");
    System.out.println("profile = " + profile.getName());
    System.out.println("country = " + country.getName());
    System.out.println("currency = " + currency.getName());
    setProfile(profile);
    setCountry(country);
    setCurrency(currency);
    //setCreatedBy(user);
    }

    First of all CMP entity bean doesn't need
    this.setName(name);
    It is just
    setName(name);
    and ofcourse need to return null.
    and I can see that you are not set the ID for the Profile_ID
    that's while it is null value. If ID is not auto increasement then you need to set the ID there..

  • Exception in method: ejbPostCreate: java.lang.IllegalArgumentException

    Hi,
    when i ported our application from 6.1(SP3) to 7.0(SP1),
    I am getting the java.lang.IllegalArgumentException.
    I am attaching the relevent stack trace
    <Info> <EJB> <010051> <EJB Exception during invoc
    ation from home: com.ibsplc.gulfshare.reservation.booking.ejb.ReservationManager
    EJB_5uuvrj_LocalHomeImpl@1824d6 threw exception: javax.ejb.TransactionRolledback
    LocalException: EJB Exception:; nested exception is: java.lang.IllegalArgumentException:
    Illegal attempt to assign a removed bean to a CMR field. The EJB with primary
    key 'com.ibsplc.gulfshare.reservation.booking.ejb.ReservationPK@1920' has been
    removed and cannot be assigned to this CMR field.
    javax.ejb.TransactionRolledbackLocalException: EJB Exception:; nested exceptionis:
    java.lang.IllegalArgumentException: Illegal attempt to assign a removed bean to
    a CMR field.

    Hi satheesh,
    am kamal. am also getting the same exception
    " nested exception is: java.lang.IllegalArgumentException: [EJB:010133]Illegal attempt to assign a removed bean to a CMR field. The EJB with primary key '1' has been removed and cannot be assigned to this CMR field."
    in my case am using two entity beans one for customer-order and the other for customer-Address. am creating the address bean within ejbPostcreate of order.
    while running the client am getting the exception "Illegal attempt to assign a removed bean to a CMR field"
    have you found any solution for it. can you pls hlp me on this. am held up whith this problem.
    regards,
    kamal.

  • CMR - two phase create ( ejbCreate + ejbPostCreate)

    HI,
    I have two tables. There is a CMR between the tables.
    customer
    customer_id (PK)
    individual
    individual_id (PK)
    customer_id (FK)
    It seems to me that when using CMR that
    1. The foreign key is required to be optional.
    2. The create process is a two phase operation, i.e. first create the base record using ejbCreate and then set up the relationship using ejbPostCreate.
    Are the above two points correct?
    If so ...I am in trouble, because my DBA ( quite rightly in my opinion) is refusing to make the foreign key optional...db integrity etc.
    Is this a J2EE thing ....or an application server thing ( I am using OC4J).
    hope I am making sense,
    thanks in advance
    Kevin

    Hi,
    The relationship must be initialized during the creation process. Typically, this is done in the bean implementation method ejbPostCreate().
    When you create an entity for the state of New York, you must also create and initialize its relationship with the capital city of Albany.
    The entity bean would not get inserted into DB until ejbCreate() and ejbPostCreate() methods are called.
    Thanks.
    speduri.

  • What is the use of ejbPostCreate()?

    Can any body tell me What is the exact or relative purpose of ejbPostCreate() method?

    Hello,
    The container invoke the postCreate method just after the ejbCreate.
    unlike the ejb Create the postCreate method can invoke getPrimaryKey end getEJBObject method of the entityContext interface.

  • Cannot deploy EntityBean from Weblogic 5.1

    Hi everyone,
    I'm relatively new to EJB deployment, but there is an Entity bean that I was able to deploy using Weblogic 4.0 and fail to do the same with Weblogic 5.1, although I'm going through all the necessary steps, like creating xmls (ejb_jar, weblogic-cmp-rdbms-jar, and weblogic-ejb-jar), creating a jar file, and recompiling it using weblogic.ejbc, and that's where it stops. While it works fine with session beans, every time I'm trying to deploy entity bean, it gives me the following message:
    ERROR: Error from ejbc: [9.1.5.1] In EJB EmployerEntityEJB, there is an ejbPostCreate method ejbPostCreate() that has no matching ejbCreate method.
    Yet my ejbCreate and ejbPostCreate methods do match, unless I'm missing something, but at this point I have no idea what exactly. Any kind of help would be great, 'cause I'm almost out of ideas.
    Here's the code I'm working on:
    EmployerEntity.java:
    import java.rmi.*;
    import java.sql.*;
    import javax.ejb.*;
    import java.util.*;
    public interface EmployerEntity extends EJBObject, Remote {
    public boolean postingUpdate(Hashtable posting) throws RemoteException,SQLException;
    public void callingBreakHashtable(Hashtable posting) throws RemoteException;
    EmployerEntityHome.java:
    import java.rmi.*;
    import javax.ejb.*;
    import java.io.*;
    import java.util.*;
    import javax.naming.*;
    public interface EmployerEntityHome extends EJBHome{
    public EmployerEntity create(Hashtable posting) throws RemoteException, EJBException, CreateException;
    public EmployerEntity findByPrimaryKey(EmployerEntityPK job_id) throws FinderException,RemoteException;
    public EmployerEntity findByPosition(int job_id) throws FinderException,RemoteException;
    EmployerEntityPK.java:
    import java.io.Serializable;
    public class EmployerEntityPK {
    public int job_id;
    and finally EmployerEntityBean.java (I left only ejbCreat and ejbPostCreate methods, so that I won't confuse anybody):
    import java.io.*;
    import java.util.*;
    import javax.ejb.*;
    import javax.naming.*;
    import java.rmi.*;
    import java.sql.*;
    //and local classes
    public class EmployerEntityBean extends LocalClassEntityBean {
    Hashtable posting=new Hashtable();
    public EmployerEntityBean() {}
    public EmployerEntityPK ejbCreate(Hashtable posting) throws EJBException, CreateException {
    if (posting_entity_flag)
    this.posting=posting;
    callingBreakHashtable(posting);
    Syslog.debug(this,"EJBCreate Called ");
    return null;
    public void ejbPostCreate(Hashtable posting) throws EJBException {
    Syslog.debug(this,"EJBPostCreate Called ");
    Thanks for your help.
    PS. Also, could it be that the error that I'm getting might be caused by something other than simply mismatching ejbCreate and ejbPostCreate? If so, what are the other possible reasons?
    Thanks

    Hi,
    First of all, you don't need to add EJBException in your method definition as its a runtime exception. Next your ejbPostCreate() is missing the CreateException and thats the reason you have a mismatch.
    Also your remote interface should extend EJBObject ( which is a subclass of java.rmi.Remote). Catch the SQLException and rethrow it as an EJBException with proper message. And finally I take it that LocalClassEntityBean implements EntityBean.
    Best wishes

  • How to insert data in a one-to-many relationship

    How do you insert data into the client, my model entity beans have a one-to-many relationship.
    PARENT ENTITY BEAN
    PARENT-ID
    PARENT-NAME
    The ejbCreate(Integer parentID,String name)
    CHILD ENTITY BEAN
    CHILD-ID
    CHILD-NAME
    PARENT-ID(foreign key of PARENTID).
    ejbCreate(Integer parentID,String name,String foreignparentID)
    In a jsp page i collect the parent details and 3 corresponding chld details in a text box.
    Can you please tell me how do i proceed from here...
    ie. how to i insert data into the entity beans..
    Do i pass the child as a collection, and within parents ejbCreate() method do i lookup for the childs home interface and insert one -by -one from the collection.
    1. Considering the above example, can some one pls tell how the ejbCreate() mehod signatures, for the parent and child entity beans should be.
    2. Pls also show some sample client code as to how to make an insertion.
    3. In case you are passing a collection of child data, then in what format does one have to insert into a collection and also how does the container know how to insert the values in the child table , bcoz we are passing as a collection.
    4.In case collections cannot be inserted do we need to iterate into the collection in parent's ejbCreate() method, and manually insert into the database of the childtable, thereby creating child entity beans.
    Thanks for your time and support...
    regards
    kartik

    Hi,
    3. In this case of course child's ejbCreate(and postCreate) looks like
    ejbCreate(Integer childID,String name,ParentLocal parent) {
    setId(Id);
    setName(name);
    ejbPostCreate(Integer childID,String name,ParentLocal parent) {
    setParent(parent);
    Here you don't need IDs, but it happens only using Locals, not Remotes, if I'm not wrong. Container does it itself.
    1. Of course, if you have parent.getChildren() and parent.setChildren() then you don't need any loops, but it should be done anyway in postCreate, because in ejbCreate there no parent exists yet.
    Once more 3: example - I'm using JBoss 3.2.5 as EJB container. It has tomcat inside and EJB and JSP+Struts use the same jvm. It means for me that I don't need to use remote interfaces, just locals. And in this case I can implement ejb-relations. So, a have the abstract method parent.getChildren() which returns Collection of ChildLocal - s and method parent.setChildren(Collection childrenLocals) which creates/modifies children by itself.
    I have not used remotes for a long time, but as I remember it was not possible to implement ejb-relations using remotes.
    regards,
    Gio

  • Unique Key Violation While Doing Multiple Updates And Create in EJB

    Hello All,
    I am using oracle 9i and Weblogic 7.0. I have a table that has a unique key constraint on one column , say 'Col1' and i am using a CMP to read,create and update data in this table. The problem description is as follows.
    I have JTable that display the data from the above said table. The user can modify the existing data and insert new data that will be reflected in the DB using the CMP. Let us say the following are displayed
    ROW1
    Col1 : 3
    Col2 : 'ABC'
    Col3 : 1 (Primary key in the table)
    Now the user modifies the above row and inserts a new record. Now the following will be the display
    ROW1 (Modified)
    Col1 : 4
    Col2 : 'ABC'
    Col3 : 1 (Primary key in the table)
    ROW2 (New)
    Col1 : 3
    Col2 : 'DEF'
    Col3 : 2 (Primary key in the table)
    When the above data is saved i do the following in the Code
    a) Session Bean
    For (all the data in the Jtable)
    try
    home.findByPrimaryKey(Col3);
    remote.update(Col1,Col2);
    catch(FinderException fe)
    home.create(Col1,Col2,Col3);
    When the above code is run During the first loop the update runs succesfully (i.e update old value of 3 with 4 ) but during the 2nd loop the create (i.e Insert new value 3) gives me the unique key violated exception. The following is the stack trace
    <Oct 25, 2004 11:36:22 AM IST> <Info> <EJB> <010049> <EJB Exception in method: ejbPostCreate: java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated
    java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1892)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2130)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2013)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2869)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
    at weblogic.jdbc.jts.Statement.executeUpdate(Statement.java:509)
    at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.__WL_create(TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.java:1435)
    at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.ejbPostCreate(TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.java:1353)
    at java.lang.reflect.Method.invoke(Native Method)
    at weblogic.ejb20.manager.DBManager.create(DBManager.java:1023)
    at weblogic.ejb20.manager.DBManager.localCreate(DBManager.java:904)
    at weblogic.ejb20.internal.EntityEJBLocalHome.create(EntityEJBLocalHome.java:180)
    at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop_LocalHomeImpl.create(TerminalPaymentsCMP_kbdoop_LocalHomeImpl.java:73)
    at de.dl.ucs.contract.helperclasses.SubsegmentMaintanence.saveTerminalPayments(SubsegmentMaintanence.java:697)
    at de.dl.ucs.contract.controller.SubsegmentSL.saveSubsegmentDetails(SubsegmentSL.java:570)
    at de.dl.ucs.contract.controller.SubsegmentSL.processFinanceSubsegmentSave(SubsegmentSL.java:1601)
    at de.dl.ucs.contract.controller.SubsegmentSL_kgzv4j_EOImpl.processFinanceSubsegmentSave(SubsegmentSL_kgzv4j_EOImpl.java:498)
    at de.dl.ucs.contract.events.FinanceSubsegmentBEH.saveSubsegmentDetails(FinanceSubsegmentBEH.java:749)
    at de.dl.ucs.contract.events.FinanceSubsegmentBEH.processEvent(FinanceSubsegmentBEH.java:232)
    at de.dl.ucs.framework.flowcontroller.ControllerBean.delegateAction(ControllerBean.java:229)
    at de.dl.ucs.framework.flowcontroller.ControllerBean_riqvk4_EOImpl.delegateAction(ControllerBean_riqvk4_EOImpl.java:46)
    at de.dl.ucs.framework.flowcontroller.ControllerBean_riqvk4_EOImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:441)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:382)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:726)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:377)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:234)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:210)
    >
    <Oct 25, 2004 11:36:22 AM IST> <Info> <EJB> <010051> <EJB Exception during invocation from home: [email protected] threw exception: javax.ejb.TransactionRolledbackLocalException: EJB Exception:; nested exception is: java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated
    Please help me with this, as far as i am concerned since both update and create is in the same transaction the update on the row must be visible to the create and hence there shouild not be any problem.....
    thanks in advance
    Shanki

    Hi,
    Thanks,
    There are 3 columns involved with that table . Out of whihc one is a Primary Key (string) , The other column (Number) has a unique key constraint defined on it and the last column stores a value corresponding to the 2nd column.
    The reason for me to do a create in the Finder exception is as follows.
    I Loop through the Data present in JTable. As given in the example let us assume that there are 2 rows in the JTable. Out of whihc the First row needs an updation and the second row , which is a new row needs to be created. So During the First iteration of the loop, The findermethod does not throw any exception (Because it is a modfied row) and hence the update gets fired successfully. During the second iteration , since it is a new row the findermethod will throw a finder exception and hence create will get fired.
    I understand that this is not a good coding style but then it is not 100% wrong and i need to find out as to why it is not working.
    Hope am clear in explaining my problem
    Thanks
    Shanki

  • Why MYSQL error come

    when I deploy cmp bean on jboss-3.2.2 it gives following error (I use lomboz plugins):-
    5:53:11,197 INFO [EjbModule] Deploying FirstStat
    15:53:11,728 WARN [EntityContainer] No resource manager found for jdbc/MySqlDs
    15:53:13,320 ERROR [EntityContainer] Starting failed
    org.jboss.deployment.DeploymentException: Error in jbosscmp-jdbc.xml : datasource-mapping MYSQL not found
         at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityMetaData.<init>(JDBCEntityMetaData.java:433)
         at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.<init>(JDBCApplicationMetaData.java:310)
    Note:- Stateless or stateful bean created with dao, accessing of database normally.
    FirstStatBean.class
    * Created on Jan 23, 2006
    * TODO To change the template for this generated file go to
    * Window - Preferences - Java - Code Style - Code Templates
    package chaman.com;
    import java.rmi.RemoteException;
    import javax.ejb.EJBException;
    import javax.ejb.EntityBean;
    import javax.ejb.EntityContext;
    * <!-- begin-user-doc --> You can insert your documentation for '<em><b>FirstcmpBean</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>Firstcmp</j2ee:display-name>
    <j2ee:ejb-name>Firstcmp</j2ee:ejb-name>
    <j2ee:ejb-class>chaman.com.FirstcmpBean</j2ee:ejb-class>
    <j2ee:persistence-type>Container</j2ee:persistence-type>
    <j2ee:prim-key-class>java.lang.Integer</j2ee:prim-key-class>
    <j2ee:cmp-version>2.x</j2ee:cmp-version>
    <j2ee:abstract-schema-name>ecr</j2ee:abstract-schema-name>
    <j2ee:primkey-field>id</j2ee:primkey-field>
    </lomboz:entityEjb>
    <lomboz:fieldMappings>
    <lomboz:fieldName>id</lomboz:fieldName>
    <lomboz:fieldType>java.lang.Integer</lomboz:fieldType>
    <lomboz:columnName>id</lomboz:columnName>
    <lomboz:jdbcType>VARCHAR</lomboz:jdbcType>
    <lomboz:sqlType>INT</lomboz:sqlType>
    <lomboz:readOnly>false</lomboz:readOnly>
    <lomboz:primaryKey>true</lomboz:primaryKey>
    </lomboz:fieldMappings>
    <lomboz:fieldMappings>
    <lomboz:fieldName>fname</lomboz:fieldName>
    <lomboz:fieldType>java.lang.String</lomboz:fieldType>
    <lomboz:columnName>fname</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:fieldMappings>
    <lomboz:fieldName>lname</lomboz:fieldName>
    <lomboz:fieldType>java.lang.String</lomboz:fieldType>
    <lomboz:columnName>lname</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:fieldMappings>
    <lomboz:fieldName>phone</lomboz:fieldName>
    <lomboz:fieldType>java.lang.String</lomboz:fieldType>
    <lomboz:columnName>phone</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>address</lomboz:tableName>
    <lomboz:dataSourceName></lomboz:dataSourceName>
    </lomboz:entity>
    </lomboz:EJB>
    <!-- end-lomboz-definition -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.bean name="Firstcmp"
    *     jndi-name="Firstcmp"
    *     type="CMP"
    * primkey-field="id"
    * schema="ecr"
    * cmp-version="2.x"
    * data-source=""
    * @ejb.persistence
    * table-name="address"
    * @ejb.finder
    * query="SELECT OBJECT(a) FROM ecr as a"
    * signature="java.util.Collection findAll()"
    * @ejb.pk class="java.lang.Integer"
    * @ejb.resource-ref res-ref-name="jdbc/MySqlDs"
    * res-auth="Container"
    * @jbos.resource-ref res-ref-name="jdbc/MySqlDs"
    * jndi-name="java:/MySqlDS"
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract class FirstcmpBean implements javax.ejb.EntityBean {
    protected EntityContext eContext;
    * <!-- begin-user-doc -->
    * The ejbCreate method.
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.create-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public java.lang.Integer ejbCreate(Integer id, String fname,String lname, String phone ) 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
         setId(id);
         setFname(fname);
         setLname(lname);
         setPhone(phone);
    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(Integer id, String fname,String lname, String phone) throws javax.ejb.CreateException {
    // begin-user-code
    // end-user-code
    * <!-- begin-user-doc -->
    * CMP Field id
    * Returns the id
    * @return the id
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.persistent-field
    * @ejb.persistence
    * column-name="id"
    * jdbc-type="VARCHAR"
    * sql-type="INT"
    * read-only="false"
    * @ejb.pk-field
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract java.lang.Integer getId();
    * <!-- begin-user-doc -->
    * Sets the id
    * @param java.lang.Integer the new id value
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract void setId(java.lang.Integer id);
    * <!-- begin-user-doc -->
    * CMP Field fname
    * Returns the fname
    * @return the fname
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.persistent-field
    * @ejb.persistence
    * column-name="fname"
    * jdbc-type="VARCHAR"
    * sql-type="VARCHAR"
    * read-only="false"
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract java.lang.String getFname();
    * <!-- begin-user-doc -->
    * Sets the fname
    * @param java.lang.String the new fname value
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract void setFname(java.lang.String fname);
    * <!-- begin-user-doc -->
    * CMP Field lname
    * Returns the lname
    * @return the lname
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.persistent-field
    * @ejb.persistence
    * column-name="lname"
    * jdbc-type="VARCHAR"
    * sql-type="VARCHAR"
    * read-only="false"
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract java.lang.String getLname();
    * <!-- begin-user-doc -->
    * Sets the lname
    * @param java.lang.String the new lname value
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract void setLname(java.lang.String lname);
    * <!-- begin-user-doc -->
    * CMP Field phone
    * Returns the phone
    * @return the phone
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.persistent-field
    * @ejb.persistence
    * column-name="phone"
    * jdbc-type="VARCHAR"
    * sql-type="VARCHAR"
    * read-only="false"
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract java.lang.String getPhone();
    * <!-- begin-user-doc -->
    * Sets the phone
    * @param java.lang.String the new phone value
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract void setPhone(java.lang.String phone);
         /* (non-Javadoc)
         * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
         public void setEntityContext(EntityContext arg0) throws EJBException,
                   RemoteException {
              // TODO Auto-generated method stub
    this.eContext= arg0;
         /* (non-Javadoc)
         * @see javax.ejb.EntityBean#unsetEntityContext()
         public void unsetEntityContext() throws EJBException, RemoteException {
              // TODO Auto-generated method stub
    this.eContext=null;
    jbosscmp-jdbc.class
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
    <jbosscmp-jdbc>
    <defaults>
    <datasource>java:/MySqlDS</datasource>
    <datasource-mapping>MYSQL</datasource-mapping>
    <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
    </defaults>
    <enterprise-beans>
    <!--
    To add beans that you have deployment descriptor info for, add
    a file to your XDoclet merge directory called jbosscmp-jdbc-beans.xml
    that contains the <entity></entity> markup for those beans.
    -->
    <entity>
    <ejb-name>Firstcmp</ejb-name>
    <table-name>address</table-name>
    <cmp-field>
    <field-name>id</field-name>
    <column-name>id</column-name>
    <jdbc-type>VARCHAR</jdbc-type>
    <sql-type>INT</sql-type>
    </cmp-field>
    <cmp-field>
    <field-name>fname</field-name>
    <column-name>fname</column-name>
    <jdbc-type>VARCHAR</jdbc-type>
    <sql-type>VARCHAR</sql-type>
    </cmp-field>
    <cmp-field>
    <field-name>lname</field-name>
    <column-name>lname</column-name>
    <jdbc-type>VARCHAR</jdbc-type>
    <sql-type>VARCHAR</sql-type>
    </cmp-field>
    <cmp-field>
    <field-name>phone</field-name>
    <column-name>phone</column-name>
    <jdbc-type>VARCHAR</jdbc-type>
    <sql-type>VARCHAR</sql-type>
    </cmp-field>
    </entity>
    </enterprise-beans>
    </jbosscmp-jdbc>

    thank u for sending solution.
    cmp file successfully deployed but one prob. creats, when i send parameters values of
    create method (create("suman","kumar")) through client file, it inserts data correctly in table
    but it gives following error(Table stru:- (id int auto_increment primary key, fname varchar(20), lname varchar(20)):-
    javax.ejb.CreateException: Primary key for created instance is null.
         at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:520)
         at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:208)
         at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:269)
         at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:736)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(

  • FOREIGN KEY IS PRIMARY KEY

    Hi,
    Has anyone come across the following problem?
    I have two tables
    customer individual
    customer_id (PK) customer_id (PK)
    customer_id in individual is the primary key for that table. It is also a foreign key ( related back to customer).
    If I use JDeveloper to drag in the two tables ( into a class diagraqm), I have a problem.
    JDeveloper "sees" the Individual bean foreign key mapping and generates a getCustomer() method (which returns a handle to the appropriate customer bean).
    However as it "removes" the getCustomer_id() method(which returns the actual customer_id), the primary_key reference is dropped.
    When I try and compile, JDeveloper quite rightly complains with "where is the primary key".
    Can anyone help? Do I need to make it a rule that the foreign key is not also the primary key?
    thanks in advance,
    Kevin

    Hello,
    I am having the same problem attempting to use a foreign key as a primary key in an EJB 2.0 CMR running on WLS 6.1. If I do not set the foreign key portion of my composite key in the ejbCreate() method I get an error stating that the field cannot be null (and must be set), when I set the field in the ejbCreate I then get an Error in the ejbPostCreate stating that CMR fields cannot be set using the setXXX methods. The entity relations are as follows:
    SalesOrder <--------------------------------------->SalesOrderProduct
    SalesOrder = (orderid(PK)+orderstatus+salesrepid+contractdate+processdate)
    SalesOrderProduct = (orderid(PK/FK)+productid(PK)+qty+unitcost)
    The CMR relationship is bi-directional. The SalesOrder entity bean's ejbPostCreate() method
    invokes a helper method that attempts to create the salesOrder product entity as part of the salesorder create transaction and that's when I get the errors stated above.
    Have or anyone found out how to handle this kind of cmr using the Weblogic server (6.1) and ejb 2.0??
    Thanks,
    Darryl

  • Error when using OC4J Datasource

    Hi,
    A customer is using a Servlet to run in an OC4j instance and is using EJB's for data DML.
    To work around the possibility that XMLTypes are not supported we do an update in the DoPost.
    public void ejbPostCreate(String mediumnummer, String inzender, String inhoud, PrlBerichttypeLocal prlBerichttypeLocal)
    OracleConnection oconnection = null;
    OraclePreparedStatement opstmt = null;
    CLOB tempCLOB = null;
    try
    oconnection = (OracleConnection)getConnection();
    String sql = "";
    sql += "update prl_xml_berichten SET ";
    sql += "INHOUD = XMLTYPE(?) where id = ?";
    opstmt = (OraclePreparedStatement)oconnection.prepareCall(sql);
    System.out.println(sql);
    System.out.println("username : "+ oconnection.getMetaData().getUserName());
    tempCLOB = CLOB.createTemporary(oconnection,true,CLOB.DURATION_SESSION);
    Writer writer = tempCLOB.getCharacterOutputStream();
    writer.write(inhoud);
    writer.flush();
    writer.close();
    opstmt.setCLOB(1,tempCLOB);
    opstmt.setLong(2,id.longValue());
    boolean test = opstmt.execute();
    tempCLOB.trim(0);
    if (!test) System.out.println("Succes !!!!");
    else System.out.println("Failure!!!");
    // connection.commit();
    catch (Exception exc)
    System.out.println("Fout bij inhoud update ");
    exc.printStackTrace();
    finally
    try
    if (opstmt != null) opstmt.close();
    if (oconnection != null) oconnection.close();
    System.out.println("create dopost gedaan...");
    catch (SQLException sqlex)
    sqlex.getMessage();
    System.out.println("Fout bij afsluiten dopost");
    When they are using the getConnection from the Datasource:
    private Connection getConnection() throws NamingException, SQLException
    InitialContext context = new InitialContext();
    DataSource dataSource = null;
    // Look up data source object in directory service using JNDI
    dataSource = (DataSource)context.lookup("jdbc/prlDS");
    // Establishing db connection
    return dataSource.getConnection();
    The following error occurs:
    username : PRL
    create dopost gedaan...
    com.evermind.server.rmi.OrionRemoteException: javax.ejb.EJBException: java.lang.AbstractMethodError: oracle.jdbc.OracleConnection oracle.jdbc.OracleConnection.unwrap()
    java.rmi.RemoteException com.evermind.server.ejb.EJBUtils.getUserException(java.lang.Throwable, boolean) EJBUtils.java:263
    java.lang.String CheckIn_StatelessSessionBeanWrapper8.checkInMessage(java.lang.String[]) CheckIn_StatelessSessionBeanWrapper8.java:126
    When we change it to the connection setup with a hard string it does work:
    private Connection getConnection() throws NamingException, SQLException
    DriverManager.registerDriver(new OracleDriver());
    return DriverManager.getConnection(Receiver.DATASOURCE);
    Does anybody have an idea what the difference is with the direct connect string or the datasource from OC4J.
    I attached the full error and the datasource.xml.
    Regards,
    Remco

    Hi Remco,
    You may not be aware of this, but the "Connection" returned from a "DataSource" is not necessarily the same as the one returned from "DriverManager". If I remember correctly, there was a similar question to yours posted to this forum, not so long ago. As I recall, Steve Button mentioned that there are emulated and non-emulated "Connection"s. I saw no mention in your post regarding which version of OC4J you are using, so I will assume the latest, stand-alone, production version (9.0.3). The Data Sources chapter of Oracle9iAS Containers for J2EE Services Guide has more details.
    Good Luck,
    Avi.

  • Unable to execute the cmp using the weblogic

    I was trying to execute cmp using weblogic server7.0.
    It a simple program,
    The remote interface-
    import javax.ejb.*;
    import java.rmi.RemoteException;
    public interface SportTeam extends EJBObject{
    public void setOwnerName(String ownerName) throws RemoteException;
    public String getOwnerName() throws RemoteException;
    public void setFranchiseName(String franchiseName) throws RemoteException;
    public String getFranchiseName() throws RemoteException;
    }The home interface
    import javax.ejb.*;
    import java.rmi.RemoteException;
    import java.util.Collection;
    public interface SportTeamHome extends EJBHome{
    SportTeam create(String sport,String nickName)throws RemoteException,CreateException;
    SportTeam create(String sport,String nickName,String ownerName,String franchisePlayer)throws RemoteException,CreateException;
    SportTeam findByPrimaryKey(SportTeamPK sportTeam) throws RemoteException,FinderException;
    Collection findByOwnerName(String ownerName) throws RemoteException,FinderException;
    }The bean
    import javax.ejb.*;
    import javax.naming.*;
    import java.rmi.RemoteException;
    import java.sql.*;
    import java.util.*;
    public abstract class SportTeamEJB implements EntityBean{
    public SportTeamPK ejbCreate(String sport,String nickName) throws CreateException {
    setSport(sport);
    setNickName(nickName);
    setOwnerName(null);
    setFranchiseName(null);
    return null;
    public void ejbPostCreate(String sport,String nickName){}
    public SportTeamPK ejbCreate(String sport,String nickName,String ownerName,String franchiseName) throws CreateException {
    setSport(sport);
    setNickName(nickName);
    setOwnerName(ownerName);
    setFranchiseName(franchiseName);
    return null;
    public void ejbPostCreate(String sport,String nickName,String ownerName,String franchiseName){}
    public void ejbLoad(){}
    public void ejbStore(){}
    public void ejbRemove(){}
    public void ejbActivate(){}
    public void ejbPassivate(){}
    public void setEntityContext(EntityContext ctx){}
    public void unsetEntityContext(){}
    abstract public String getSport();
    abstract public void setSport(String sport);
    abstract public String getNickName();
    abstract public void setNickName(String nickName);
    abstract public String getOwnerName();
    abstract public void setOwnerName(String ownerName);
    abstract public String getFranchiseName();
    abstract public void setFranchiseName(String franchiseName);
    }the client side program
    import java.rmi.RemoteException;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import java.util.Properties;
    import java.util.Collection;
    import java.util.Iterator;
    public class TestClient{
    public static void main(String[] args){
    try{
         Properties prop=new Properties();
         prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
         prop.setProperty(Context.PROVIDER_URL,"t3://localhost:7001");
         InitialContext initial=new InitialContext(prop);
         Object objref=initial.lookup("CMPSportBean");
         SportTeamHome home=(SportTeamHome)PortableRemoteObject.narrow(objref,SportTeamHome.class);
         System.out.println("Creating a row.");
         home.create("basketball","Kings","Joe Maloof","Jason Williams");
         System.out.println("Looking up by primary key...");
         SportTeam team=home.findByPrimaryKey(new SportTeamPK("basketball","Kings"));
         System.out.println("Current franchise player:");
         System.out.println(team.getFranchiseName());
         System.out.println("Looking by by owner...");
         Collection col=home.findByOwnerName("Joe Maloof");
         if(     0 == col.size()     ){
              System.out.println("Found no such owner");
         }else {
              Iterator iter=col.iterator();
              while(iter.hasNext()){
              Object objref2=iter.next();
              SportTeam teamRef2=(SportTeam) PortableRemoteObject.narrow(objref2,SportTeam.class);
              System.out.println("Owner name:"+ teamRef2.getOwnerName());
    team.remove();
    }catch(RemoveException re){
         re.printStackTrace();
    }catch(NamingException ne){
         ne.printStackTrace();
    }catch(CreateException ce){
         ce.printStackTrace();
    }catch(FinderException fe){
         fe.printStackTrace();
    }catch(RemoteException re){
                  re.printStackTrace();
    }The primary key class
    //package sportBean.cmp;
    import java.io.Serializable;
    public class SportTeamPK implements Serializable{
    public String sport;
    public String nickName;
    public SportTeamPK(){}
    public SportTeamPK(String sport,String nickName){
    this.sport =sport;
    this.nickName=nickName;
    public String getSport(){
    return sport;
    public String getNickName(){
    return nickName;
    public int hashCode(){
    return (sport+nickName).hashCode();
    public boolean equals(Object other){
         if( (other == null) ||! (other instanceof SportTeamPK) ){
            return false;
         SportTeamPK otherPK=(SportTeamPK)other;
         return sport.equals(otherPK.sport) && nickName.equals(otherPK.nickName);
    The program has complied successfully .
    The META-INF directory has been created automatically
    the ejb-jar.xml file
    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
    <!-- Generated XML! -->
    <ejb-jar>
      <enterprise-beans>
        <entity>
          <ejb-name>CMPSportBean</ejb-name>
          <home>SportTeamHome</home>
          <remote>SportTeam</remote>
          <ejb-class>SportTeamEJB</ejb-class>
          <persistence-type>Container</persistence-type>
          <prim-key-class>SportTeamPK</prim-key-class>
          <reentrant>False</reentrant>
          <abstract-schema-name>SportEJB</abstract-schema-name>
          <cmp-field>
            <field-name>sport</field-name>
          </cmp-field>
          <cmp-field>
            <field-name>nickName</field-name>
          </cmp-field>
          <cmp-field>
            <field-name>ownerName</field-name>
          </cmp-field>
          <cmp-field>
            <field-name>franchiseName</field-name>
          </cmp-field>
          <query>
            <query-method>
              <method-name>findByOwnerName</method-name>
              <method-params>
                <method-param>java.lang.String</method-param>
              </method-params>
            </query-method>
            <ejb-ql><![CDATA[SELECT OBJECT(o) FROM SportEJB AS o WHERE o.ownerName=?1]]></ejb-ql>
          </query>
        </entity>
      </enterprise-beans>
      <assembly-descriptor>
      </assembly-descriptor>
    </ejb-jar>the weblogic-ejb-jar.xml file
    <!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN' 'http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd'>
    <!-- Generated XML! -->
    <weblogic-ejb-jar>
      <weblogic-enterprise-bean>
        <ejb-name>CMPSportBean</ejb-name>
        <entity-descriptor>
          <pool>
          </pool>
          <entity-cache>
            <max-beans-in-cache>1000</max-beans-in-cache>
            <idle-timeout-seconds>600</idle-timeout-seconds>
            <read-timeout-seconds>600</read-timeout-seconds>
            <cache-between-transactions>False</cache-between-transactions>
          </entity-cache>
          <persistence>
            <persistence-use>
              <type-identifier>WebLogic_CMP_RDBMS</type-identifier>
              <type-version>6.0</type-version>
              <type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
            </persistence-use>
          </persistence>
          <entity-clustering>
          </entity-clustering>
        </entity-descriptor>
        <transaction-descriptor>
          <trans-timeout-seconds>2</trans-timeout-seconds>
        </transaction-descriptor>
        <jndi-name>CMPSportBean</jndi-name>
      </weblogic-enterprise-bean>
    </weblogic-ejb-jar>the weblogic-cmp-rdbms-jar.xml file
    <!DOCTYPE weblogic-rdbms-jar PUBLIC  '-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB RDBMS Persistence//EN' 'http://www.bea.com/servers/wls700/dtd/weblogic-rdbms20-persistence-700.dtd'>
    <!-- Generated XML! -->
    <weblogic-rdbms-jar>
      <weblogic-rdbms-bean>
        <ejb-name>CMPSportBean</ejb-name>
        <data-source-name>myjdbcjndi</data-source-name>
        <table-map>
          <table-name>sportsteams</table-name>
          <field-map>
            <cmp-field>ownerName</cmp-field>
            <dbms-column>ownername</dbms-column>
          </field-map>
          <field-map>
            <cmp-field>franchiseName</cmp-field>
            <dbms-column>franchisename</dbms-column>
          </field-map>
          <field-map>
            <cmp-field>nickName</cmp-field>
            <dbms-column>nickname</dbms-column>
          </field-map>
          <field-map>
            <cmp-field>sport</cmp-field>
            <dbms-column>sport</dbms-column>
          </field-map>
        </table-map>
        <weblogic-query>
          <query-method>
            <method-name>findByOwnerName</method-name>
            <method-params>
              <method-param>java.lang.String</method-param>
            </method-params>
          </query-method>
        </weblogic-query>
        <check-exists-on-method>False</check-exists-on-method>
      </weblogic-rdbms-bean>
      <create-default-dbms-tables>True</create-default-dbms-tables>
    </weblogic-rdbms-jar>I tried to write config.xml file
    <JDBCDataSource
       Name=" "
       JNDIName="myjdbcjndi"
       PoolName="MyJDBC Connection Pool"
       Targets="myserver"
    />
    <JDBCConnectionPool
       Name="MyJDBC Connection Pool"
       Targets="myserver"
        URL="jdbc:odbc:test"
        DriverName="sun.jdbc.odbc.JdbcOdbcDriver"
        InitialCapacity="1"
        MaxCapacity="10"
    />When i tried to deploy, it showed me errors-
    weblogic.management.ApplicationException: activate failed forcmp
    Start server side stack trace:
    weblogic.management.ApplicationException: activate failed forcmp
    Module Name: cmp, Error: Exception activating module: EJBModule(cmp,status=PREPARED)
    Unable to deploy EJB: CMPSportBean from cmp:
    weblogic.ejb20.WLDeploymentException: The DataSource with the JNDI name: myjdbcjndi could not be located. Please ensure that the DataSource has been deployed successfully and that the JNDI name in your EJB Deployment descriptor is correct.
         at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.setup(RDBMSPersistenceManager.java:138)
         at weblogic.ejb20.manager.BaseEntityManager.setupPM(BaseEntityManager.java:211)
         at weblogic.ejb20.manager.BaseEntityManager.setup(BaseEntityManager.java:181)
         at weblogic.ejb20.manager.DBManager.setup(DBManager.java:162)
         at weblogic.ejb20.deployer.ClientDrivenBeanInfoImpl.activate(ClientDrivenBeanInfoImpl.java:945)
         at weblogic.ejb20.deployer.EJBDeployer.activate(EJBDeployer.java:1296)
         at weblogic.ejb20.deployer.EJBModule.activate(EJBModule.java:349)
         at weblogic.j2ee.J2EEApplicationContainer.activateModule(J2EEApplicationContainer.java:1592)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1029)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1016)
         at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:1112)
         at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:732)
         at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:24)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    TargetException:
    Unable to deploy EJB: CMPSportBean from cmp:
    weblogic.ejb20.WLDeploymentException: The DataSource with the JNDI name: myjdbcjndi could not be located. Please ensure that the DataSource has been deployed successfully and that the JNDI name in your EJB Deployment descriptor is correct.
         at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.setup(RDBMSPersistenceManager.java:138)
         at weblogic.ejb20.manager.BaseEntityManager.setupPM(BaseEntityManager.java:211)
         at weblogic.ejb20.manager.BaseEntityManager.setup(BaseEntityManager.java:181)
         at weblogic.ejb20.manager.DBManager.setup(DBManager.java:162)
         at weblogic.ejb20.deployer.ClientDrivenBeanInfoImpl.activate(ClientDrivenBeanInfoImpl.java:945)
         at weblogic.ejb20.deployer.EJBDeployer.activate(EJBDeployer.java:1296)
         at weblogic.ejb20.deployer.EJBModule.activate(EJBModule.java:349)
         at weblogic.j2ee.J2EEApplicationContainer.activateModule(J2EEApplicationContainer.java:1592)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1029)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1016)
         at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:1112)
         at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:732)
         at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:24)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1035)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1016)
         at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:1112)
         at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:732)
         at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:24)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    End server side stack trace
    Module Name: cmp, Error: Exception activating module: EJBModule(cmp,status=PREPARED)
    Unable to deploy EJB: CMPSportBean from cmp:
    weblogic.ejb20.WLDeploymentException: The DataSource with the JNDI name: myjdbcjndi could not be located. Please ensure that the DataSource has been deployed successfully and that the JNDI name in your EJB Deployment descriptor is correct.
         at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.setup(RDBMSPersistenceManager.java:138)
         at weblogic.ejb20.manager.BaseEntityManager.setupPM(BaseEntityManager.java:211)
         at weblogic.ejb20.manager.BaseEntityManager.setup(BaseEntityManager.java:181)
         at weblogic.ejb20.manager.DBManager.setup(DBManager.java:162)
         at weblogic.ejb20.deployer.ClientDrivenBeanInfoImpl.activate(ClientDrivenBeanInfoImpl.java:945)
         at weblogic.ejb20.deployer.EJBDeployer.activate(EJBDeployer.java:1296)
         at weblogic.ejb20.deployer.EJBModule.activate(EJBModule.java:349)
         at weblogic.j2ee.J2EEApplicationContainer.activateModule(J2EEApplicationContainer.java:1592)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1029)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1016)
         at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:1112)
         at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:732)
         at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:24)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    TargetException:
    Unable to deploy EJB: CMPSportBean from cmp:
    weblogic.ejb20.WLDeploymentException: The DataSource with the JNDI name: myjdbcjndi could not be located. Please ensure that the DataSource has been deployed successfully and that the JNDI name in your EJB Deployment descriptor is correct.
    Start server side stack trace:
    weblogic.ejb20.WLDeploymentException: The DataSource with the JNDI name: myjdbcjndi could not be located. Please ensure that the DataSource has been deployed successfully and that the JNDI name in your EJB Deployment descriptor is correct.
         at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.setup(RDBMSPersistenceManager.java:138)
         at weblogic.ejb20.manager.BaseEntityManager.setupPM(BaseEntityManager.java:211)
         at weblogic.ejb20.manager.BaseEntityManager.setup(BaseEntityManager.java:181)
         at weblogic.ejb20.manager.DBManager.setup(DBManager.java:162)
         at weblogic.ejb20.deployer.ClientDrivenBeanInfoImpl.activate(ClientDrivenBeanInfoImpl.java:945)
         at weblogic.ejb20.deployer.EJBDeployer.activate(EJBDeployer.java:1296)
         at weblogic.ejb20.deployer.EJBModule.activate(EJBModule.java:349)
         at weblogic.j2ee.J2EEApplicationContainer.activateModule(J2EEApplicationContainer.java:1592)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1029)
         at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1016)
         at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:1112)
         at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:732)
         at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:24)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    End server side stack trace
         <<no stack trace available>>
         <<no stack trace available>>
    I tried to put the file into the directory structure.
    I kept the class files into the WEB-INF/classess
    I could'nt understand whats wrong with it.
    Please help me it is urgent, if i could understand it i can proceed further

    Hi,
    I had the same error as you. I'm agree with arvind_India (previous). You must :
    1. Define a correct Connection Pool (warning: deploy it on your managed server).
    2. Test your connection Pool on your managed server.
    3. Create a DataSource from your connection Pool.
    4. Deploy your DataSource on your managed server.
    5. Verify the JNDI TREE of your managed server (Now, the JNDI name of your dataSource must appair).
    6. Deploy your Entity Bean (the error has disapeared).
    David (Paris-France).

  • Error while deploying CMP.. can u pls tell me...

    Hi,
    Below is the error my jboss 3.2.3 container is throwing when i tried to deploy my CMP entity bean. It says
    my ejbFindByPrimaryKey() method must be implemented,but in a CMP i am told the container will take care of the implementation, one just has to specify it in the home object.. can anyone pls tell me where i could have gone wrong.
    2004-07-09 12:47:39,825 INFO [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/D:/jboss-3.2.3/server/default/deploy/product.jar
    2004-07-09 12:47:40,404 WARN [org.jboss.ejb.EJBDeployer.verifier] EJB spec violation:
    Bean : Product
    Section: 12.2.2
    Warning: The class must be defined as public and must not be abstract.
    2004-07-09 12:47:40,404 WARN [org.jboss.ejb.EJBDeployer.verifier] EJB spec violation:
    Bean : Product
    Section: 12.2.5
    Warning: Every entity bean must define the ejbFindByPrimaryKey method.
    2004-07-09 12:47:40,419 ERROR [org.jboss.deployment.MainDeployer] could not create deployment: file:/D:/jboss-3.2.3/server/default/deploy/product.jar
    org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.
         at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:491)
         at org.jboss.deployment.MainDeployer.create(MainDeployer.java:786)
         at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:641)
         at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:605)
         at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
         at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
         at $Proxy6.deploy(Unknown Source)
         at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:302)
         at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:476)
         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)

    This is my code
    ProductBean
    import javax.ejb.EntityContext;
    import javax.ejb.EntityBean;
    public abstract class ProductBean implements EntityBean {
         protected EntityContext ctx;
         //All set and get Methods
         public abstract String getName();
         public abstract void setName(String name);
         public abstract String getDescription() ;
         public abstract void setDescription(String desc);
         public abstract double getBasePrice() ;
         public abstract void setBasePrice(double baseprice);
         public abstract String getProductID();     
         public abstract void setProductID(String prodname);
         //EJB required Methods
         public void ejbActivate(){
              System.out.println("ejbActivate called");
         public void ejbRemove(){
              System.out.println("ejbRemove called");
         public void ejbPassivate(){
              System.out.println("ejbPassivate called");
         public void ejbLoad(){
              System.out.println("ejbLoad called");
         public void ejbStore(){
              System.out.println("ejbStore called");
         public void setEntityContext(EntityContext ctx){
              System.out.println("setEntityContext called");
              this.ctx=ctx;
         public void UnsetEntityContext(){
              System.out.println("UnsetEntityContext called");
              this.ctx=null;
         public void ejbPostCreate(String productID,String name,String description,double basePrice){
              System.out.println("ejbPostCreate called");
         public ProductKey ejbCreate(String productID,String name,String description,double basePrice){
              System.out.println("Create method  called");
              setProductID(productID);
              setName(name);
              setDescription(description);
              setBasePrice(basePrice);
              return new ProductKey(productID); // i am not sure which to retun,
              //return null;
                                               //Well just on a note for the above
                                              // I READ THAT CMP2.0 MUST RETURN NULL, BUT IN ED-ROMANS MASTERING
                                              // EJB  IT SAYS THE BEAN MUST RETURN THE PRIMARY KEY CLASS.
                                              // I HAVE TRIED BOTH THE ABOVE RETURN VALUES, STILL I GET THE SAME
                                              / /ERROR.
    HomeInterface
    import java.rmi.RemoteException;
    import java.util.Collection;
    import javax.ejb.CreateException;
    import javax.ejb.EJBHome;
    import javax.ejb.FinderException;
    public interface ProductHome extends EJBHome {
         public Product create(String productID,String name,String description,double basePrice)throws CreateException,RemoteException;
         public Product findByPrimaryKey(ProductKey key) throws FinderException,RemoteException;
         public Collection findByName(String name) throws RemoteException,FinderException;
         public Collection findByDescription(String desc) throws RemoteException,FinderException;
         public Collection findByBasePrice(double basePrice) throws RemoteException,FinderException;
         public Collection findByExpensiveProduct(double minPrice ) throws RemoteException,FinderException;
         public Collection findCheapProducts(double maxPrice) throws RemoteException,FinderException;
         public Collection findAllProducts() throws RemoteException,FinderException;
    RemoteInterface
    import java.rmi.RemoteException;
    import javax.ejb.EJBObject;
    public interface Product extends EJBObject {
         public String getName() throws RemoteException;
         public void setName(String name)throws RemoteException;
         public String getDescription() throws RemoteException;
         public void setDescription(String desc) throws RemoteException;
         public double getBasePrice() throws RemoteException;
         public void setBasePrice(double baseprice)throws RemoteException;
         public String getProductID()throws RemoteException;     
    ProductKey class - This is my PRIMARY KEY CLASS
    import java.io.Serializable;
    public class ProductKey implements Serializable{
         public String productID;
         public ProductKey(){          
         public ProductKey(String prodID){
              productID=prodID;
         public String toString(){
              return productID;
         public int hashCode()     {
              return productID.hashCode();
         public boolean equals(Object prod){
              return ((ProductKey)prod).productID.equals(productID);
    This is my ejb-jar.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!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 >
       <description><![CDATA[No Description.]]></description>
       <display-name>Generated by XDoclet</display-name>
       <enterprise-beans>
          <entity>
             <description><![CDATA[]]></description>
             <ejb-name>Product</ejb-name>
             <home>ProductHome</home>
             <local-home>ProductHomeLocal</local-home>
             <remote>Product</remote>
             <local-remote>ProductLocal</local-remote>
             <ejb-class>ProductBean</ejb-class>
               <persistence-type>Bean</persistence-type>
               <prim-key-class>ProductKey</prim-key-class>
               <reentrant>False</reentrant>     
               <cmp-version>2.x</cmp-version>
              <abstract-schema-name>ProductBean</abstract-schema-name>
              <cmp-field> <field-name>productID</field-name></cmp-field>
              <cmp-field> <field-name>name</field-name></cmp-field>
              <cmp-field> <field-name>description</field-name></cmp-field>
              <cmp-field> <field-name>basePrice</field-name></cmp-field>       
               <primkey-field>productID</primkey-field>
            <query>
                 <query-method>
                      <method-name>findByName</method-name>
                           <method-params>
                                <method-param>java.lang.String</method-param>
                           </method-params>
                 </query-method>
                 <ejb-ql>
                           <![CDATA[SELECT OBJECT(a) from ProductBean as a where name=?1]]>
                 </ejb-ql>
            </query>
            <query>
                 <query-method>
                      <method-name>findByBasePrice</method-name>
                           <method-params>
                                <method-param>double</method-param>
                           </method-params>
                 </query-method>
                 <ejb-ql>
                           <![CDATA[SELECT OBJECT(a) from ProductBean as a where basePrice = ?1]]>
                 </ejb-ql>
            </query>
            <query>
                 <query-method>
                      <method-name>findExpensiveProducts</method-name>
                           <method-params>
                                <method-param>double</method-param>
                           </method-params>
                 </query-method>
                 <ejb-ql>
                           <![CDATA[SELECT OBJECT(a) from ProductBean as a where basePrice > ?1]]>
                 </ejb-ql>
            </query>
            <query>
                 <query-method>
                      <method-name>findCheapProducts</method-name>
                           <method-params>
                                <method-param>double</method-param>
                           </method-params>
                 </query-method>
                 <ejb-ql>
                           <![CDATA[SELECT OBJECT(a) from ProductBean as a where basePrice < ?1]]>
                 </ejb-ql>
            </query>
                    <query>
                 <query-method>
                      <method-name>findAllProducts</method-name>
                           <method-params>
                                <method-param>double</method-param>
                           </method-params>
                 </query-method>
                 <ejb-ql>
                           <![CDATA[SELECT OBJECT(a) from ProductBean as a where productID IS NOT NULL]]>
                 </ejb-ql>
            </query>
                 </entity>
          </enterprise-beans>
       </ejb-jar>
    This is my jboss.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">
    <jboss>
       <unauthenticated-principal>nobody</unauthenticated-principal>
       <enterprise-beans>
          <entity>
             <ejb-name>Product</ejb-name>
             <jndi-name>ProductHome</jndi-name>
              <local-jndi-name>ProductHomeLocal</local-jndi-name>
          </entity>
       </enterprise-beans>
       <resource-managers>
       </resource-managers>
    </jboss>
    This is my jbosscmp-jdbc.xml
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
    <jbosscmp-jdbc>
       <defaults>
         <datasource>java:/OracleDS</datasource>
         <datasource-mapping>Oracle8</datasource-mapping>
       </defaults>
       <enterprise-beans>
          <entity>
             <ejb-name>Product</ejb-name>
             <table-name>ProductTable</table-name>
             <cmp-field>
                <field-name>productID</field-name>
                <column-name>PRODUCTID</column-name>
            </cmp-field>
             <cmp-field>
                <field-name>name</field-name>
                <column-name>NAME</column-name>
            </cmp-field>
            <cmp-field>
                <field-name>description</field-name>
                <column-name>DESCRIPTION</column-name>
            </cmp-field>
            <cmp-field>
                <field-name>basePrice</field-name>
                <column-name>BASEPRICE</column-name>
            </cmp-field>
          </entity>
       </enterprise-beans>
    </jbosscmp-jdbc>

  • Composite Primary Key Error

    I am using Sun One App Server PE8.
    I have a class with a composite primary key field. When I place the following method in my Home interface:
    public MyEjb findByPrimaryKey(MyEjbPrimaryKey pk) throws FinderException, RemoteException;I get the following error when deploying:
    ejbFindByPrimaryKey(EjbPrimaryKey) is already defined in MyEjb1368202910_ConcreteImpl
        public MyEjbPrimaryKey ejbFindByPrimaryKey (MyEjbPrimaryKey key)However, If i remove this method from the Home interface, i get the following error when running the verification tool:
    Error: No single arg findByPrimaryKey(PrimaryKeyClass) method was found in home interface class [ MyEjb ].However, I can still deploy the EAR successfully.
    Another related symptom of this problem, is if I include the following method in my Home interface:
    public MyEjb findByPrimaryKey(String pkField1, String pkField2) throws FinderException, RemoteException;And call this method, I get the following exception at runtime:
    java.rmi.RemoteException: Bean class for ejb [MyEjb] does not define a method corresponding to [Home] interface method [public abstract MyEjb MyEjbHome.findByPrimaryKey(java.lang.String,java
    .lang.String) throws javax.ejb.FinderException,java.rmi.RemoteException]I get these same problems with all EJB's that use composite keys. Has anyone else had this problem?
    Thanks
    toby

    This is a CMP bean, with no ejbFindByPrimaryKey in the Bean class. Below, i have included the Home interface and the Bean class (with unneccessary code removed)
    Thanks for looking at this for me.
    BEAN CLASS
    package lands.mc.bus.prod;
    import java.rmi.*;
    import java.util.*;
    import javax.ejb.*;
    public abstract class TopoMapBean implements EntityBean
      private EntityContext entity;
      public TopoMapBean()
      public void setEntityContext(EntityContext ctx)
        entity = ctx;
      public void unsetEntityContext()
        entity = null;
      public TopoMapPrimaryKey ejbCreate(String mapName, String mapNumber, String mnemonic,String edition, String scale)
      throws CreateException
        // call setters...
        return null;
      public void ejbPostCreate( String mapName,
                                                   String mapNumber,
                                             String mnemonic,
                                             String edition,
                                             String scale )
      removed set/get methods
      public void ejbStore() {}
      public void ejbLoad() {}
      public void ejbActivate() {}
      public void ejbPassivate() {}
      public void ejbRemove() {}
    }HOME INTERFACE
    package lands.mc.bus.prod;
    import java.rmi.*;
    import java.util.*;
    import javax.ejb.*;
    public interface TopoMapHome extends EJBHome
      public TopoMap create(String mapName,
                            String mapNumber,
                            String mnemonic,
                            String edition,
                            String scale
      throws CreateException, RemoteException;
      public TopoMap findByPrimaryKey(String mapNumber, String edition) throws FinderException, RemoteException;
    // doesnt deploy with this signature
    //  public TopoMap findByPrimaryKey(TopoMapPrimaryKey pkey) throws FinderException;
    // have to use this method instead of findByPrimaryKey(String, String) above
      public TopoMap findTopoMap(String mapNumber, String edition) throws FinderException, RemoteException;

Maybe you are looking for