

So, let's open the pom.xml from yesterdays project and introduce the new plugin:ĭone. I tried the static weaving plugin done by Craig Day.

Mainly because it introduces a massive complexity to the build and having seen far too many projects without the right skills for managing even normal maven projects, this simply isn't a solution for me. Thanks Laird for the pointers! Don't get me wrong: This is a valid approach, but I simply don't like it. A detailed explanation about what is happening can be found on his blog. Laird Nelson did a great job to archetype-ize an example configuration for all 3 big JPA providers (EclipseLink, OpenJPA, Hibernate) and your could give this a try.

Copy classes from left to right and do an amazing lot of wrangling to get your classpath rigth. You would have to use maven-antrunner-plugin to get this introduced. The second thing may be Craig's eclipselink-staticweave-maven-plugin. The first thing you probably find is the StaticWeaveAntTask. Having the maven project at hand, this sounds like a fairly easy job. Static means: post processing the entities during the build. If dynamic waving doesn't work, we have to use the fallback called static weaving. Compare this nice discussion for a more detailed explanation. The combination of embedded GlassFish, Arquillian and the maven sure-fire-plugin mix this up a bit and the end of the story is, that exactly none of your entities are enhanced at all. It only works when the entity classes to be weaved do exist only in the application classloader. Obviously the default dynamic weaving doesn't work with the described setup. If(person1 != _persistence_person_vh.getValue()) Person person1 = _persistence_get_person() If(_persistence_person_vh.isCoordinatedWithProperty() || _persistence_person_vh.isNewlyWeavedValueHolder()) Public WeavedAttributeValueHolderInterface _persistence_get_person_vh() And this is only one of the enhanced methods a weaving process is introducing into your code. This is how your enhanced entity class should look like. If you decompile a weaved entity you can see what the JPA provider is complaining about. And that missing method is introduced by the weaving process. Mapping: .ManyToOneMappingĭescriptor: RelationalDescriptor(.AuditLog -> )Īt .DescriptorException.noSuchMethodWhileInitializingAttributesInMethodAccessor(DescriptorException.java:1170)Īt .(MethodAttributeAccessor.java:200) Internal Exception: : .AuditLog._persistence_get_person_vh() The class was not weaved properly - for EE deployments, check the module order in the application.xml deployment descriptor and verify that the module containing the persistence unit is ahead of any other module that uses it. Without modifying the project it would lead to some very nasty exceptions:Įxception Description: A NullPointerException would have occurred accessing a non-existent weaved _vh_ method. That's exactly one of the mentioned cases where your JPA provider would need to do some enhancements to your class files before executing. Imagine you take the example from yesterday's blog post and change the simple String account property to something like = CascadeType.PERSIST, fetch = FetchType.LAZY) The problem with Arquillian and Embedded GlassFish End weaver class transformer processing class. Weaved fetch groups (FetchGroupTracker). Begin weaver class transformer processing class.

You may have seen some finer log output from EclipseLink like the following: Dynamic weaving is mostly recommended as it is easy to configure and does not require any changes to a project's build process. Weaving can be performed either dynamically at runtime, when Entities are loaded, or statically at compile time by post-processing the Entity. The EclipseLink JPA persistence provider uses weaving to enhance JPA entities for the mentioned things and to do internal optimizations. Weaving is a technique of manipulating the byte-code of compiled Java classes. JPA providers like to call this "enhancing" and it is most often referred to as "weaving". To name but a few: lazy loading, change tracking, fetch groups and so on. Everything works fine up to the point when you start introducing enhanced features to your entities. Even if it was intended to be a more complex demo it turns out, that I missed a big issue with the setup. This is a followup post to the one I did yesterday.
