| I can see your point on that, people use getReference to avoid unnecessary database calls. As I read it, getReference doesn't prohibit a database call, only that "state may be lazily fetched." In some sense, the discriminator type isn't an "unnecessary" database, since that information is required to return a proxy of the correct type (still, I'll concede better to have none at all if there's another way). The trouble I've found is when there's a bit more going on during a transaction, and in one service a getReference is called (where type isn't important), followed later by a find in another service (where it is important), leading to a ClassCastException (since the old proxy is returned), which can be hard to trace since it can be far away from the getOne() call. Is there, perhaps, a way to throw clearer exception in this case? Or maybe a way to "upgrade" the proxy when find is called? Something else to provide a bit more help to a developers than a ClassCastException? |