Hello,

I have an object model that is demonstrated by the following code snippet:

        // Create a paper
        Paper   p = new Paper();
        p.setTitle("The title of the paper");

        // Add keywords
        p.addKeyword("keyword1");
        p.addKeyword("keyword2");
        p.addKeyword("keyword3");

        // Create an initial version of the paper
        Version v = new Version();
        v.setLabel("INITIAL");
        v.setAcceptType(ACCEPT_UPLOAD_BY_AUTHOR);

        // Create a file
        File    f = new File();
        f.setFileName("paper.tex");
        f.setMediaType("text/plain");
        f.setData(new java.io.FileInputStream("paper.tex"));

        // Attach the file to the version
        v.setFile(f);

        // Add the version to the paper
        p.addVersion(v);

Each Version object depends on a Paper object. File objects are not
dependent, they are related objects and their persistence is managed
by the instances of the Version class that implements the Persistent
interface.

The Paper object above can be serialized into the database in a
standalone application with

        Database        db;
        db.setAutoStore(true);
        db.begin();
                db.create(p);
        db.commit();

But if I cut and paste this code fragment to a JSP bean its execution
fails.

The Castor logs generated by the application:

[castor] Castor: Creating hu.jfce.tmcs.db.Paper (null)
[castor] Castor: Creating hu.jfce.tmcs.db.File (null)   // <== File object is created 
here
[castor] Castor: Creating hu.jfce.tmcs.db.Keyword (null)
[castor] Castor: Creating hu.jfce.tmcs.db.Keyword (null)
[castor] Castor: Creating hu.jfce.tmcs.db.Keyword (null)
[castor] Castor: Creating hu.jfce.tmcs.db.Version (null)

The Castor logs generated by the servlet:

[castor] Castor: Creating hu.jfce.tmcs.db.Paper (null)  // <== File object is not 
created
[castor] Castor: Creating hu.jfce.tmcs.db.Keyword (null)
[castor] Castor: Creating hu.jfce.tmcs.db.Keyword (null)
[castor] Castor: Creating hu.jfce.tmcs.db.Keyword (null)
[castor] Castor: Creating hu.jfce.tmcs.db.Version (null)
java.sql.SQLException: ERROR:  <unnamed> referential integrity violation - key 
referenced
from versions not found in files

The application and the servlet use exactly the same configuration
(the same mapping, autostore is enabled).

It seems to me that the object trees are traversed differently in the
application and in the servlet. The File object must be serialized
before the Version but according to the logs that does not happen
in the second case.

Any idea how to fix the problem?

Thanks in advance,

Peter

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to