Hello everyone,
My name is Chris, I work in a small team that tries to slowly migrate an old c++ db code to java, we plan to use Hibernate's JPA api.
One requirement is that we have to keep the current database structure, which actually targets both Ms SQLServer and Oracle.
Therefore I used the hibernate generator (
Code:
org.hibernate.tool.ant.HibernateToolTask
) to rev-eng the db structure and generate JPA annotated POJOs.
Due to some SQLServer quirks, a table A that should have a FK towards table B is not actually modeled with a FK in the SQlServer db (on SQLServer, the delete cascade that we get for a FK is not recursive, so the db uses other mechanisms for achieving the effect of a recursive delete cascade, while avoiding the FK - sure, it's less than ideal, but it has been working like that in the past).
The same table A has an actual FK towards table B under Oracle (because Oracle's FK comes with a properly recursive delete cascade).
Now, the thing is, we will get two different pojo's based on our databases. The one we get for Oracle has an extra member of type B for the FK relation that is present in Oracle db.
The pojo we get for SQLServer does NOT have the same member, of course, because there is no direct FK linking A and B inside the SQLServer db. All this is normal, I know.
Still, I would like to use one POJO for all databases and since the logical structure is really the 'same', I'd like to find a way to use one mapping only.
So I have naively tried to use the POJO I got for Oracle with SQLServer, hoping that Hibernate will find the extra annotation and will use it to fetch B data inside A, without further checking the presence of the FK in the SQLServer db structure.
Instead, when Hibernate initializes, it checks the mapping info against my SQLServer connection and (correctly) fails with an annotation exception.
I understand why that happens.
Still, I would like to ask if there is a clean or 'almost' clean way to get what I want.
Which is clearly to use a single set of POJOs which can be used with both our databases (without touching the db structures).
I know, I know, this is not a clean approach. That's why I am here, because I want something as clean as possible, but without changing the database structure.
Is there by any chance something that could me, in my ingrate situation?
Thanks,
Chris