2

I am using Datanucleus as the JPA engine to perform CRUD on an entity in Force.com DB. Insert and Select are working fine, but while updating a new row is getting created and delete does not remove the record at all. I am using following for transaction enforcement

Is there kind of an issue with the proxy object to actual object synchronization after the object has been fetched, modified and then subject to updating.

It seems that as the ORM layer (datanucleus+force sdk) is unable to match between the altered object and the original one, it is landing up creating new row.

Any help is highly appreciated.

Thanks

Soumyak
  • 31
  • 5
  • 1
    Well you're using Salesforce.com's own DataNucleus plugin for their datastore. It is not open source AFAIK and you'd be best asking them. The log for any DataNucleus usage tells you a lot, so perhaps look at it ;-) – DataNucleus May 10 '11 at 15:39
  • I have the same problem even if I am not using Force.com – Vitaly Olegovitch Nov 02 '12 at 14:04

1 Answers1

0

It would help if you can post your code. But I am guessing you might be hitting a known difference in behavior between DataNucleus and other ORMs like Hibernate.

Are you doing something like this?

MyEntity ent = new MyEntity();
ent.setId(idFromWebRequest);
ent.setXXX(valueFromWebRequest);
ent = entityManager.merge(ent);

(where the instantiation and setters might be carried out by a data binding mechanism such as Spring MVC). If you do it like this, it will not work with DataNucleus but it will work with Hibernate. For DataNucleus you must instead do:

MyEntity ent = entityManager.find(MyEntity.class, idFromWebRequest);
ent.setXXX(valueFromWebRequest);
ent = entityManager.merge(ent);

I would prefer it worked like Hibernate, but the DataNucleus team believes this is the correct behavior. Maybe they can chime in. I believe it's a matter of when you consider an entity a new entity vs. a detached entity. If your entity instance is detached, then calling merge on it should reattach it and your database row will be updated at transaction commit / flush. If it's a new instance, then the entity manager will always create a new record.

As for your delete issue, I don't know what it could be. Perhaps you can post a code sample? You can find a complete CRUD sample app using the JPA provider here:

https://github.com/forcedotcom/javasample-musiclib

Jesper J.
  • 993
  • 8
  • 17
  • Obviously DataNucleus follows the JPA spec (and passes it). If an object passed in to "merge" is "transient" (i.e not persistent, nor detached) then it is persisted (as new). You can only get "detached" by calling detach() or closing an EntityManager. If anyone wanted to contribute their time to implement http://datanucleus.org/servlet/jira/browse/NUCCORE-595 then they could have the option of this other behaviour. Since VMForce is effectively commercial, benefitting from DataNucleus yet not contributing so far to it, then its their choice if they want that functionality, aka open source. – DataNucleus May 24 '11 at 12:59
  • Database.com SDK is open source: http://github.com/forcedotcom/java-sdk. I am pretty sure Fiaz Hossain has contributed patches back to DataNucleus. – Jesper J. Jul 22 '11 at 00:16
  • Jesper, thanks for the link now that you've made it open source; hope it goes well. I'll update the DN docs to link to it. Fiaz has raised 3 issues in DN JIRA, and the only thing i received from him was an unverified proposal for one of the issues, and I have received no patches from anyone else that I know to be affiliated with Salesforce. Thanks for your interest – DataNucleus Jul 22 '11 at 11:17