Announcement Announcement Module
Collapse
No announcement yet.
How to get the Hibernate Configuration object or equivalent? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get the Hibernate Configuration object or equivalent?

    Spring instantiates the Hibernate SessionFactory itself. How can I get the Hibernate Configuration (Spring reads this data from the applicationContext.xml instead) or equivalent? I need to do this in order to create a table programmatically through Hibernate (unless there is a way to do it in Spring).

    Thanks

  • #2
    You can get rid of Hibernate.cfg.xml or hibernate.properties by putting the same information in applicationContext.xml. Your DAO class needs to extends HibernateDaoSupport class. Then you can call getHibernateTemplate() method (inherited from HibernateDaoSupport) and don't worry about reading configurations, exceptions, etc.

    Hope this helps.

    Comment


    • #3
      LocalSessionFactoryBean / Hibernate uses a datasource, configured by Spring, to "access" the database. You can use this datasource to create your table programmatically:
      Code:
        DataSource ds = (DataSource) context.getBean("dataSource");
        JDBCTemplate tpl = new JDBCTemplate(ds);
        tpl.execute(sql);
      HTH

      Comment

      Working...
      X