Is there a reason why QueyBeans are not enhanced in entityBeans?

67 views
Skip to first unread message

Roland Praml

unread,
Aug 25, 2016, 7:03:13 AM8/25/16
to Ebean ORM

Hello Rob

a new day, a new issue :)

I tried to use QueryBeans in an Entity - with the result that the queryBean does not work. e.g.:
@Entity
public class AclEntry  {

   
static final long serialVersionUID = 1L;

   
private String guid;


   
...

   
public static AclEntry findByGuid(final EbeanServer db, final String guid) {
       
return new QAclEntry(db).guid.eq(guid).findUnique(); // throws NPE here, because no enhancement happens.
   
}
}

As I know in the meantime how to debug the enhancer, I found out that I get a "NoEnhancementRequired" in this codeblock from "TypeQueryClassAdapter":
    if (hasEntityBeanInterface(interfaces)) {
     
throw new NoEnhancementRequiredException("Not enhancing EntityBean");
   
}

This check was added in August 2015: https://github.com/ebean-orm/querybean-agent/commit/ee1c957860bc8d6b554f90cae585c90567db6398

which is wrong in my opinion... r at least I do not understand why QueryBean-enhanchment should be skipped on Entities. (Maybe bad design could be a reason)

It makes the introducion of the combinedTransformer also obsolete a few days before.

https://github.com/ebean-orm/querybean-agent/commit/e8cf012773c0465c2bab9ed368842d6d53d7963c
https://github.com/ebean-orm/ebean-eclipse-enhancer/commit/7cae41d7b18b17c1c622fe94fb2761a7cb4e5e80

If you agree, I can remove that check.

best regards
Roland

Rob Bygrave

unread,
Aug 25, 2016, 7:28:35 AM8/25/16
to ebean@googlegroups
which is wrong in my opinion... r at least I do not understand why QueryBean-enhanchment should be skipped on Entities. 

Purely my opinion but no I'd not put static "finder methods" on an entity bean.  I instead would have a "Finder class" (referenced as a static field).

In the view / opinion that code ought to be able to "grow" in a relatively nice way I prefer putting all the "finder methods" onto a "Finder class" such that it can get bigger with more methods and still be "nice" (and allow the entity bean to still be nice to read, and allows some basic finder functionality to be inherited).  

That is, I think an entity with 20 static finder methods on it is not something I'd like to see myself. I'd personally not start down that path (and instead generate Finder classes).


So:

- Finder classes work in simple cases (few finder methods) and grow nicely when there are losts of finder methods 
- There is existing code generation support to generate and link "Finder classes" (https://youtu.be/smAB0X0X_i4)
- There is existing support for testing "Finder classes" (https://youtu.be/1fjtz_hMw38)

For these reasons I personally don't like "finder methods" on entity classes and don't want to encourage that per say.

Hmmm.


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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Bygrave

unread,
Aug 26, 2016, 3:36:44 AM8/26/16
to ebean@googlegroups

So that all said ... 


Q: Is there any good technical reason why entity beans should not have query bean enhancement?  

A: No.



Q: Longer term should entity bean and query bean enhancement be merged into a single agent that does both?

A: I think yes. "Query beans" have been around about 6 months now and are proving to be pretty good and I think it is pretty likely that in the future the query bean enhancement just becomes part of the "ebean-agent" (which already does entity bean and @Transactional enhancement).

At that point the "ebean-agent" would do:
- Entity bean enhancement
- @Transactional enhancement
- Query bean enhancement

I can't think of a reason why we would not do that, so I think it is just a matter of time before I make that change.


Cheers, Rob.

Reply all
Reply to author
Forward
0 new messages