Ok, so I'm looking at the example application - great work, nice and chopped down and perfect for diagnosing issues like this.
Now with regards to this issue I did reproduce ... so the Java example worked as expected and the scala example threw the OptimisticLockingException.
The 'issue' is that with the Scala "Element" on construction it is setting it's id to 0 and parent to null (when compared with the Java "Child" bean which does not). In Ebean internals ... BeanDescriptor.isInsertMode() is doing a check for hasIdProperty() and with "Element" that is returning true ... and so it tries to do an update rather than an insert as we would hope. When the update executes and updates 0 rows that is interpreted as an OptimisticLockingException.
The fix is to treat Id's with a value of 0 as being not set. Now interestingly enough Ebean does do that effectively for 'top level' beans but this bug is that it was not doing that when it cascaded down a level. So for example, I could reproduce by changing the java "Child" bean to have ... int id = 0;
Rolling out release 4.7.1 now which contains this fix (so in maven central in an hour or so).
Cheers, Rob.
Side notes:
- Element.outer had an @Column when that should really be a @JoinColumn I believe.
- The logging was not including the DML statements or Transaction Begin, Commit, Rollback. If you are not seeing that in your logging you are missing out big time (the actual SQL with bind variables and transaction demarcation).
- There is an enhancement plugin for IDEA and Eclipse IDE. With those turned on it is much easier to run/debug main methods