-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Mutliple schema , same database, same table strcture problem
PostPosted: Tue Feb 23, 2010 5:53 pm 
Newbie

Joined: Tue Feb 23, 2010 5:31 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Mutliple schema , same database, same table strcture problem
PostPosted: Tue Feb 23, 2010 11:10 pm 
Newbie

Joined: Tue Feb 23, 2010 11:06 pm
Posts: 2
Hi Patemir,

Did you try with criteria API provided. you can use following method,
https://www.hibernate.org/hib_docs/v3/a ... .String%29

public Criteria createCriteria(String entityName)

and create your queries.


Top
 Profile  
 
 Post subject: Re: Mutliple schema , same database, same table strcture problem
PostPosted: Wed Feb 24, 2010 12:44 pm 
Newbie

Joined: Tue Feb 23, 2010 5:31 pm
Posts: 2
yeah , thats works.

But so I think everybody is agree with the approach of solving my problem. (use of entity-name).

I thought , people reading this will first ask/suggest some other solution to solve the problem. But I think that is only way to solve problem (using entity-name).

-thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.