• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Container trying to save CMR field

 
Naveen Sampra
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me out with this problem.

I am using CMP EJB2.0 with CMR.

When trying to save a child entity(which is part of a CMR relationship), should the container call the setParent(parentEntity) method also.

I get a database error which says, "trying to set a null value to a not null column".

How do I solve this problem. The setParentId() method is setting the correct parent Id. I don't want container to call the abstract setParent() method.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naveen Sampra:
Can someone help me out with this problem.

I am using CMP EJB2.0 with CMR.

When trying to save a child entity(which is part of a CMR relationship), should the container call the setParent(parentEntity) method also.

I get a database error which says, "trying to set a null value to a not null column".

How do I solve this problem. The setParentId() method is setting the correct parent Id. I don't want container to call the abstract setParent() method.


When creating the child record , are you setting the parent as well in ejbPostCreate of the child entity?.
I guess you have to since parent id is a non nullable parent key on child entity. Make sure that the parent entity that you are setting is a valid reference.
IMHO i find it surprising that the container allows you to do setParentId() instead of setParent(parentEntity) when you have a cmr between child and parent on that column (parentId). The container is expected to take care of that part (setting parent id ) implicitly
 
Naveen Sampra
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am not doing anything in ejbPostCreate() of the child entity. It's just an empty method. I don't have any post processing to do.

All my set logic is in the ejbCreate() method. I am setting a correct value in setParentId().

When I remove the setParent() method, generated ejb code sets null to that field. When I add setParent() and set it with a valid reference to parent, I get IllegalStateException thrown.

Any ideas as to how to handle CMR field in ejbCreate() ?
[ April 27, 2005: Message edited by: Naveen Sampra ]
 
Naveen Sampra
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should the set operation of CMR field be called in ejbCreate() ?
 
Karthik Guru
Ranch Hand
Posts: 1209
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setting the parent entity reference (ie do a setParent) in ejbPostCreate and not ejbCreate. The ejbPostCreate signature is exactly same as the ejbCreate except that you set the CMRs in this method call.
 
Naveen Sampra
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Your solution is correct.

I found the solution yesterday and was about to post the finding today, when I saw your post.

Actually, the problem is application server specific. I am using WAS 5.1 currently and remember I did not run into this problem while using JBOSS.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naveen Sampra:
Actually, the problem is application server specific.


It is always advisable to set CMRs in ejbPostCreate irrespective of the app server you are using. Atleast the bean is portable that way.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic