0 Replies Latest reply on Jul 21, 2005 4:20 AM by Sameer Saptarishi

    Using CMP data is not inserted in to DB.

    Sameer Saptarishi Newbie

      Hi friends,
      I am using JBoss 4.0.2 and Postgres 7.2 ds.
      I have written the following EJB

      public abstract class AnesthesiaUserEJB implements EntityBean {
      private EntityContext context;
      public Long userid;
      public String username;
      public String password;
      public Date createddate;
      public Date updateddate;
      public String usertype;

      public void ejbLoad() throws EJBException, RemoteException {

      }
      public void ejbActivate() throws EJBException, RemoteException {

      }
      public Long ejbCreate(UserData userData) throws CreateException {
      System.out.println("@@@@@@@@Called Came in EJBCreate@@@@@@@");
      System.out.println("@@@@@1"+userData.getUsername());
      System.out.println("@@@@@2"+userData.getPassword());
      System.out.println("@@@@@3"+userData.getUsertype());

      //Long myid = new Long(UniqueIdGenerator.getId());
      //System.out.println("My id generated ====== "+myid);
      //this.userid = new Long(123);
      //System.out.println("My id generated ====== "+this.userid);

      //try{

      this.createddate = new Date();
      this.updateddate = createddate;
      this.username = userData.getUsername();
      this.password = userData.getPassword();
      this.usertype = userData.getUsertype();

      /* }catch(NullPointerException ne){
      System.out.println("Came in null pointer exception");
      System.out.println(ne.getMessage());
      }catch(Exception e){
      System.out.println("Error in ejbCreate");
      e.printStackTrace();
      }*/
      return userid;
      }
      public void ejbPostCreate(UserData userData) throws CreateException,RemoteException {


      }
      public void ejbRemove()
      throws RemoveException, RemoteException, EJBException {

      }

      public void setEntityContext(EntityContext context)
      throws EJBException, RemoteException {

      }

      public void unsetEntityContext() throws EJBException, RemoteException {


      }

      public void ejbPassivate() throws EJBException, RemoteException {

      }

      public void ejbStore() throws EJBException, RemoteException {

      }



      public UserData getUserData() {
      System.out.println("Came in AnesthesiaUserManagerEJB getUserData");
      UserData userData = new UserData();
      System.out.println("1");
      userData.setUsername(this.username);
      System.out.println("2" + userData.getUsername());
      userData.setPassword(this.password);
      System.out.println("3"+userData.getPassword());
      userData.setUserid(this.userid);
      System.out.println("4" + userData.getUserid());
      userData.setUsertype(usertype);
      System.out.println("5" + userData.getUsertype());
      userData.setCreateddate(this.createddate);
      System.out.println("6" + userData.getCreateddate());
      userData.setUpdateddate(this.updateddate);
      System.out.println("7" + userData.getUpdateddate());
      return userData;
      }

      public void setUserData(UserData userData) {
      this.updateddate = new Date();
      this.username = userData.getUsername();
      this.password = userData.getPassword();
      this.usertype = userData.getUsertype();
      }



      /**
      * @return
      */
      public abstract String getPassword();

      /**
      * @return
      */
      public abstract String getUsername();

      /**
      * @param string
      */
      public abstract void setPassword(String string);



      /**
      * @param string
      */
      public abstract void setUsername(String string);

      public abstract void setUsertype(String string);

      public abstract String getUsertype();


      /**
      * @return
      */
      public abstract Long getUserid();

      /**
      * @param long1
      */
      public abstract void setUserid(Long long1);

      /**
      * @return
      */
      public abstract Date getCreateddate();


      /**
      * @return
      */
      public abstract Date getUpdateddate();

      /**
      * @param date
      */
      public abstract void setCreateddate(Date date);

      /**
      * @param date
      */
      public abstract void setUpdateddate(Date date);

      } //End of class

      Following is the ejb-jar and jbossjdbccmp.xml

      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>
      <enterprise-beans>

      <ejb-name>UserManager</ejb-name>
      com.cygnet.medina.UserManager.UserManagerHome
      com.cygnet.medina.UserManager.UserManager
      <ejb-class>com.cygnet.medina.UserManager.UserManagerEJB</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>


      <assembly-descriptor>
      <container-transaction>

      <ejb-name>UserManager</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>


      <ejb-name>AnesthesiaUser</ejb-name>
      com.cygnet.medina.user.AnesthesiaUserHome
      com.cygnet.medina.user.AnesthesiaUser
      <ejb-class>com.cygnet.medina.user.AnesthesiaUserEJB</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <abstract-schema-name>AnesthesiaUser</abstract-schema-name>
      <cmp-field>
      <field-name>userid</field-name>
      <column-name>userid</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>username</field-name>
      <column-name>username</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      <column-name>password</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>usertype</field-name>
      <column-name>usertype</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>createddate</field-name>
      <column-name>createddate</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>updateddate</field-name>
      <column-name>updateddate</column-name>
      </cmp-field>
      <primkey-field>userid</primkey-field>

      <query-method>
      <method-name>findByUsername</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql></ejb-ql>



      <assembly-descriptor>
      <container-transaction>

      <ejb-name>AnesthesiaUser</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </enterprise-beans>
      </ejb-jar>

      jbosscmp-jdbc .xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC
      "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN"
      "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">

      <!-- ===================================================================== -->
      <!-- -->
      <!-- Standard JBossCMP-JDBC Configuration -->
      <!-- -->
      <!-- ===================================================================== -->

      <!-- $Id: standardjbosscmp-jdbc.xml,v 1.84.2.6 2005/01/26 18:51:35 starksm Exp $ -->

      <jbosscmp-jdbc>


      java:/DefaultDS
      <!-- optional since 4.0 <datasource-mapping>Hypersonic SQL</datasource-mapping> -->
      <create-table>true</create-table>
      <remove-table>false</remove-table>
      <read-only>false</read-only>
      <read-time-out>300000</read-time-out>
      <row-locking>false</row-locking>
      <pk-constraint>true</pk-constraint>
      <fk-constraint>false</fk-constraint>


      <enterprise-beans>

      <ejb-name>AnesthesiaUser</ejb-name>
      <pk-constraint>true</pk-constraint>
      <table-name>AnesthesiaUser</table-name>
      <cmp-field>
      <field-name>userid</field-name>
      <column-name>userid</column-name>
      <jdbc-type>BIGINT</jdbc-type>
      <sql-type>SERIAL</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>username</field-name>
      <column-name>username</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>Text</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      <column-name>password</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>Text</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>usertype</field-name>
      <column-name>usertype</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>Text</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>createddate</field-name>
      <column-name>createddate</column-name>
      <jdbc-type>DATE</jdbc-type>
      <sql-type>DATETIME</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>updateddate</field-name>
      <column-name>updateddate</column-name>
      <jdbc-type>DATE</jdbc-type>
      <sql-type>DATETIME</sql-type>
      </cmp-field>

      <query-method>
      <method-name>findByUsername</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <jboss-ql><![CDATA[
      SELECT OBJECT(u)
      FROM AnesthesiaUser u
      WHERE u.username = ?1 ]]></jboss-ql>

      <entity-command name="postgresql-fetch-seq"/>



      </enterprise-beans>
      </jbosscmp-jdbc>

      Following is the postgres-ds.xml
      <?xml version="1.0" encoding="UTF-8"?>

      <!-- ===================================================================== -->
      <!-- -->
      <!-- JBoss Server Configuration -->
      <!-- -->
      <!-- ===================================================================== -->

      <!-- $Id: postgres-ds.xml,v 1.3 2004/09/15 14:37:40 loubyansky Exp $ -->
      <!-- ==================================================================== -->
      <!-- Datasource config for Postgres -->
      <!-- ==================================================================== -->



      <local-tx-datasource>
      <jndi-name>PostgresDS</jndi-name>
      <connection-url>jdbc:postgresql://192.168.1.33:5432/AnesthesiaDB</connection-url>
      <driver-class>org.postgresql.Driver</driver-class>
      <user-name>postgres</user-name>

      <!-- sql to call when connection is created
      <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->

      <!-- sql to call on an existing pooled connection when it is obtained from pool
      <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->

      <type-mapping>PostgreSQL 7.2</type-mapping>

      </local-tx-datasource>




      The primary key field is a serial sqltype.
      When I try to insert a record in the database Only the primary field is inserted.But the other field values are not inserted into the DB.

      Can anyone tell me what the problem is ??

      Thanks a lot in advance
      P2