Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, so i will just give you y configuration:</p> <p>In folder WEB-INF i have 2 files:</p> <p>1) hibernate-context.xml </p> <p>content:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "&gt; &lt;context:property-placeholder location="/WEB-INF/spring.properties"/&gt; &lt;!-- Enable annotation style of managing transactions --&gt; &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt; &lt;!-- &lt;tx:annotation-driven/&gt; --&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" p:dataSource-ref="dataSource" p:configLocation="${hibernate.config}" p:packagesToScan="com.rasp.lta"/&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${app.jdbc.driverClassName}"/&gt; &lt;property name="url" value="jdbc:mysql://{url to database}"/&gt; &lt;property name="username" value="{user name}"/&gt; &lt;property name="password" value="{password}"/&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory"&gt; &lt;qualifier value="transactionManager"/&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>2) hibernate.cfg.xml</p> <p>content:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/property&gt; &lt;property name="show_sql"&gt;true&lt;/property&gt; &lt;!--&lt;property name="create"&gt;update&lt;/property&gt;--&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <p>Then in WEB-INF i have folder: spring in which there is file root-context.xml, the content is:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt; &lt;!-- Root Context: defines shared resources visible to all other web components --&gt; &lt;import resource="../hibernate-context.xml"/&gt; &lt;/beans&gt; </code></pre> <p>Additionally to have transaction in whole project, you should add to web.xml:</p> <pre><code>&lt;filter&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.orm.hibernate3.support.OpenSessionInViewFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;filter&gt; &lt;filter-name&gt;encoding-filter&lt;/filter-name&gt; &lt;filter-class&gt; org.springframework.web.filter.CharacterEncodingFilter &lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;encoding&lt;/param-name&gt; &lt;param-value&gt;UTF-8&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;forceEncoding&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; </code></pre> <p>And in the end in controller:</p> <pre><code> @Service("linkAddress") @Transactional public class LinkAddressService { @Resource(name = "sessionFactory") private SessionFactory sessionFactory; public List&lt;LinkAddressEntity&gt; linkAddressEntityList(String linkList){ Session session = sessionFactory.getCurrentSession(); List&lt;LinkAddressEntity&gt; linkAddressList = (List&lt;LinkAddressEntity&gt;) session.getNamedQuery(LinkAddressEntity.QUERY_IN) .setString("id", linkList).list(); return linkAddressList; } } </code></pre> <p>I hope it will be helpfull.</p>
    singulars
    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.
    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