I run into this problem a lot. I want to make components reusable, but because of relationships I can't. Let me explain...
The User module
I have User.class which contains
emailAddress, password, etc...
The Content module
Content.class holds images and text and other things.
It has a field user, that is ManyToOne in order to know who owns that content.
UserExtension module
I need to extend User.class to store a bunch of specific data for an application.
The problem I run into is
Content content = getContentFromSomewhere();
User user = content.getUser();
UserExtension extension = getUserExtention(user);
I'm looking for way to be able to get UserExtension directly from content. It would just make life a lot easier when writing queries and such.
Is there anything to 'tell' the Content.class that its relationship is with UserExtension and not User (User is just a MappedSuperclass). So I could do something like:
UserExtension extension = (User) content.getUser();
I always run into problems like this. I want to keep code simple and reusable for many projects. Currently I create a lot of 'boilerplate' code, like wrapper classes to hold a Content.class and a UserExtension.class. Then a bunch of methods to retrieve them all the various ways.
Thoughts anyone?
Thanks!
|