Victor Batista wrote: > > Hi! > Thanks for your reply! > > > > Is there any way to have incremental primary keys without the > > > explicit usage of sequences? If yes, how? > > > > What do you mean by implicit use of sequences? > Is it possible to have an incremental primary key without the usage of > sequences? > > Which is the better way to have a incremental primary key? > > 1) > * @jboss.entity-command > * name="pk-sql" > * @jboss.entity-command-attribute > * name="pk-sql" > * value="SELECT nextval('TEST_SEQ')" > > 2) Which I can't get working.. > * @jboss:entity-command > * name="postgresql-fetch-seq" > * > class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand" > * @jboss:entity-command-attribute > * name="sequence" > * value="TEST_SEQ" > > 3) Any other......
Below is what I'm using with Postgresql: /** * @ejb.bean * name="MyBean" * type="CMP" * cmp-version="2.x" * schema="MyBean" * view-type="both" * reentrant="false" * jndi-name="/MyBeanHome" * local-jndi-name="/MyBeanLocalHome" * primkey-field="id" * * @ejb.transaction * type="Required" * * @ejb.persistence * table-name="t_mybean" * * @ejb.pk * generate="false" * * @jboss.entity-command * name="postgresql-fetch-seq" */ public abstract class MyBean implements EntityBean { /** * @ejb.interface-method * * @ejb.persistence * sql-type="SERIAL" * jdbc-type="INTEGER" * * @jboss.persistence * auto-increment="true" * sql-type="SERIAL" * jdbc-type="INTEGER" * * @ejb.value-object * match="Movie" */ public abstract Integer getId(); public abstract void setId(Integer id); } What can be causing the error is that your primary key is an auto-increment, SERIAL, and you are using it as a foreign key in another bean (the type SERIAL in Postgresql has attribute "not null"). In this case you must specify in jbosscmp-jdbc.xml that the fk must have type INTEGER, if you don't do this jboss will create the fk with type SERIAL an you will get a lot of errors (this error happens with postgresql, I don't know about other databases) To avoid this problem I modified the xdoclet template to support the tags jdbc-type and sql-type in jboss.relation. I sent the patch to the xdoclet project, but it is not included in the most recent distribution yet. If this is your problem tell me and I'll send you my modified xdoclet template for jbosscmp-jdbc.xml. > > > > What can I win with a unknown-pk declaration? > > There is a paragraph in the spec about it called Special case Unknown > > primary keys. > I have seen the spec, and for now I don't need the unknown-pk :-) > > > > Is there any way to automatically create the sequences if > > > they don't still exist (something like: @jboss:create-table > > > create="true")? > > > > At the moment, JBoss does not create sequences even if it is setup to > > create tables. As a workaround, I think, you could use something like > > @jboss.persistence post-table-create="CREATE SEQUENCE %%t_seq START WITH > > 1 INCREMENT BY 1" > Unfortunately the jboss.persistence tag doesn't seems to be working.... > > Regards and thanks, > Victor Batista > > ------------------------------------------------------- > The SF.Net email is sponsored by EclipseCon 2004 > Premiere Conference on Open Tools Development and Integration > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. > http://www.eclipsecon.org/osdn > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user -- Ivens Porto OSE - Open Systems Engineering http://www.ose.com.br Phone: (55) 34 - 3214-5995 Fax: (55) 34 - 3214-5994 Cel: (55) 34 - 8816-9942 ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user