Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate using multiple databases
    primarykey
    data
    text
    <p>Someone know how to add a another datasource in hibernate configuration and how to configure Spring to that datasource its autoinject in my respective DAO?</p> <p>This is my code with one datasource, that run perfectly, but i don't know how add another datasource. I want to add another data source that is a database with different tables than the actual database.</p> <p>HIBERNATE CONF</p> <pre><code> &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName"&gt; &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt; &lt;/property&gt; &lt;property name="url" value="jdbc:mysql://localhost/personal"/&gt; &lt;property name="username" value="root"/&gt; &lt;property name="password" value="mysql"/&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="dataSource"&gt; &lt;ref local="dataSource"/&gt; &lt;/property&gt; &lt;property name="packagesToScan"&gt; &lt;list&gt; &lt;value&gt;com.app.personal.model&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;tx:annotation-driven/&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory"&gt; &lt;ref local="sessionFactory"/&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>DAO EXAMPLE</p> <pre><code>@Repository public class ModuloDAOHibernate extends HibernateTemplate implements ModuloDAO { @Autowired public ModuloDAOHibernate(SessionFactory sessionFactory) { super(sessionFactory); } public List&lt;Modulo&gt; getAllGrupoModuloDAO() { Criteria criteriaList = this.getSession().createCriteria(Modulo.class); criteriaList.addOrder(Order.asc("orden")); return criteriaList.list(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload