-
1. Re: Unknown primary key class
mdrob Nov 22, 2002 11:01 AM (in response to timhoverd)Try the latest JBoss 3.2 beta2 - it seems to support Unknown primary key class
-
2. Re: Unknown primary key class
hvenstrom Nov 24, 2002 7:09 PM (in response to timhoverd)I am working on the same problem and I have found two intresting posts regarding this, here is the short
version. Good luck with the configuration.
/Harald
And yes of course you need the JBoss 3.2 beta2 to get it to work
----------------------------------------------------------
JBossCMP becomes cooler. Now it supports Unknown primary keys (Refer to EJB2.0 spec 10.8.3 for details).
To make use of this feature, entity beans must have prim-key-class declared as java.lang.Object and no primkey-field in ejb-jar.xml.
To set up unknown primary key, the new optional unknown-pk element is used in jbosscmp-jdbc.xml. (See jbosscmp-jdbc_3_0.dtd for details).
If unknown-pk element is omitted in jbosscmp-jdbc.xml, the default one from standardjbosscmp-jdbc.xml will be used.
The default (and the only for now) key generator factory is UUIDKeyGeneratorFactory. It's deployed as a service and bound to the global JNDI context.
Other key generator factory implementations are welcome!
The feature is available in CVS HEAD version.
--
Alex Loubyansky
JBossCMP now provides some new ways to setup and create entity beans.
It is based on so called entity commands.
First some working examples (snippet from jbosscmp-jdbc.xml):
<ejb-name>MyCMPBean</ejb-name>
<table-name>mycmp_table</table-name>
<!-- auto-incremented primary key (jdk1.3/1.4) for now supported only for MySQL. -->
<cmp-field>
<field-name>id</field-name>
<column-name>knownid</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER(11)</sql-type>
<auto-increment/>
</cmp-field>
<!-- entity command to create the entity -->
<entity-command name="mysql-get-generated-keys"/>
<!-- unknown primary key generated with SQL statement -->
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<column-name>genid</column-name>
<jdbc-type>TIMESTAMP</jdbc-type>
<sql-type>DATETIME</sql-type>
</unknown-pk>
<entity-command name="pk-sql"/>
-->
<!-- pk-sql generated unknown-pk; overriding default sql
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<column-name>genid</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
</unknown-pk>
<entity-command name="pk-sql">
SELECT SEQ_2279_1.nextval FROM DUAL
</entity-command>
-->
<!-- mysql generated unknown-pk
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<column-name>genid</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER(11)</sql-type>
<auto-increment/>
</unknown-pk>
<entity-command name="mysql-get-generated-keys"
class="org.jboss.ejb.plugins.cmp.jdbc.mysql.MySQLCreateEntityCommand"/>
-->
<!-- the use of key generator for unknown-pk
<unknown-pk>
<unknown-pk-class>java.lang.String</unknown-pk-class>
<column-name>genid</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(32)</sql-type>
</unknown-pk>
<entity-command name="key-generator"
class="org.jboss.ejb.plugins.cmp.jdbc.JDBCKeyGeneratorCreateCommand">
UUIDKeyGeneratorFactory
</entity-command>
-->
The general syntax of entity-command is:
<entity-command name="CommandName"
class="ComandClass">
value1
value2
</entity-command>
Only the 'name' is required.
You can check the list of available commands in
standardjbosscmp-jdbc.xml in entity-commands element.
The default entity command is specified in 'defaults' element and can
be overriden in each entity element as above.
If entity-command in the entity provides 'class' or 'attribute' it
overrides the corresponding element of in the known command.
For now the feature is available in HEAD version.
PS: templates for non-MySQL auto-increment SQL statements are welcome!!!
alex -
3. Re: Unknown primary key class
ehenne Dec 4, 2002 3:48 PM (in response to timhoverd)I have Petstore 1.3.1 now running on JBoss 3.0.2, but to do so I had to define explicit primary keys for those tables. I have started a new topic where I am presenting my experiences:
"Running PetStore 1.3 on JBoss 3.0" (http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ -
4. Re: Unknown primary key class
auswalk Dec 4, 2002 7:10 PM (in response to timhoverd)I could not find the code for the 'mysql-get-generated-keys' entity command. Is this provided in jboss3.2.0-beta2?
thanks -
5. Re: Unknown primary key class
auswalk Dec 4, 2002 7:13 PM (in response to timhoverd)Disregard, I found it.
-
6. Re: Unknown primary key class
auswalk Dec 5, 2002 12:01 PM (in response to timhoverd)I have a problem. I am using MSSQLServerv7 identity columns for my PK. However I found a class:
org.jboss.ejb.plugins.cmp.jdbc.jdbc3.JDBCGetGeneratedKeysCreateCommand
So as long as my driver is jdbcv3 compliant, this should work yes? (I am in the process of acquiring a jdbcv3 driver).