We do have a requirements that says if any of the CMP EJB fields are modified then we need to set modified_by and modified_date fields also ( note: each CMP EJB has modified_by and modified_date CMP fields ). I know that just before the end of a transaction container calls the ejbStore() method of the CMP bean. But its funny here, no matter what happened to the CMP fields i.e wheatear they are modified or not the container (9iAS OC4J )is going to call the ejbStore() and then it decides to write to DB or not ( i.e. after it calls the ejbStore it checks for the cmp fields internal dirty flags ). I thought I will set the CMP fields updated_by and updated_date in the ejbStore method, but the problem is a call to ejbStore does not necessarily mean there were changes in the CMP fields, in that case if I set the updated_by, updated_date in the ejbStore its just these fields that are changed and cmp is going to write these two fields to DB with out any other fields being changed!!! Does any one have any idea how to know from with in the CMP EJB if any one of the current CMP EJBs fields has changed their values? Thank you --Mallik
I suppose the trigger does not work because it does not know modified_by. IMO, you dirty flag has to be a persisted field too, ejb_store must clear it. Because, you don't contol ejb_load either. Hopefully this will force the container to clear your flag.
posted 16 years ago
Stepping back from the problem, it appears your design is using an entity bean when it only needs read-only access. This is an EJB anti-pattern. BTW, are Value Objects and Transfer Objects two names for the same concept or was Value Object closed to modification? [ September 14, 2003: Message edited by: Rufus BugleWeed ]
posted 16 years ago
BTW, are Value Objects and Transfer Objects two names for the same concept or was Value Object closed to modification?
You might want to have a look at this earlier thread.
Thank you all of you, But I wonder I did not get any clear answer for my question, I hope so many people would have faced the same problem and might have some soulution. Let me explain my requirement here once again, Before container writes the CMP EJB to DB I have to set up the UPDATED_BY ( = the current user's loginID ) and UPDATED_DATE (= the current system date) for that particular record. If CMP is not going to write that particular row to the DB I don't want to set these two fields. To my strange!!! the container calls the ejbStore() method and does not let me know if its going to write to DB for sure. I am only interested in knowing if the CMP is going to write to DB for sure, I don't know how to get this information!!! if some one knows please let me know. I know one method of implementing this, but I feel its too lengthy not consistant with the J2EE api's, this is done as follows 1. declare a CMP EJB instance variable boolean flag and name it as isModified or some thing and set it to flase at the end of ejb post create method and in the ejbLoad() method and also at the end of ejbStore() method. 2. Write a wrapper methods for each of the setField methods such as updateField() and with in this wrapper method set isModified to true and then call the corresponding setField() method. 3. Any EJB clients that wants to set some new value to a field that client has to use the updateField() method instead of setField() method oooooooooooooooops so much of work!!! Now querying the isModified field of the CMP would let me know if its going to write to DB for sure. I can check for this status in the ejbStore() method and then decied to set the other two field values i.e UPDATED_BY and UPDATED_DATE values of the CMP EJB Fields. Thank you Mallik