I tried but it does not work.
The point is, I have an abstract base class with a getIdentifier function. Every class that inherits from that will provide its own implementation. I want to be able to query against this so I set up the following:
user (abstract)
- getIdentifier (not mapped in hibernate)
subuser1
- getIdentifier (mapped in hibernate using formula to give the email address)
subuser2
- getIdentifier (mapped in hibernate using formula to give the username)
This works as long as you query for the exact subtype, but a query against just user will fail.
I tried this next
user (abstract)
- getIdentifier (mapped as formula returning "")
subuser1
- getIdentifier (mapped in hibernate using formula to give the email address)
subuser2
- getIdentifier (mapped in hibernate using formula to give the username)
This allows to query against the general user type, but all queries for identifier return "", because the base property formula overrides those of its children.
From an OO perspective this should not happen and as formula properties are no static members, but dynamic fields (more like functions) I want to be able to alter their implementation for each subclass.
The reason I don't want to map both the identifier and the username and the email column is that this would give me redundant data in the database as the email and username field are already saved. But I'll stick to this path as I see no other working alternative at this point.
|