Example
Hibernate configuration file #1
Name: hibernate.mysql.cfg.xml
Package: pkc1.hibConfigs
Content:
```
com.mysql.jdbc.Driver
mypasswd
jdbc:mysql://localhost:3306/mydatabase
mylogin
org.hibernate.dialect.MySQLDialect
<mapping resource="model/Soccerplayer.hbm.xml" />
<mapping resource="model/Soccerteam.hbm.xml" />
<!-- others... -->
</hibernate-configuration>
```
Hibernate configuration file #2
Name: hibernate.postgres.cfg.xml
Package: pkc1.hibConfigs
Content:
```
org.postgresql.Driver
mypasswd
jdbc:postgresql://localhost/mydatabase
mylogin
org.hibernate.dialect.PostgreSQLDialect
<mapping resource="model/User.hbm.xml" />
<!-- others... -->
</hibernate-configuration>
```
Configuring these two classes:
struts.propeties
hibernatePlugin.configurationFiles=/pkc1/hibConfigs/hibernate.mysql.cfg.xml,/pkc1/hibConfigs/hibernate.postgres.cfg.xml
struts.xml
<constant name="hibernatePlugin.configurationFiles" value="/pkc1/hibConfigs/hibernate.mysql.cfg.xml,/pkc1/hibConfigs/hibernate.postgres.cfg.xml"></constant>
Using annotations
If using a single Hibernate configuration (only one configurantion file)
Hibernate Core Session:
@SessionTarget
org.hibernate.Session session;
Transaction:
@TransactionTarget
org.hibernate.Transaction transaction;
If using a single multiple Hibernate configuration (multiple one configurantion files, like the two above)
Hibernate Core Session: ``` @SessionTarget("sfMySql") // the same of the name attribute of tag from the hibernate configuration file org.hibernate.Session session1;
@SessionTarget("sfPostgres") // the same of the name attribute of tag from the hibernate configuration file org.hibernate.Session session2; ```
Transaction: ``` @TransactionTarget("session1") // this transaction will be retrieved from session1 object in the same class org.hibernate.Transaction1 transaction1;
@TransactionTarget("session2") // this transaction will be retrieved from session2 object in the same class org.hibernate.Transaction2 transaction2; ```
Note: The Full Hibernate Plugin's Session Factory Class sets the SessionFactory from the first configuration file as the default. So, in the example, the sfMySql would be the default. So, for inject a Session from this SessionFactory we should do just...
@SessionTarget // the *sfMySql* will be used
org.hibernate.Session session1;
Note2: If just one Session object is setted at the @TransactionTarget, the first Session object found in the classe will be used. So...
``` @SessionTarget("sfMySql") org.hibernate.Session sessionA;
@SessionTarget("sfPostgres") org.hibernate.Session sessionB;
@TransactionTarget // this transaction will be retrieved from sessionA object org.hibernate.Transaction2 transaction; ```