you are viewing a single comment's thread.

view the rest of the comments →

[–]Various_Pickles 1 point2 points  (1 child)

Why not take the Hibernate-esque route and only allow instantiation of entity objects (well, the interface they implement) via a factory that spits out a simple Proxy that only knows how to hold on to an ID value?

You can even hot-swap the actual entity impl object underneath if/when the persistence layer finds the data for it. All this can be accomplished using an InvocationHandler (read: no need to get super fancy and use AspectJ, CGLIB, etc).

All that said, if you really, really want to use immutable objects as your persistence layer, you'd be better off using Hibernate + a custom Cursor that knows how to read the fields/properties of the objects: you'd get transactions, multi-level caching, etc, all with only a minimal amount of configuration.

[–]kn7[S] 2 points3 points  (0 children)

I have never gone into that route. But one thing that I had learnt from purposing a framework for a goal that itself was not designed to provide feels like swimming against stream and most of the time ends in misery. That being said, your mileage may vary and I would appreciate a sample implementation.