Hello,
In our application we have an object that holds all the details of a Project. At some point we decided we needed versions for a Project so we created a new class ProjectVersion and made Project a child of this class (ProjectVersion has the project fields declaration now). Also we added a class ProjectGroup that holds the original project id and the link to its latest version. In order to change as little as possible in the code, at the database level we changed the Project table into a view that joins ProjectVersion with ProjectGroup in order to show only the latest versions of the projects.
Now for Hibernate we first tried to use inheritance and joined-subclass seemed to be the proper choice for the Project class (joining with ProjectGroup to obtain only the latest versions). But when trying to select all the ProjectVersions hibernate will automatically add the join for the Project class, so we can't do queries on ProjectVersions. After that we tried to map individually the two classes, so we mapped the Project class on the Project view. But now at startup Hibernate complains that it can't add foreign keys because underlying table is actually a view. And maybe there are other things wrong with this approach?!?
I'm asking to see if you guys know a better way to do the hibernate mappings in this case or maybe you did things differently to add versions to an object?
Thanks, Alex
|