Hi All
i want to get session of different configuration file so i can fire SQL query on that database.
Code:
1 public SessionFactory createSessionFactory() {
2 Configuration prototypeConfig = new Configuration().configure("shard0.hibernate.cfg.xml");
3 prototypeConfig.addResource("weather.hbm.xml");
4 List<ShardConfiguration> shardConfigs = new ArrayList<ShardConfiguration>();
5 shardConfigs.add(buildShardConfig("shard0.hibernate.cfg.xml"));
6 shardConfigs.add(buildShardConfig("shard1.hibernate.cfg.xml"));
7 shardConfigs.add(buildShardConfig("shard2.hibernate.cfg.xml"));
8 ShardStrategyFactory shardStrategyFactory = buildShardStrategyFactory();
9 ShardedConfiguration shardedConfig = new ShardedConfiguration(
10 prototypeConfig,
11 shardConfigs,
12 shardStrategyFactory);
13 return shardedConfig.buildShardedSessionFactory();
14 }
15
16 ShardStrategyFactory buildShardStrategyFactory() {
17 ShardStrategyFactory shardStrategyFactory = new ShardStrategyFactory() {
18 public ShardStrategy newShardStrategy(List<ShardId> shardIds) {
19 RoundRobinShardLoadBalancer loadBalancer = new RoundRobinShardLoadBalancer(shardIds);
20 ShardSelectionStrategy pss = new RoundRobinShardSelectionStrategy(loadBalancer);
21 ShardResolutionStrategy prs = new AllShardsShardResolutionStrategy(shardIds);
22 ShardAccessStrategy pas = new SequentialShardAccessStrategy();
23 return new ShardStrategyImpl(pss, prs, pas);
24 }
25 };
26 return shardStrategyFactory;
27 }
28
29 ShardConfiguration buildShardConfig(String configFile) {
30 Configuration config = new Configuration().configure(configFile);
31 return new ConfigurationToShardConfigurationAdapter(config);
32 }
this is the only code which i got to create session factory, but the problem is how to get session of different configuration file.
Here we configure first xml file and add rest of configuration file, but the problem is you get the session of first configuration file shard0.hibernate.cfg.xml, but how to get other.
Please reply.