1 Reply Latest reply on Aug 2, 2005 4:11 AM by Ulf Niesar

    Problem entering data in DB using a CMP in JBoss 4.0.2

    Sameer Saptarishi Newbie

      Hi All,

      I am using JBoss 4.0.2 and Postgres 7.2 as my database server.
      Now I am trying to insert a record in the DB using CMP beans meaning I have not written any SQL statements.
      Only abstract methods and the primarykey field is autogenerated by the DB.
      i.e it is of Serial type.

      Now when I run the EJB only the primary key field is generated by the rest of the values are not entered in the Database.Can anyone tell me why this could happen.

      Here is my META-INF directory in JBoss


      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>
      <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>HospitalManager</ejb-name>
      com.cygnet.medina.HospitalManager.HospitalManagerHome
      com.cygnet.medina.HospitalManager.HospitalManager
      <ejb-class>com.cygnet.medina.HospitalManager.HospitalManagerEJB</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>


      <assembly-descriptor>
      <container-transaction>

      <ejb-name>HospitalManager</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
      <cmp-version>2.x</cmp-version>
      <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>
      <!-- Added -->


      <ejb-name>Hospital</ejb-name>
      com.cygnet.medina.Hospital.HospitalHome
      com.cygnet.medina.Hospital.Hospital
      <ejb-class>com.cygnet.medina.Hospital.HospitalEJB</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Hospital</abstract-schema-name>
      <cmp-field>
      <field-name>hospitalid</field-name>
      <column-name>hospitalid</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>hospitalname</field-name>
      <column-name>hospitalname</column-name>
      </cmp-field>
      <primkey-field>hospitalid</primkey-field>

      <assembly-descriptor>
      <container-transaction>

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

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

      </enterprise-beans>
      </ejb-jar>


      ----------------------------------------------------------------------

      My 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:/PostgresDS
      <!-- 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"/>




      <!-- Added -->

      <ejb-name>Hospital</ejb-name>
      <pk-constraint>true</pk-constraint>
      <table-name>Hospital</table-name>
      <cmp-field>
      <field-name>hospitalid</field-name>
      <column-name>hospitalid</column-name>
      <jdbc-type>BIGINT</jdbc-type>
      <sql-type>SERIAL</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>hospitalname</field-name>
      <column-name>hospitalname</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>Text</sql-type>
      </cmp-field>
      <entity-command name="postgresql-fetch-seq"/>


      <!-- End -->
      </enterprise-beans>

      </jbosscmp-jdbc>
      -----------------------------------------------------------------------------------
      My postgresDS.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/MyDB</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>




      Please can any one tell me the reason.
      When I debug i can see all the values which I pass from the frontend in my ejbCreate() method.

      Thanks in Advance

      Cheers
      Sameer