سؤال

I have a Java + GAE + JPA project and I want introduce Objectify framework to as well as I have JPA, so my question: is it possible to combine JPA (EntityManager, JPQL etc...) with Objectify in cases where I need it? Have anybody such experience?

I mean I want to have a DAO which manipulates with EntityManager and ObjectifyService as well

هل كانت مفيدة؟

المحلول

The simple answer is yes, you can have both at the same time. The mapping of JPA entities to Objectify entities is "as you would expect" - fields have the same names, etc.

It gets a little more complicated if you use advanced Objectify features like embedded classes and polymorphism - but even these can be mapped in JPA. The Objectify documentation describes the native storage format for these features.

Be careful about doing this, however. Objectify is very forgiving of incoherent data - a convenient feature when making schema changes. But if you, for example, forget to add a field to your Objectify entity and then use Objectify to load/save the entity, you will effectively "strip off" the forgotten field. Parallel entity classes must be maintained carefully.

نصائح أخرى

Yes you can, but why? In the case of transition from JPA to Objectify it is reasonable but I wouldn't suggest anything outside that scope.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top