I am sorry if this is in the wrong place but I couldn't work out how to add the 
information to the Wiki. 

To do AutoIncrement Primary Keys in MySQL in JBoss CMP is easy and you dont need to 
use Unknown -pk either 

How we did it.....

First you define your ejb-jar Bean entry


  | <entity>
  | <ejb-name>UserBean</ejb-name>
  | <home>UserHome</home>
  | <remote>User</remote>
  | <local-home>UserLocalHome</local-home>
  | <local>UserLocal</local>
  | <ejb-class>UserBean</ejb-class>
  | <persistence-type>Container</persistence-type>
  | <prim-key-class>java.lang.Long</prim-key-class>
  | <primkey-field>id</primkey-field>
  | <reentrant>False</reentrant>
  | <cmp-field><field-name>id</field-name></cmp-field>
  | <cmp-field><field-name>name</field-name></cmp-field>
  | <cmp-field><field-name>password</field-name></cmp-field>
  | <cmp-version>2.x</cmp-version> 
  | <abstract-schema-name>UserBeanAPS</abstract-schema-name>
  | <resource-ref>
  | <res-ref-name>jdbc/mysql</res-ref-name>
  | <res-type>javax.sql.DataSource</res-type>
  | <res-auth>Container</res-auth>
  | </resource-ref>
  | </entity>
  | 

Then you have to create the jbosscmp-jdbc.xml entry


  | <entity>
  | <ejb-name>UserBean</ejb-name>
  | <table-name>user</table-name>
  | <cmp-field>
  |   <field-name>id</field-name>
  |   <column-name>user_id</column-name>
  |   <auto-increment/>
  |   <not-null/>
  | </cmp-field>
  | <cmp-field>
  |   <field-name>name</field-name>
  |   <column-name>user_name</column-name>
  | </cmp-field>
  | <cmp-field>
  |   <field-name>password</field-name>
  |   <column-name>user_password</column-name>
  | </cmp-field>
  | <entity-command name="mysql-get-generated-keys"
  |  class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand"/>
  | </entity>
  | 

The last entry in the entity declaration above is the magic command, 

and not an Unknown Primary Key in sight....

I hope this information helps...

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

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


-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to