[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jboss-user
Subject:    [JBoss-user] [Persistence & CMP/JBoss] - Using Auto-increment PK from MySQL
From:       oskar <nukes () jboss ! org>
Date:       2004-11-30 21:38:10
Message-ID: 10564840.1101850690828.JavaMail.jboss () colo-br-02 ! atl ! jboss ! com
[Download RAW message or body]

Hello!

I'm using JBOSS 4.0 with a MySQL DB.

I try to create a Entity CMP EJB with serveral fields. 

One field is the primary key. Due to this EJB represents a user I want to give \
primary-keys as Integer values (not timestamps or other generatet stuff). I created a \
column in the db which is of type integer and set to autoincrement (this works fine).

I createt the following jbosscmp-jdbc.xml:

  | <jbosscmp-jdbc>
  |    <defaults>
  |      <datasource>java:ForumDS</datasource>
  |      <datasource-mapping>mySQL</datasource-mapping>
  |      <entity-command name="mysql-get-generated-keys" />
  |    </defaults>
  | 
  |    <enterprise-beans>
  | 
  |         <entity>
  |          <ejb-name>User</ejb-name>
  |          <create-table>no</create-table>
  |          <remove-table>no</remove-table>
  |       
  |          <table-name>forum_user</table-name>
  | 
  |          <cmp-field>
  |             <field-name>userId</field-name>
  |             <column-name>user_id</column-name>
  |             <jdbc-type>INTEGER</jdbc-type>
  |             <sql-type>INTEGER</sql-type>
  |         </cmp-field>
  |          <cmp-field>
  |             <field-name>nickName</field-name>
  |             <column-name>nick_name</column-name>
  |             <jdbc-type>VARCHAR</jdbc-type>
  |             <sql-type>VARCHAR</sql-type>
  |         </cmp-field>
  |          <cmp-field>
  |             <field-name>EMail</field-name>
  |             <column-name>e_mail</column-name>
  |             <jdbc-type>VARCHAR</jdbc-type>
  |             <sql-type>VARCHAR</sql-type>
  |         </cmp-field>
  | 
  |       <unknown-pk>
  |             <unknown-pk-class>java.lang.Object</unknown-pk-class>
  |             <field-name>userId</field-name>
  |             <column-name>user_id</column-name>
  |             <jdbc-type>INTEGER</jdbc-type>
  |             <sql-type>INTEGER</sql-type>
  |             <auto-increment />
  |       </unknown-pk>
  |       </entity>
  |    </enterprise-beans>
  | </jbosscmp-jdbc>
  | 
  | 

and the ejb-jar.xml looks like:


  | 
  | <ejb-jar >
  | 
  |    <description>[CDATA[No Description.]]</description>
  |    <display-name>Generated by XDoclet</display-name>
  | 
  |    <enterprise-beans>
  | 
  |      <entity >
  |          <description>Forum User</description>
  | 
  |          <ejb-name>User</ejb-name>
  | 
  |          <home>user.UserHome</home>
  |          <remote>user.User</remote>
  |          <local-home>user.UserLocalHome</local-home>
  |          <local>user.UserLocal</local>
  | 
  |          <ejb-class>user.UserCMP</ejb-class>
  |          <persistence-type>Container</persistence-type>
  |          <prim-key-class>java.lang.Object</prim-key-class>
  |          <reentrant>False</reentrant>
  |          <cmp-version>2.x</cmp-version>
  |          <abstract-schema-name>forumUser</abstract-schema-name>
  |          <cmp-field >
  |             <description>User Id</description>
  |             <field-name>userId</field-name>
  |          </cmp-field>
  |          <cmp-field >
  |             <description>Nick Name</description>
  |             <field-name>nickName</field-name>
  |          </cmp-field>
  |          <cmp-field >
  |             <description>E-Mail Adress</description>
  |             <field-name>EMail</field-name>
  |          </cmp-field>
  |         
  |          <query>
  |             <query-method>
  |                <method-name>findAll</method-name>
  |                <method-params>
  |                </method-params>
  |             </query-method>
  |             <ejb-ql>[CDATA[SELECT OBJECT(a) FROM forum as a]]</ejb-ql>
  |          </query>
  |       </entity>
  | 
  |    </enterprise-beans>
  |    <assembly-descriptor >
  |    </assembly-descriptor>
  | 
  | </ejb-jar>
  | 
  | 

When I try to create the instance of the EJB an Exception is thrown which says:


  | StandardWrapperValve[CreateUser]: Servlet.service() for servlet CreateUser threw \
exception  | javax.servlet.ServletException: Could not create User! Primary key for \
created instance is null.   | 

Althoug the row in the db is created.

can anyone explain why it doesn't work? And why it is unable to bring the data from \
the db to the Primary key field?

Thanks
Oskar



View the original post : \
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3856953#3856953

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3856953



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic