-
1. Re: Problem : CMR field cannot be null
ibruell Feb 11, 2004 3:35 AM (in response to sesques)In the containerConfiguration is a flag called <sync-on-commit-only> set this to true and synchronisation will happen after or at commit time.
-
2. Re: Problem : CMR field cannot be null
juha Feb 11, 2004 3:35 AM (in response to sesques)insert-after-ejb-post-create in jboss.xml
-
3. Re: Problem : CMR field cannot be null
ibruell Feb 11, 2004 3:45 AM (in response to sesques)Ooops, i was wrong ...
-
4. Re: Problem : CMR field cannot be null
sesques Feb 12, 2004 5:39 PM (in response to sesques)Hi,
Thanks for response but cannot work:
I insert :
<container-configurations>
<container-configuration extends="Standard CMP 2.x EntityBean">
<container-name>foobar</container-name>
<insert-after-ejb-post-create>true</insert-after-ejb-post-create>
</container-configuration>
</container-configurations>
in my jboss.xml and I threw the exception:
"Primary key for created instance is null" when I returned from ejbCreate. It's because JBOSS wants to gets the primary key just after the ejbCreate method.
Another problem is that I dont know how to generate the container configuration with XDoclet. So I have to patch the file jboss.xml each time the file is regenerated.
In fact, I saw one solution on other forums: I create CMP fields for foreign keys and I initialize them in ejbCreate, then I initialize CMR fields in ejbPostCreate. This solution work, even if it is not in the state of the art. -
5. Re: Problem : CMR field cannot be null
sesques Feb 12, 2004 5:50 PM (in response to sesques)Of course, to understand all the problem, I forgot to mention that I use database autogenerated keys, thats why jboss threw an error. I think that if not the case, It's works fine with the insert-after-ejb-post-create tag.
-
6. Re: Problem : CMR field cannot be null
belakdar Feb 18, 2004 5:06 PM (in response to sesques)Could you please post an example of what could be a solution when using auto-increment keys and CMR fieds through foreign keys. I'm having a same problem even by using the <insert-after-ejb-post-create> and setting CMR field at ejbPostCreate method.
What is wrong here ?
Any idea ?
Thanks
belakdar. -
7. Re: Problem : CMR field cannot be null
sesques Mar 1, 2004 9:36 AM (in response to sesques)Hi,
Here is the example :
public java.lang.Object ejbCreate( Customer Client,
Date OrderDate,
String OrderReference)
throws CreateException
{
try {
setOrderDate (OrderDate); // Simple CMP field
setOrderReference (OrderReference); // Simple CMP field
setCustomerId (Client.getId()); // CMP field for foreign key
} catch(Exception e) {
...
}
return null;
}
public java.lang.Object ejbPostCreate( Customer Client,
Date OrderDate,
String OrderReference)
throws CreateException
{
try {
setCustomer(Client); // Sets the CMR field
} catch(Exception e) {
....
}
}
Here is the CMP field for the foreign key
/**
* @ejb.persistence column-name = "CUSTOMER_ID"
* @ejb.interface-method
*/
public abstract Long getCustomerId();
/**
* @ejb.interface-method
*/
public abstract void setCustomerId(Long val);
And the corresponding CMR field
/**
* @ejb.interface-method
* @ejb:transaction type="Required"
* @ejb:relation
* name="Order-Customer"
* role-name="Order-have-Customer"
* target-ejb="PhML_Customer"
* @jboss:relation
* fk-column = "CUSTOMER_ID"
* related-pk-field = "customerId"
*/
public abstract PharmaML_EJB.interfaces.Customer getCustomer();
/**
* @ejb.interface-method
*/
public abstract void setCustomer(PharmaML_EJB.interfaces.Customer arg);