I'm working on a web based application, and I have a question regarding how I can use the persistence features of castor.

To explain...

The user logs on onto the application and their details are loaded from the database and stored in their session. (NB: The User class implements Timestampable). See code listing 1.

At some point the user decides to write a note on a specific client. The note is attached to the client and also includes details about the current user that submitted the note. See code listing 2. NB: A client can have a collection of notes each which refer to the particular user that created them.

My problem is that when this code is commited, a new note is created for the client and it also creates a new copy of the User. This is not the desired behaviour that I'm after. I want it to use the users information and make an association between the two. Not create another copy of it.

-> What should I do to solve this elegantly?

I've tried initially loading the user using Database.Exclusive. i.e.

user = db.load(User.class, new Integer(1), Database.Exclusive);

But that doesn't seem to work.

If in the second code listing,

I perform a db.update(user) on the user before retrieving the client's details it works but it doesn't seem very elegant/correct to do this.

Any help would be very appreciated.

Thanks in advance,
qwam.

--------------- code listing 1.

User user = null;

db.begin();

user = db.load(User.class, new Integer(1));

db.commit();

--------------- code listing 2.

db.setAutoStore(true);
db.begin();

Client client = db.load(Client.class, new Integer(1));

Note note = new Note();
note.setText("This is a new note.");
note.setUser(user);
client.addNote(user);

db.commit();


_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail

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

Reply via email to