Hi,
I am implmenting one of the use case with spring and hibernate, I am having problem with mulitple schema of db2. Let me first give some details:
Database: DB2
Database name: ABC
Schemas: Under database ABC- I have four schemas IL,TX,NJ and CA (for each state different schema)
Under every schema I have tables like P,Q,R (same table definition under every schema)
Now data of each state should be stored under their schema.
As its clear that I have same database so I configured only one session factory pointing to this database. Now runtime I have decide in which schema I have to store data, so for that I have mapped my class with diffrent entity-names, my mapping for class P will be something like
Code:
<hibernate-mapping>
<class name="P"
table="IL.P" entity-name="IL">
//rest of field
</class>
<class name="P"
table="TX.P" entity-name="TX">
//rest of field
</class
</hibernate-mapping>
Now when I have to save say my POJO in IL schema, I am using this
Code:
HibernateTemplate template = new HibernateTemplate(sessionFactory);
template.save("IL", p);
And so far this is working fine for saving data. But now I want to write finder methods using hql/criteria, but not sure how to use the entity-name into them. If I just use finder without any entity name then I think it will search on all tables. Not sure how come hibernate miss to handle this scenario of (Mutliple schema , same database, same table strcture problem).
And ya its very necessary to store data in seperate schema - its valid requirement that data of IL customer should be in IL schema.
Please advice how should I go for implementing finder methods.
Thanks,
patemir