Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Static Weaving and Lifecycle Methods(Problems with Lifecycle methods using static weaving)
Static Weaving and Lifecycle Methods [message #1827306] Tue, 12 May 2020 17:47 Go to next message
Roland Welker is currently offline Roland WelkerFriend
Messages: 13
Registered: October 2013
Junior Member
Hi Everybody,

I am using eclipselink (2.7.5) in a aws lambda project with a java 8 runtime. I have a utility class holding 2 life cycle methods (PrePersit and PreUpdate, annotated approprietly) which are than assigned via the entity listener annotation to a mapped superclass, updating create/modify dates and a soft delete flag.

This works all fine.

To improve performance I started using static weaving build with maven (de.empulse.eclipselink), Lazy Loading and Jackson JSON field filter to avoid a full entity tree being fetched and sent.

Once the static weaved lambda has been deployed, the EntityListener is still being invoked and sets the field values (I can see it in the objects after the persist/commit, however the values are not persisted to the database.

For testing purposed I have taken the weaving task back out and the values are showing up correctly in the db.

I have found a few related posts and one Eclipselink bug report going back to 1.x version, but no actual solution. I have also tried:

<property name="eclipselink.weaving.changetracking" value="false"/>

To see if this would make a difference without effect.

All entities, mapped super classes and Entity Listener are explicitly listed in the persistence.xml file.

Has anyone any solutions to use static weaving and Entity Listener successfully?

Thank you very much,
Roland
Re: Static Weaving and Lifecycle Methods [message #1827494 is a reply to message #1827306] Fri, 15 May 2020 18:25 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1388
Registered: July 2009
Senior Member
Can you provide more detail on what you are doing and when? Changing an entity within an entity listener event entirely depends on what you are doing and the event to determine how/when and even if it gets picked up in the current transactional context. Not all events were intended to allow you to change values, and it would be expensive to recalculate changes after every event type that could be fired.

Chances are good though that if it is working with weaving turned off, you are accessing the property directly instead of through its accessor methods. Change tracking injects code to watch for changes that you might be bypassing.

[Updated on: Fri, 15 May 2020 18:28]

Report message to a moderator

Re: Static Weaving and Lifecycle Methods [message #1827495 is a reply to message #1827494] Fri, 15 May 2020 18:36 Go to previous messageGo to next message
Roland Welker is currently offline Roland WelkerFriend
Messages: 13
Registered: October 2013
Junior Member
Hi Chris,

It is fairly simple crud persist routine running a user transaction either doing an Entity Manger persist or merge (depending if the it is already in the db or not).

The Listener sets 2 (or one in case of the merge) Calendar fields and in case of the pre-persist also sets a soft delete boolean flag ... roughly like this:

em.ut.begin();

if (dto.id != null)
  entity = fetch(dto.id)
else
  entity new EntityType()

entity.deepclone(dto) // use reflection to copy content from dto into entity

if (dto.id == null)
  em.persit(entity)
else
  em.merge(entity)

// em.flush() ... tried this also
em.ut.commit()


Obviously not real code, but this represents exactly the flow.

The listener methods are implemented in a separate class and than assigned via @EntityListener on a Managed Superclass that all entities are derived from and which in turn holds those 3 fields that get updated.

In either case, weaving being enabled or not the Listener does get invoked, but with weaving enabled the change is not detected.



Re: Static Weaving and Lifecycle Methods [message #1827677 is a reply to message #1827495] Wed, 20 May 2020 14:32 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1388
Registered: July 2009
Senior Member
The changes not detected - do you mean the listener is not invoked, changes made by the listener are not detected, or changes to mapped superclass properties are not detected and updated in the database at all? This is only showing a custom merge method signature that hints at reflection being used, something I mentioned you might be doing in your listener and would certainly cause issues to any woven methods if you are bypassing the public accessors. JPA requires you use method access when using any sort of lazy fetching, and all EclipseLink weaving is built of that premise.

You might want to create a simple test case, as we know (it is in EclipseLink build tests) that weaving a mapped superclass hierarchy 'works'. We need to see the differences from the standard use cases and what you are doing to figure out what might be going wrong.
Previous Topic:MappedSuperClass with EclipseLink
Next Topic:JPA 2.1 AttributeConverter autoApply option not working if converter class extends base class
Goto Forum:
  


Current Time: Sun Jun 13 21:56:09 GMT 2021

Powered by FUDForum. Page generated in 0.01738 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top