joscha / play-authenticate

An authentication plugin for Play Framework 2.x (Java)
http://joscha.github.com/play-authenticate/
Other
807 stars 366 forks source link

added hibernate example #271

Open skelt opened 9 years ago

skelt commented 9 years ago

Added an example for JPA

joscha commented 9 years ago

uh wow, could you please

for a start? Right now, the changeset contains way too much noise to see the actual changes.

skelt commented 9 years ago

Ok i think thats it (new to github)

joscha commented 9 years ago

Much smaller :) Do you think you could also remove all other clutter that is not needed by the JPA example (e.g. views, test base classes, etc.) to make it even smaller?

skelt commented 9 years ago

I think this is as small as i can make it, unless you can see anything else obvious? :)

skelt commented 9 years ago

Looking at adding a session factory rather than the developer having to call em.close() - will let you know how i get on.

skelt commented 9 years ago

Using session factory over entity manager has the same effect, the developer is responsible for closing sessions. I also looked at an example that uses a proxy to create a session for each transaction request, releasing it when commit is called. The code is more maintainable, but it does not support lazy loading. There is also the issue of only one session running on the main thread that could create a bottleneck/concurrency issues. The code can be seen here if interested: https://github.com/skelt/play-authenticate-hibernate/tree/session-factory

So it looks like the latest commit is the preferred option due to it being fully JPA compliant and thread safe. The only issue is you can't really use @Transactional with this, it will only works if there are no nested transactions.

joscha commented 9 years ago

I think the amount of duplicated code from the main sample is still too high - if we merged this, it would get update hell at some point in time. I wonder if it would be better to extract the samples from the main repository into its own repos, where these can be forked and then adapted (so in the case of hibernate, only the changed and new files would need to be checked in, everything else would come from upstream). What do you think @mkurz ?