Hi there,
this is pretty urgent and I'm stuck. I'm using Jboss 4.0 DR4.
I set up two tables named Contract and Type. The Contract table has a reference to the Type table (foreign key relationship). I set up a CMR relationship that works fine, except when I try to insert a new Contract into the database.
The Errormessage reads:
17:05:56,736 ERROR [Contract] Could not create entity
java.sql.SQLException: Try to insert null into a non-nullable column in statement [INSERT INTO CONTRACT (ID, NAME, TYPE, CLIENT, STATUS, type) VALUES (10, NULL, 0, 0, 0, NULL)]
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.jdbcResultSet.<init>(Unknown Source)
at org.hsqldb.jdbcConnection.executeStandalone(Unknown Source)
at org.hsqldb.jdbcConnection.execute(Unknown Source)
at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
I initialize the primary key field in the ejbCreate method and the relationship in the ejbPostCreate method, but that method apparently never gets called, because the ejbCreate method is executed first and then Jboss generates the above error message.
The create methods look like this:
/**
* @return
* @throws CreateException
*
* @ejb.create-method
*/
public Integer ejbCreateContract(Integer id, ContractTypeLocal ctl) throws CreateException{
setId(id);
return null;
}
public void ejbPostCreateContract(Integer id, ContractTypeLocal ctl){
setContractTypeCMR(ctl);
}
I'm pretty stuck and don't really know what to do.
thanks
matt
-
ejbPostCreate in JBoss :: NEED HELP (3 messages)
- Posted by: Matthias Zint
- Posted on: July 01 2004 11:28 EDT
Threaded Messages (3)
- found the Solution by Matthias Zint on July 01 2004 15:53 EDT
- found the Solution by Martin Straus on July 05 2004 00:15 EDT
- CMR fields by Matthias Zint on July 08 2004 06:19 EDT
- found the Solution by Martin Straus on July 05 2004 00:15 EDT
-
found the Solution[ Go to top ]
- Posted by: Matthias Zint
- Posted on: July 01 2004 15:53 EDT
- in response to Matthias Zint
The bean creation process has to be delayed. I read that in earlier posts (about weblogic), but didn't know if that was possible in jboss as well.
I found the solution in the following post:
http://www.jboss.org/index.html?module=bb&op=viewtopic&t=43591
I added the following code to the standardjboss.xml configuration-file
<container-configuration extends="Standard CMP 2.x EntityBean">
<container-name>INSERT after ejbPostCreate Container</container-name>
<insert-after-ejb-post-create>true</insert-after-ejb-post-create>
</container-configuration>
and used the XDoclet tag
@jboss.container-configuration name="INSERT after ejbPostCreate Container"
in the contract bean.
For now :) everything works fine
cheers
matt
btw - this works with simple and compound primary keys, where part of the key is a foreign key to another table -
found the Solution[ Go to top ]
- Posted by: Martin Straus
- Posted on: July 05 2004 00:15 EDT
- in response to Matthias Zint
I guess you are using CMP... The error is perfectly reasonable, in my opinion, if your fk field in contract table is not nullable... which should make you wonder about your design. Can a contrant have no type? If so, the fk field should be nullable, and the insert must work with a null Type in ejbCreate.
Regards -
CMR fields[ Go to top ]
- Posted by: Matthias Zint
- Posted on: July 08 2004 06:19 EDT
- in response to Martin Straus
Hi Martin,
the contract type field is nullable (CMP). The reason this has to be done is that I'm using CMR (Container Managed Relationship) and that field has to be set when I create a new Contract, otherwise I would get an error.
The relationsship is one-to-many (type - contract). The dependent side of the relationship has to be set I suppose.
cheers
matt