cristof commented on code in PR #144:
URL: https://github.com/apache/openjpa/pull/144#discussion_r3771749945
##########
openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java:
##########
@@ -477,7 +823,160 @@ public boolean isLoaded(Object entity, String attribute) {
return (OpenJPAPersistenceUtil.isManagedBy(this, entity) &&
(OpenJPAPersistenceUtil.isLoaded(entity, attribute) ==
LoadState.LOADED));
}
-
+
+ @Override
+ public <E> boolean isLoaded(E entity, Attribute<? super E, ?> attribute) {
+ return isLoaded(entity, attribute.getName());
+ }
+
+ @Override
+ public SchemaManager getSchemaManager() {
+ if (!this.isOpen()) {
+ throw new IllegalStateException("EntityManagerFactory is
closed.");
+ }
+ return new SchemaManagerImpl(_factory);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <R> R callInTransaction(Function<EntityManager, R> work) {
+ EntityManager em = createEntityManager();
+ boolean startedTransaction = false;
+ boolean jtaTransaction = getTransactionType() ==
PersistenceUnitTransactionType.JTA;
+ Broker broker = em.unwrap(Broker.class);
+ try {
+ if (jtaTransaction) {
+ if (!broker.syncWithManagedTransaction()) {
+ broker.begin();
+ startedTransaction = true;
+ }
+ } else {
+ em.getTransaction().begin();
+ startedTransaction = true;
+ }
+ R result = work.apply(em);
+ if (startedTransaction) {
+ if (jtaTransaction) {
+ broker.commit();
+ } else {
+ em.getTransaction().commit();
+ }
+ }
+ // For unenhanced (runtime-subclassed) entities, the user's
function
+ // may return an original POJO that was passed to persist().
+ // Entities loaded via find() on other EMs are subclass
instances,
+ // causing getClass() mismatches in equals(). To ensure
consistent
+ // class identity, re-find managed entities from the database
so that
+ // the returned instance is a subclass (matching what find()
returns).
+ if (result != null && em.contains(result)) {
Review Comment:
Gated the re-find block only for results that are not enhanced classes as
defined by OpenJPAPersistenceUtil#toPC
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]