views:

173

answers:

1

I'm using PS to store data in my app. I think I have a misunderstanding of how PS works. If anyone could tell me how to make it so that the bill I retrieve from PS is unencrypted as opposed to the encrypted bill I end up with? Note: I originally store and unencrypted bill!

From what I can tell, it considers both bills, and both PO objects to be the same objects! When I look at their memory locations in Eclispe, both bill and both PO objects have identical memory locations! What am I missing?

Thanks!

    //create an unencrypted bill
    BillDAO testBill = new BillDAO();

    //store it in PS
    PersistentObject po = PersistentStore.getPersistentObject(4);
    po.setContents(testBill);
    po.forceCommit();

    //encrypt the bill
    testBill.encrypt();

    //retrieve it from PS using a different PO
    PersistentObject po2 = PersistentStore.getPersistentObject(4);
    BillDAO retrievedBill = (BillDAO) po2.getContents();

    //and now for some reason my retrieved bill is encrypted!
    //it should be unencrypted
+3  A: 

The two objects (in PS and in RAM) are linked, therefore changes to one reflect on the other. See Mike Kirkup response to this thread on the BB forum and in specific:

You should only ever call setContents() once. This would occur on the very first time that you are adding data. For each subsequent call you should be calling getContents() and then modifying that object directly. By modifying the object directly, you would then call commit at the end of your work where the system would properly commit your changes...

Also, you might wanna checkout his recommendations for key generation :)

Hope this helps!

Tamar
Could you provide a code example of how to change my code?
DanG
Well, if you want a persisted not encrypted object and a RAM encrypted object, I think you'll need to clone the object (or to create two objects). I don't know what you're trying to do so it's hard for me to give a sample...
Tamar
Understood. Thanks.
DanG
You're welcome :)
Tamar