You have several choices with JBoss-3.2 and upper.

To set it up you need to declare prim-key-class as java.lang.Object
and no primkey-field. Also, ejbCreate method should return Object and
findByPrimaryKey should return Object.

Then in jbosscmp-jdbc.xml you need to configure unknown-pk and
entity-command elements.
You have several choices:
<!-- use of UUID key generator for unknown-pk -->
         <unknown-pk>
            <unknown-pk-class>java.lang.String</unknown-pk-class>
            <field-name>genfield</field-name>
            <column-name>genid</column-name>
            <jdbc-type>VARCHAR</jdbc-type>
            <sql-type>VARCHAR(32)</sql-type>
         </unknown-pk>
         <entity-command name="key-generator"/>

<!-- database generated keys -->
         <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">
            <!-- this sql is dummy, some sequence tables should used here -->
            <attribute name="pk-sql">SELECT MAX(genid)+1 FROM myjdbc_table</attribute>
         </entity-command>

<!-- JDBC3.0 getGeneratedKeys -->
         <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>
         </unknown-pk>
         <entity-command name="get-generated-keys"/>

<!-- this is mysql specific way under jdk1.3 -->
         <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"/>

Hope this helps.

alex

Monday, November 18, 2002, 5:01:52 PM, you wrote:

TGR> Hi,
 
TGR> I wanna create beans but I my primary keys are sequences in the database.
TGR> How can I create a bean without having
TGR> to determine this key value??? Is there any way to ask the container to
TGR> create this sequence???
 
TGR> Thanks,
 
 
 
TGR> Tânia Ramos
TGR> Analista de Sistemas - NDS
TGR> *  <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
TGR> Fóton® Informática e Serviços
TGR> * Fone: (61) 3031 5087
 



-- 
Best regards,
 Alex Loubyansky




-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing 
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to