Ebean enhancement ignores a model

457 views
Skip to first unread message

Christien Lomax

unread,
Apr 22, 2015, 5:18:30 PM4/22/15
to eb...@googlegroups.com

We are using the avaje-agentloader to enhance our ebeans. All the ebeans are in the same package. We are including the loader, the agent & the base ebean library in our project (via sbt):

"org.avaje" % "avaje-agentloader" % "1.1.2",
"org.avaje.ebeanorm" % "avaje-ebeanorm" % "4.5.5",
"org.avaje.ebeanorm" % "avaje-ebeanorm-agent" % "4.5.2",

However, when the loader runs the enhancement, it skips ONE ebean.

Each ebean is annotated with @Entity and extends com.avaje.ebean.Model. There seem to be no differences between the ones that get enhanced and the one that does not. There are no extra includes, or extends, etc.

Basically, I'm wondering if anyone has run across this issue in the past, or has any insights.

Things we've tried:

  • specifying actual classes to be enhanced via serverConfig.setClasses(...)
  • specifying pakages to analyse/enhance via serverConfig.addPackage(...) or setPackages(...)
  • not specifying at all and having the loader analyse all.
  • we've set a break-point at Transformer.transform and the bean in question is never actually hit.

Note: if we use the ebean agent via an agent loader on the command line, or via a maven plugin, or sbt, it works.


Originally posted to StackOverflow.

Rob Bygrave

unread,
Apr 22, 2015, 5:46:49 PM4/22/15
to ebean@googlegroups
Firstly to clarify a few things about ServerConfig - serverConfig.setClasses() and serverConfig.addPackage() have nothing to do with enhancement.  What these values do is specify the classes (entity beans, listeners, types etc) that an EbeanServer must know about or the packages/jars to scan to find classes that EbeanServer must know about. That is, the enhancement is independent of these values and the enhancement should have already occurred at this point.

The enhancement agent has it's own parameter for specifying the packages to scan for enhancement (and does not use ServerConfig).

What the agent-loader does is to register the javaagent to the all ready running JVM. Classes loaded after that point should be enhanced if necessary ... classes loaded before that point will not be enhanced/transformed.

That is, I strongly suspect that the class for the one entity bean in question was for some reason class loaded prior to the agent registering ... and hence you didn't see it at the breakpoint in Transformer.transform.  Now assuming this is the case what can we do about it?

1) A tough one but have a look at the code and imports and see if you can change it so that the agent is registered with the JVM before it class loads the entity class in question.  Not as easy as is sounds.

2) Change the Ebean agent to also support 'class redefinition' which means that if/when this is detected use the agent to redefine an already loaded class.  I have not tried to make this change and see if it works yet.  There are limitations to what changes you are allowed to make when redefining a class so using this approach so it might not work.


Hope that helps a little.

Cheers, Rob. 



--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christien Lomax

unread,
Apr 23, 2015, 12:34:36 PM4/23/15
to eb...@googlegroups.com
Hi Rob,

Thanks so much!

The bean does seem to be loaded before the agent gets loaded.  I looked into the class loader and its being loaded well before the agent.  We are looking into why, but as of yet have not figured it out.  Right now we've switched to loading the agent manually via -javaagent:...  

Do you know of any (working) examples of loading the agent via SBT?  The issue is that we have to run both SBT (for intellij debugging, play plugin, etc) and Maven (for our company standards, build server, etc).  So Maven has the lovely ebean enhancement plugin, but SBT does not?  We are using the newer eBeans (4.x) so we cannot use the playEbean stuff.

Personally, I'd rather use the AgentLoader, as it mean that the agent is loaded (in hopefully) one place in the code, regardless of if we are running maven, SBT, eclipse or IntelliJ (or command line!) with no separate configurations.  I'll continue to try and track down why the bean is loading early.  The app is a play app and we use Guice, so we are loading the agent loader as early in the Guice start up as possible where it will be instantiated by both the Play application and unit tests.

/c

Rob Bygrave

unread,
Apr 23, 2015, 5:01:42 PM4/23/15
to ebean@googlegroups

Do you know of any (working) examples of loading the agent via SBT? 
No and unfortunately I don't know much about SBT at all.

However, the first link includes ... "sbt 0.13.8 adds an extension point whereby users can effectively manipulate java bytecode (.class files) before the incremental compiler attempts to cache the classfile hashes."
... so it could be that how enhancement should work with SBT has significantly changed since SBT 0.13.8 (that's my guess).

Also note that Play 2.4 should support Ebean 4.x and the related enhancement code for Play is here: https://github.com/playframework/play-ebean/blob/master/sbt-play-ebean/src/main/scala/play/ebean/sbt/SbtEbean.scala
... and James Roper made some changes/commits 2 days ago.  So maybe watch the Play 2.4 Ebean 4.x integration project and perhaps look to use that? - https://github.com/playframework/play-ebean


 I'll continue to try and track down why the bean is loading early.
Ok. The other option I forgot to mention for enhancement during development is to use the IntelliJ Ebean plugin.


Cheers, Rob.



Emanuel Greisen

unread,
Jan 23, 2017, 6:19:30 AM1/23/17
to Ebean ORM
I am using this with "ebean-spring-agent" and getting very strange behaviour. It seems to enhance some classes, and the later I wait before invoking EbeanServerFactory.create(...) the better. However, it seems to be rather random - I have had things working for weeks when all of a sudden it just didn't get all classes enhanced in due time.

Now, Rob states that he is not going to use the ebean-spring-agent, and also the ebeanorm website says the agent-loader is a bad idea. But, when it works, it works really well.

Rob Bygrave

unread,
Jan 26, 2017, 3:18:35 AM1/26/17
to ebean@googlegroups
> when it works, it works really well.

Quite right.



> website says the agent-loader is a bad idea

Yes, because there is effectively a "race" in that it works great when the agent loads early enough (before any entity classes are loaded) but it is hard to ensure that the agent loads early enough in all cases (and so sometimes it disappoints and so isn't really considered reliable enough).




To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages