• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMP 2.0 problem with MySQL server

 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am using Jboss 4.0.2 and MySQL4.1.13 windows version.
I am trying to insert a record in the database using CMP.
I get all the print in the ejbCreate method.
But when I see in the db a Null is inserted in hospitalname field and the hospitalid is autogenerated.
Can anyone tell me where I am making a mistake.

I would be very greatful.
Is there some configuration mistake.

Here is my code.
HospitalEJB.java
public abstract class HospitalEJB implements EntityBean {

private EntityContext context;
public Long hospitalid;
public String hospitalname;

public void ejbLoad() throws EJBException, RemoteException {

}
public void ejbActivate() throws EJBException, RemoteException {

}

public Long ejbCreate(HospitalData hospitalData) throws CreateException{
Long myid = new Long(UniqueIdGenerator.getId());
System.out.println("My id generated ====== "+myid);
this.hospitalid = new Long(123);
System.out.println("My id generated ====== "+this.hospitalid);
this.hospitalname = hospitalData.getHospitalname();
return null;

}

public void ejbPostCreate(HospitalData hospitalData)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 {

}





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

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

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

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


public HospitalData getHospitalData(){
HospitalData hospitalData = new HospitalData();
hospitalData.setHospitalid(this.hospitalid);
hospitalData.setHospitalname(this.hospitalname);
return hospitalData;
}


public void setHospitalData(HospitalData hospitalData){
this.hospitalname = hospitalData.getHospitalname();
}

}
----------------------------------------------------------------------
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>
<session>
<ejb-name>UserManager</ejb-name>
<home>com.cygnet.medina.UserManager.UserManagerHome</home>
<remote>com.cygnet.medina.UserManager.UserManager</remote>
<ejb-class>com.cygnet.medina.UserManager.UserManagerEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>UserManager</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>


<session>
<ejb-name>HospitalManager</ejb-name>
<home>com.cygnet.medina.HospitalManager.HospitalManagerHome</home>
<remote>com.cygnet.medina.HospitalManager.HospitalManager</remote>
<ejb-class>com.cygnet.medina.HospitalManager.HospitalManagerEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>HospitalManager</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

<entity>
<ejb-name>AnesthesiaUser</ejb-name>
<home>com.cygnet.medina.user.AnesthesiaUserHome</home>
<remote>com.cygnet.medina.user.AnesthesiaUser</remote>
<ejb-class>com.cygnet.medina.user.AnesthesiaUserEJB</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Long</prim-key-class>
<reentrant>False</reentrant>
<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>
<query-method>
<method-name>findByUsername</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql></ejb-ql>
</query>

</entity>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>AnesthesiaUser</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
<!-- Added -->

<entity>
<ejb-name>Hospital</ejb-name>
<home>com.cygnet.medina.Hospital.HospitalHome</home>
<remote>com.cygnet.medina.Hospital.Hospital</remote>
<ejb-class>com.cygnet.medina.Hospital.HospitalEJB</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Long</prim-key-class>
<reentrant>False</reentrant>
<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>
</entity>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Hospital</ejb-name>
<method-name>*</method-name>
</method>
<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>

<defaults>
<datasource>java:/MySqlDS</datasource>
<!-- 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>
</defaults>

<enterprise-beans>
<entity>
<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>BIGINT</sql-type>
</cmp-field>
<cmp-field>
<field-name>username</field-name>
<column-name>username</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(50)</sql-type>
</cmp-field>
<cmp-field>
<field-name>password</field-name>
<column-name>password</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(50)</sql-type>
</cmp-field>
<cmp-field>
<field-name>usertype</field-name>
<column-name>usertype</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(50)</sql-type>
</cmp-field>
<cmp-field>
<field-name>createddate</field-name>
<column-name>createddate</column-name>
<jdbc-type>TIMESTAMP</jdbc-type>
<sql-type>DATETIME</sql-type>
</cmp-field>
<cmp-field>
<field-name>updateddate</field-name>
<column-name>updateddate</column-name>
<jdbc-type>TIMESTAMP</jdbc-type>
<sql-type>DATETIME</sql-type>
</cmp-field>
<query>
<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>
</query>
<entity-command name="mysql-get-generated-keys"/>


</entity>

<!-- Added -->
<entity>
<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>BIGINT</sql-type>
</cmp-field>
<cmp-field>
<field-name>hospitalname</field-name>
<column-name>hospitalname</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(50)</sql-type>
</cmp-field>
<entity-command name="mysql-get-generated-keys"/>
</entity>

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

</jbosscmp-jdbc>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic