db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

JSP and Servlets : objects stored, but null values persisted

Last post 11-15-2007, 06:01 PM by chaicijun@gmail.com. 2 replies.
Sort Posts: Previous Next
  •  11-15-2007, 12:29 PM 43609

    JSP and Servlets : objects stored, but null values persisted

    has anyone come across a problem whereby when null values are persisted instead of the real values, in JSP and servlets?

    example :

    //java

    public class MyData {

    private String s;

    public MyData(String s) { setS(s); }

    public void setS(String s) { this.s = s; }

    public String getS() { return this.s; }

    }

    in the servlet :

    server = openServer() method is called in a context listener set up in Tomcat 6. db4o 6.1 is used. The server is running in embedded server mode.

    ObjectContainer db = server.openClient();

    db.set(new MyData("test data"));

    db.commit();

    ...

    the above are the statements that were run.

    for the first time the database is created, the data is persisted correctly. However, subsequent executions of the same function result in MyData object being saved in the database but the field 's' is null.

    does anyone have any ideas?

     

  •  11-15-2007, 01:11 PM 43610 in reply to 43609

    Re: JSP and Servlets : objects stored, but null values persisted

    Probably AccessibleObject#setAccessible() is not allowed
    in your servlet environment.

    You may have to grant reflectpermission on the machine.

    Google for:
    reflectpermission grant

    You will find this one for example, and it tells you
    what you will have to add to your server.policy file
    under (11.):

    http://blogs.sun.com/vkraemer/category/Java
  •  11-15-2007, 06:01 PM 43617 in reply to 43610

    Re: JSP and Servlets : objects stored, but null values persisted

     thank you carl; your advice helped.

     the problem does not occur anymore after i added the following line in catalina.policy file.

    grant codeBase "file:${catalina.home}/webapps/webappname/WEB-INF/lib/db4o-6.1-java5.jar" {
     permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
    }

    note : i also realised that the db4o- jar file cannot be put under the tomcat common lib directory, because for doing so the problem is not solved. I suppose then for each web application to be deployed, the db4o- jar file must be individually deployed also, and the grant statement for that web application added in the policy file also. Wouldn't that be the case?

     

View as RSS news feed in XML