I have one common project that is dependent to an application called application1. I configured in this way the xmls that each project has a distinct jdbc properties file ( different filename ), which directs to different database. Postgres and MySQL. I created the following snippet:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/applicationContext.xml", "/common-applicationContext.xml"})
@Transactional
public class AppTest extends AbstractTransactionalJUnit4SpringContextTests{
static Logger log = Logger.getLogger(App.class.getName());
@Resource(name = "testDao")
private IDAO dao;//Traces testDao, which originates in common package
@Resource(name = "testApplication1Dao")
private IDAO daoApplication1;//Traces dao from application1 package
@Test
public void AppContextTest(){
SessionFactory sf1 = dao.getHibernateTemplate().getSessionFactory();
SessionFactory sf2 = daoApplication1.getHibernateTemplate().getSessionFactory();
- The classes TestDao and TestApplication1Dao, are extending IDAO.
Common interface. - testApplication1Dao->Postgres, configured in
applicationContext.xml and in pgsql.jdbc.properties - testDao->Mysql, configured in common-applicationContext.xml and in
mysql.jdbc.properties.
Why debugging with eclipse, I see that dao and daoApplicatio1 are same objects? Should they?
How can I print on screen, the connections and properties behind each of the dao objects?
Thanks in advance
EDIT(1)
From common project:
import org.springframework.stereotype.Repository;
@Repository("testDao")
public class TestDao extends AbstractDao {}
From application1 project:
import org.springframework.stereotype.Repository;
import gr.org.infrastructure.common.db.AbstractDao;
@Repository("testApplication1Dao")
public class TestApplication1Dao extends AbstractDao {}
and the AbstractDao is an extension of IDAO ( interface ), nothing bizzare…:
@Transactional(propagation=Propagation.REQUIRED)
public abstract class AbstractDao implements IDAO {
private HibernateTemplate hibernateTemplate;
private boolean rollbacked;
public AbstractDao() {
super();
this.rollbacked = false;
// TODO Auto-generated constructor stub
}
Apparently solved the problem and I can have concurrently two seperate connections live in the spring/hibernate app. In case anyone is interested drop me a note.