openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: Bug? DataCache after update contains only the updated information from a Collection
Date Thu, 07 Jun 2012 18:47:40 GMT
Hi John,
Good background information.  Thanks for the detail.  Unfortunately,
nothing is jumping out at me as an "easy fix".  I do have a couple of
observations and/or questions...

o  Why is the @InverseLogical annotation required?  It would seem that you
have already defined the bidirectional relationship via the mappedBy
attribute on the @OneToMany.  Is there something else you were trying to
model by using the @InverseLogical?  And, does the removal of that
annotation change the processing in any way?

o  Can you explain the use of the update() method?  Are the entities being
passed into this method detached from a persistence context?  That's where
the merge() method comes into play -- merging detached entities into a
persistence context.  The merge() method is not used just because there are
updates to an Entity.

o  Your code example doesn't show the actual interaction with the EM.  How
is the lifecycle of the EM being managed, and is the same EM being used for
all of the interactions with transactions, persisting, merging, etc?

o  Can you post your whole persistence.xml?  For example, you didn't
mention the use of the QueryCache property, but it looks like this is
enabled via the dump of the properties.  The QueryCache is no longer
automatically enabled when the DataCache is enabled, so it must be
explicitly enabled.  Not that it should affect this particular scenario,
but I'm just curious if there are other property "mismatches" that I didn't
catch.

o  If none of these questions provide any fruit, then you might have found
a bug and a JIRA will be required.  But, let's do a bit more Q&A first...

Thanks,
Kevin

On Thu, Jun 7, 2012 at 2:05 AM, Boblitz John <John.Boblitz@bertschi.com>wrote:

> Hello,
>
> I'm running openJpa 2.2.0 and have a problem with the DataCache function.
> I spent the better part of two days localizing the problem and looking for
> solutions, but alas ...
>
> So, hoping some guru out there can spot my error, here the details:
>
> Environment JavaSE
>
> Persistence XML:
> <property name="openjpa.DataCache" value="true(CacheSize=5000,
> EnableStatistics=true)" />
> <property name="openjpa.RemoteCommitProvider" value="sjvm" />
> <property name="openjpa.DetachState"
> value="fetch-groups(DetachedStateField=true)" />
>
> Entities:
>
> @MappedSuperclass
> @EntityListeners({ EntityManipulationLogger.class, EntityLogger.class })
> public abstract class BaseEntity {
> @Version
> @Column(columnDefinition = "int8")
> private long versionId;
>
> @Id
> @GeneratedValue(strategy = GenerationType.SEQUENCE)
> @Column(name = "uniqueid", columnDefinition = "int8")
> protected long uniqueId;
>
> ...
>
> @Entity
> @Table(name = "Equipment")
> public class Equipment extends BaseEntity {
>
> @JsonManagedReference
> @OneToMany(cascade = CascadeType.ALL, mappedBy = "equipmentId")
> @InverseLogical("equipmentId")
> private Set<Axle> axles = new HashSet<Axle>();
>
> ...
>
> @Entity
> @Table(name = "Axle")
> public class Axle extends BaseEntity {
>
> @JsonBackReference
> @ManyToOne(fetch = FetchType.EAGER)
> @JoinColumn(name = "equipmentId", columnDefinition = "int8", nullable =
> false)
> private Equipment equipmentId;
>
>
> Code used to Update the DataBase:
>
> @Override
> public <T extends BaseEntity> T update(T pEntity) {
>    this.lock.lock();
>   T object = null;
>    try {
>         try {
>                getTransaction().begin();
>                object = merge(pEntity);
>        } catch (Exception e) {
>                mTrc.error("Error in update(): ", e);
>                getTransaction().setRollbackOnly();
>                handleException(e);
>        } finally {
>                if (getTransaction().isActive()) {
>                    if (getTransaction().getRollbackOnly()) {
>                    getTransaction().rollback();
>                } else {
>                    getTransaction().commit();
>                }
>            }
>        }
>    } catch (Exception e) {
>        mTrc.error("Error in update(): ", e);
>        handleException(e);
>    } finally {
>        this.lock.unlock();
>    }
>    return object;
> }
>
> Symptom:
> When updating the Equipment entity, if an additional Axle is added to the
> Set and the other Axles remain unchanged:
> 1.  Upon entry into update(), pEntity contains all the Axels (new & old)
> including UID & Version.
> 2.  object = merge(pEntity) - performs as expected, object contains all
> the Axels and the new Axel has been assigned a UID
> 3.  After commit(), the new Axle is added to the Database (good)
> 4.  The entity is updated in the DataCache (I would assume this is good as
> well)
> 5.  "object" however now only contains one element in the Set<Axle> - the
> one we added, the others are no longer there.
> 6.  A subsequent refresh of the returns the same results as in #5! It hits
> in the DataCache, so I assume that the Update of the Cache
> contains only the "new" data from object.
>
> Turning off the DataCache (or excluding the Equipment Entity) solves the
> problem.
>
> Here the complete config:
>
> openjpa.AutoClear: 0
> openjpa.AutoDetach: [Ljava.lang.String;@60cf710e
> openjpa.BrokerFactory: jdbc
> openjpa.BrokerImpl: default
> openjpa.CacheDistributionPolicy: default
> openjpa.Callbacks: default
> openjpa.ClassResolver: default
> openjpa.Compatibility: default
> openjpa.ConnectionDriverName: org.postgresql.Driver
> openjpa.ConnectionFactoryMode: false
> openjpa.ConnectionFactoryProperties: QueryTimeOut=5000, PrettyPrint=true,
> PrettyPrintLineLength=80, PrintParameters=true
> openjpa.ConnectionPassword: ******
> openjpa.ConnectionProperties: MaxActive=100, MaxIdle=5, MinIdle=2,
> MaxWait=60000
> openjpa.ConnectionRetainMode: 0
> openjpa.ConnectionURL: ******
> openjpa.ConnectionUserName: *****
> openjpa.DataCache: true(CacheSize=5000, EnableStatistics=true)
> openjpa.DataCacheManager: default
> openjpa.DataCacheTimeout: -1
> openjpa.DetachState: fgs(DetachedStateField=true)
> openjpa.DynamicDataStructs: false
> openjpa.DynamicEnhancementAgent: true
> openjpa.EntityManagerFactory: default
> openjpa.FetchBatchSize: -1
> openjpa.FetchGroups: [Ljava.lang.String;@53077fc9
> openjpa.FlushBeforeQueries: 0
> openjpa.Id: g11.persistence
> openjpa.IgnoreChanges: false
> openjpa.InitializeEagerly: false
> openjpa.InstrumentationManager: default
> openjpa.InverseManager: true
> openjpa.LifecycleEventManager: validating
> openjpa.LockManager: mixed
> openjpa.Log: log4j
> openjpa.ManagedRuntime: auto
> openjpa.MaxFetchDepth: -1
> openjpa.MetaDataFactory: *** truncated!!
> openjpa.MetaDataRepository: default
> openjpa.Multithreaded: false
> openjpa.NontransactionalRead: true
> openjpa.NontransactionalWrite: true
> openjpa.Optimistic: true
> openjpa.OrphanedKeyAction: log
> openjpa.ProxyManager: default
> openjpa.QueryCache: true(CacheSize=1000, SoftReferenceSize=100,
> EvictPolicy='timestamp')
> openjpa.QueryCompilationCache: all
> openjpa.ReadLockLevel: 10
> openjpa.RefreshFromDataCache: false
> openjpa.RemoteCommitProvider: sjvm
> openjpa.RestoreState: 1
> openjpa.RetainState: true
> openjpa.RetryClassRegistration: false
> openjpa.RuntimeUnenhancedClasses: 1
> openjpa.SavepointManager: in-mem
> openjpa.Sequence: table
> openjpa.TransactionMode: false
> openjpa.WriteLockLevel: 20
> openjpa.jdbc.DBDictionary:
> postgres(supportsNullTableForGetImportedKeys=false)
> openjpa.jdbc.DriverDataSource: auto
> openjpa.jdbc.EagerFetchMode: 2
> openjpa.jdbc.FetchDirection: 1000
> openjpa.jdbc.FinderCache: true
> openjpa.jdbc.IdentifierUtil: default
> openjpa.jdbc.LRSSize: 2
> openjpa.jdbc.MappingDefaults: jpa
> openjpa.jdbc.QuerySQLCache: true(EnableStatistics=true)
> openjpa.jdbc.ResultSetType: 1003
> openjpa.jdbc.SQLFactory: default
> openjpa.jdbc.SchemaFactory: native(ForeignKeys=true)
> openjpa.jdbc.Schemas: [Ljava.lang.String;@60cf710e
> openjpa.jdbc.SubclassFetchMode: 1
> openjpa.jdbc.SynchronizeMappings: null
> openjpa.jdbc.TransactionIsolation: -1
> openjpa.jdbc.UpdateManager: default
>
>
>
>
>
> 
>
> John
>
> ----
>
> Who is General Failure, and why is he reading my hard disk?
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message