1 Reply Latest reply: Mar 6, 2006 4:16 AM by eric es RSS

Can't get working CMP on JBoss 4.0.2 and PostgreSQL 7.3.4 (a

Krzysztof Hycnar Newbie

Hello All,

I've been trying to deploy a simple CMP using JBoss 4.0.2 and PostgreSQL 7.3.4-RH db engine but it fails to work when I try to configure JBoss to use a postgres sequence to fetch primary key values.

The database is available for the sever, it creates the table while deployent without any problems (I had to create the sequence manually).

I know that it is pretty common, I explored number of examples on the web addressing that problem, but the advices didn't work for me, so this group is my last resort.

The details of my app are as follows:

exception stack trace


Exception in thread "main" javax.ejb.CreateException: Could not create entity:java.sql.SQLException: ERROR: ExecInsert: Fail to add null value in not null attribute id

at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:327)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:138)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:572)
at .....



the jbosscmp-jdbc.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">

<jbosscmp-jdbc>
 <defaults>
 </defaults>

 <enterprise-beans>

 <!--
 To add beans that you have deployment descriptor info for, add
 a file to your XDoclet merge directory called jbosscmp-jdbc-beans.xml
 that contains the <entity></entity> markup for those beans.
 -->

 <entity>
 <ejb-name>AuthorEntity</ejb-name>
 <datasource>java:jdbc/libraryDS</datasource>
 <datasource-mapping>PostgreSQL</datasource-mapping>
 <create-table>true</create-table>

 <read-only>false</read-only>
 <pk-constraint>false</pk-constraint>
 <table-name>AUTHORS</table-name>

 <cmp-field>
 <field-name>firstName</field-name>
 <column-name>FIRST_NAME</column-name>

 </cmp-field>
 <cmp-field>
 <field-name>id</field-name>
 <column-name>id</column-name>

 <auto-increment/>
 </cmp-field>
 <cmp-field>
 <field-name>lastName</field-name>
 <column-name>LAST_NAME</column-name>

 </cmp-field>

 <unknown-pk>
 <unknown-pk-class>java.lang.Long</unknown-pk-class>
 <column-name>id</column-name>
 <jdbc-type>BIGINT</jdbc-type>
 <sql-type>SERIAL</sql-type>
 <auto-increment/>
 </unknown-pk>
 <entity-command name="postgresql-fetch-seq" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand">
 <attribute name="sequence">authors_id_seq</attribute>
 </entity-command>
<!-- jboss 3.2 features -->
<!-- optimistic locking does not express the exclusions needed -->
 </entity>

 </enterprise-beans>

</jbosscmp-jdbc>


additianal info from the org.jboss.ejb.plugins.cmp package (as verbose as possible)


2006-02-28 00:26:19,440 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.AuthorEntity] Loading standardjbosscmp-jdbc.xml : file:/usr/local/jboss-4.0.2/server/default/conf/standardjbosscmp-jdbc.xml
2006-02-28 00:26:19,615 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.AuthorEntity] file:/usr/local/jboss-4.0.2/server/default/deploy/Library.ear/LibraryEJB.jar/META-INF/jbosscmp-jdbc.xml found. Overriding defaults
2006-02-28 00:26:19,947 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand.AuthorEntity] SEQUENCE SQL is :SELECT currval('authors_id_seq')
2006-02-28 00:26:19,947 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand.AuthorEntity] Insert Entity SQL: INSERT INTO authors (FIRST_NAME, LAST_NAME) VALUES (?, ?)
2006-02-28 00:26:19,947 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.AuthorEntity] entity-command: [commandName=postgresql-fetch-seq,commandClass=class org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand,attributes={sequence=authors_id_seq}]
2006-02-28 00:26:19,947 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.AuthorEntity] Remove SQL: DELETE FROM authors WHERE id=?
2006-02-28 00:26:19,994 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStartCommand.AuthorEntity] Executing SQL: CREATE TABLE authors (id INT8 NOT NULL, FIRST_NAME TEXT, LAST_NAME TEXT)
2006-02-28 00:26:20,108 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCStartCommand.AuthorEntity] issuePostCreateSQL: sql is null
2006-02-28 00:26:20,109 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.AuthorEntity#findByPrimaryKey] SQL: SELECT t0_AuthorEntity.id FROM authors t0_AuthorEntity WHERE t0_AuthorEntity.id=?
2006-02-28 00:26:20,110 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.AuthorEntity] Added findByPrimaryKey query command for home interface
2006-02-28 00:26:20,110 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.AuthorEntity#findByPrimaryKey] SQL: SELECT t0_AuthorEntity.id FROM authors t0_AuthorEntity WHERE t0_AuthorEntity.id=?
2006-02-28 00:26:20,110 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.AuthorEntity] Added findByPrimaryKey query command for local home interface
2006-02-28 00:26:23,187 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand.AuthorEntity] Executing SQL: INSERT INTO authors (FIRST_NAME, LAST_NAME) VALUES (?, ?)
2006-02-28 00:26:23,191 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.AuthorEntity#firstName] param: i=1, type=VARCHAR, value=Waldemar
2006-02-28 00:26:23,191 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.AuthorEntity#lastName] param: i=2, type=VARCHAR, value=Lysiak
2006-02-28 00:26:23,192 ERROR [org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand.AuthorEntity] Could not create entity
java.sql.SQLException: ERROR: ExecInsert: Fail to add null value in not null attribute id

at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)...



Thanx in advance
Krzysiek