I think when storing an empty strings, oracle atomatically sets it to null. This causes that the string property in cache is still an empty string but the database column holds null which causes an ObjectModifiedException when you update the value for the next time.

I had similar problems at my application and resolved that by replacing an empty string with null in the setters of my data objects like:

public void setValue(final String value) {
   if ("".equals(value)) {
       _value = null;
   } else {
       _value = value;
   }
}

Having said that similar problems my happen with double values if you use e.g. column type NUMBER(15,5) as oracle only stores 5 decimal digits and throws away the rest.

Hope that helps
Ralf


Shiva P. Kodityala schrieb:

<mapping>
 <class name="com.mystruts.dto.Table2DTO" identity="a">
   <description>Table2</description>
   <map-to table="Table2"/>
   <field name="a" type="string">
     <sql name="A" type="varchar"/>
   </field>
   <field name="c" type="string">
     <sql name="C" type="varchar"/>
   </field>
<field name="b" type="string"> <sql name="B" type="varchar"/> </field> </class>
</mapping>

Methods to insert and modify:

        public static void editRow(String s1, String s2, JDOManager jdoManager) 
{

                OQLQuery oql1;
                QueryResults results1;
                Database db;
                try {
                        db = jdoManager.getDatabase();
                        db.begin();
                        oql1 =
                                db.getOQLQuery(
                                        "SELECT p FROM com.mystruts.dto.Table2DTO p 
where a = $1");
                        oql1.bind(s1);
                        results1 = oql1.execute();
                        //ArrayList table81List = new ArrayList();
                        while (results1.hasMore()) {
                                //System.out.println(results.next());
                                Table2DTO table21 = (Table2DTO) results1.next();
                                table21.setC(s2);
                                break;
                        }
                        results1.close();
                        db.commit();
                        db.close();
                } catch (Exception e) {
                        e.printStackTrace();
                }

                results1 = null;
                db = null;

        }
        public static void createRow(Table2DTO table2DTO, JDOManager 
jdoManager) {

                try {

                        // Obtain a new database
                        Database db = jdoManager.getDatabase();

                        // Begin a transaction
                        db.begin();
                        // Do something
                        db.create(table2DTO);
                        // Commit the transaction and close the database
                        db.commit();
                        db.close();

                        if (true)
                                return;

                        if (true)
                                return;

                } catch (Exception persisException) {
                        persisException.printStackTrace();
                }

        }

-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 01, 2005 2:36 PM
To: [email protected]
Subject: Re: [castor-user] ObjectModifiedException


I assume you are using the type String for the three properties in your
Java code, right ? What does the exact mapping look like ?

Werner

Shiva P. Kodityala wrote:
Oracle and all are varchar2.

SQL> desc table2;
Name                            Null?    Type
------------------------------- -------- ----
A                                        VARCHAR2(10)
B                                        VARCHAR2(10)
C                                        VARCHAR2(10)


-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 01, 2005 2:26 PM
To: [email protected]
Subject: Re: [castor-user] ObjectModifiedException


Shiva,

what database are you using ? And what column types to the three columns
a,b and c have ?

Werner

Shiva P. Kodityala wrote:

Ralf

I created a sample web application with different classes and a table. I could 
reproduce this behaviour again. This time, I have observed a pattern.

Table Name: Table2 has three fields:a, b, c
I have a class mapping to table: Table2DTO.java: having corresponding fields: 
a, b, c

I am getting ObjectModifiedException when some of the columns have "" value

For example:
I insert a row into Table2 with b and c value blanks. Printed the values of b 
and c of Table2DTO object - shows empty strings

Next time, when I try to modify the column which is blank, I am getting 
ObjectModifiedException. Further modifications of this blank columns are 
successful.

I insert a row
a1 (b and c are blanks)

modify b where a = a1 -------->ObjectModifiedException
modify b where a = a1 ---------> success
modify b where a = a1 ---------> success


How do I avoid it? By inserting some default value if nothing is supplied?


Thanks
Shiva.






-----Original Message-----
From: Shiva P. Kodityala [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 01, 2005 1:23 PM
To: [email protected]
Subject: RE: [castor-user] ObjectModifiedException


Ralf, Thanks for your suggestions.

Do you configure time-period somewhere to make an object available for certain 
time?

"According to my experience I expect the problem happend at the last write operation before the failing one."

I too feel the same.. I am doing commit and close resultset and database 
objects after insert; :(

Thanks
Shiva.

-----Original Message-----
From: Ralf Joachim [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 01, 2005 12:11 PM
To: [email protected]
Subject: Re: [castor-user] ObjectModifiedException


Hi Shiva


I'm really sorry but according to the stacktrace it is not possible to find out what caused the exception. According to my experience I expect the problem happend at the last write operation before the failing one. In most cases it is quite difficult to track this as you may have recognized yourself. I suggest you to prepare a test case that allows me to reproduce the problem. At least with the information I have at the moment I am not able to help you.

There is one other thing that came to my mind being the reason for the problem. If the object you want to change has been expired from cache you may also get this ObjectModifiedException.

Regards
Ralf


Shiva P. Kodityala schrieb:



Ralf,

I am still not able to figure out what is happening...

Could you help me figuring out what is the problem by looking at the exception? 
Is it because of nulls?

exception was logged org.exolab.castor.jdo.ObjectModifiedException: Transaction 
aborted: Object of type test.tables.User with identity hk has been modified by 
a concurrent transaction (cache entry is different from database row). The 
following fields have been changed [actual/expected value]: 
(test.tables.User).address1: [/null](test.tables.User).address2: 
[/null](test.tables.User).address3: [null/null](test.tables.User).city: 
[null/null](test.tables.User).state: [/null]

Thanks


-----Original Message-----
From: Ralf Joachim [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 29, 2005 11:31 PM
To: [email protected]
Subject: Re: [castor-user] ObjectModifiedException


Hi Shiva,

a ObjectModifiedException is thrown by Castor if the object in cache differs from the objects representation in the database. There is a various number of reasons that can cause that:

- another application changes the values in the database
- you have mapped the same table with 2 mappings and change the values through both of them - your database does change values when storing (e.g. convert null to empty String, clip String to column length)

Castor is only able to recognize that changes when you try to modify the object the next time after one of the above situation happend.

Regards
Ralf


Shiva P. Kodityala schrieb:





I am trying to modify one of the columns of an obtained row.
Problem seems to be something to do with nulls.

Here is the code:

for(int i=0; i<numberOfSelectedUsers;i++)

{

database = connectionPool.getJDOConnection();

database.begin();

String oqlString = "select p from test.tables.User p where userid=$1";

oql = database.getOQLQuery(oqlString);

oql.bind( selectedUserIds[i]);

results = oql.execute();

User user = null;

while (results.hasMore()) {

user = (User) results.next();

}

user.setActivationstatus(toStatus);

database.commit();

database.close();

database = null;

}

Here is error. It is not  happening always.. I don't know why.

following fields have been changed [actual/expected value]: 
(test.tables.User).address1: [/null](test.tables.User).address2: 
[/null](test.tables.User).address3: [null/null](test.tables.User).city: 
[null/null](test.tables.User).state: [/null](test.tables.User).country: 
[null/null](test.tables.User).ZIP: [/null]
[11/29/05 22:25:06:609 PST] 7e116486 DatabaseImpl  E 
org.exolab.castor.jdo.engine.DatabaseImpl  TRAS0014I: The following exception 
was logged org.exolab.castor.jdo.ObjectModifiedException: Transaction aborted: 
Object of type test.tables.User with identity hk has been modified by a 
concurrent transaction (cache entry is different from database row). The 
following fields have been changed [actual/expected value]: 
(test.tables.User).address1: [/null](test.tables.User).address2: 
[/null](test.tables.User).address3: [null/null](test.tables.User).city: 
[null/null](test.tables.User).state: [/null](test.tables.User).country: 
[null/null](test.tables.User).ZIP: [/null]
at org.exolab.castor.jdo.engine.SQLEngine.store(SQLEngine.java:1013)
at org.exolab.castor.persist.ClassMolder.store(ClassMolder.java:834)
at org.exolab.castor.persist.LockEngine.store(LockEngine.java:779)
at 
org.castor.persist.TransactionContext.prepareForCreate(TransactionContext..java:1654)
at org.castor.persist.TransactionContext.prepare(TransactionContext.java:1618)
at org.exolab.castor.jdo.engine.DatabaseImpl.commit(DatabaseImpl.java:521)
at test.actions.ChangeStatusAction.changeStatus(ChangeStatusAction.java:226)
at test.actions.ChangeStatusAction.active(ChangeStatusAction.java:120)
at test.actions.ChangeStatusAction.execute(ChangeStatusAction.java:47)
at 
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at 
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at 
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at 
com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at 
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at 
com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at 
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at 
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at 
com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at 
com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at 
com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at 
com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at 
com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
..
                            org.exolab.castor.jdo.ObjectModifiedException: 
Transaction aborted: Object of type test.tables.User with identity hk has been 
modified by a concurrent transaction (cache entry is different from database 
row). The following fields have been changed [actual/expected value]: 
(test.tables.User).address1: [/null](test.tables.User).address2: 
[/null](test.tables.User).address3: [null/null](test.tables.User).city: 
[null/null](test.tables.User).state: [/null](test.tables.User).country: 
[null/null](test.tables.User).ZIP: [/null]
at org.exolab.castor.jdo.engine.SQLEngine.store(SQLEngine.java:1013)
at org.exolab.castor.persist.ClassMolder.store(ClassMolder.java:834)
at org.exolab.castor.persist.LockEngine.store(LockEngine.java:779)
at 
org.castor.persist.TransactionContext.prepareForCreate(TransactionContext..java:1654)
at org.castor.persist.TransactionContext.prepare(TransactionContext.java:1618)
at org.exolab.castor.jdo.engine.DatabaseImpl.commit(DatabaseImpl.java:521)
at test.actions.ChangeStatusAction.changeStatus(ChangeStatusAction.java:226)
at test.actions.ChangeStatusAction.active(ChangeStatusAction.java:120)
at test.actions.ChangeStatusAction.execute(ChangeStatusAction.java:47)
at 
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at 
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at 
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at 
com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at 
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at 
com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at 
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at 
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at 
com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at 
com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at 
com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at 
com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at 
com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)

[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R 
org.exolab.castor.jdo.ObjectModifiedException: Transaction aborted: Object of 
type test.tables.User with identity hk has been modified by a concurrent 
transaction (cache entry is different from database row). The following fields 
have been changed [actual/expected value]: (test.tables.User).address1: 
[/null](test.tables.User).address2: [/null](test.tables.User).address3: 
[null/null](test.tables.User).city: [null/null](test.tables.User).state: 
[/null](test.tables.User).country: [null/null](test.tables.User).ZIP: [/null]
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.exolab.castor.jdo.engine.SQLEngine.store(SQLEngine.java:1013)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.exolab.castor.persist.ClassMolder.store(ClassMolder.java:834)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.exolab.castor.persist.LockEngine.store(LockEngine.java:779)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.castor.persist.TransactionContext.prepareForCreate(TransactionContext..java:1654)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.castor.persist.TransactionContext.prepare(TransactionContext.java:1618)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.exolab.castor.jdo.engine.DatabaseImpl.commit(DatabaseImpl.java:521)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
test.actions.ChangeStatusAction.changeStatus(ChangeStatusAction.java:226)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
test.actions.ChangeStatusAction.active(ChangeStatusAction.java:120)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
test.actions.ChangeStatusAction.execute(ChangeStatusAction.java:47)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[11/29/05 22:25:06:656 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
[11/29/05 22:25:06:672 PST] 7e116486 SystemErr     R  at 
com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)










------------------------------------------------------------------------

-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to