Die Integration von JTA, Hibernate 4 und die Feder 4 mit WebLogic

Ich habe ernsthafte Probleme mit der Umsetzung einer JTA /Hibernate /Spring-Anwendung (mit WebLogic 10.3 für den server). Ich war ursprünglich mit dem Spring-programmatische Konfiguration, aber bewegt haben Sie es in der Spring-XML-Konfiguration heraus zu filtern und potenzielle Probleme. Es war perfekt funktioniert, wenn ich den HibernateTransactionManager statt der JtaTransactionManager, aber jetzt ist nicht zu finden, die Sitzung für den thread.

Wenn ich mir die sessionFactory es ist nicht null, aber getSession() nicht wieder eine Sitzung.

Könnten Sie mir helfen bei der Fehlersuche das? Danke!

Mein Dao-Implementierung:

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;

...

import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import mil.navy.navsupbsc.utilities.HibernateConfiguration;

@Repository
public class ContactDAOImpl implements ContactDAO {

    @Autowired
    SessionFactory sessionFactory;

    public Session getSession() {
        try {
            sessionFactory.openSession();
            return sessionFactory.getCurrentSession();
        } catch (NullPointerException e) {
            e.printStackTrace();
            throw e;
        }

    }

@SuppressWarnings("unchecked")
public List<Contact> listContact() {

    List<Contact> contactList = getSession().createCriteria(Contact.class)
            .list();
...

Meine Spring-Servlet.xml Datei:

 <?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
    xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="packagesToScan" value="mil.navy.navsupbsc.entity" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.driverClassName">oracle.jdbc.OracleDriver</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
            </props>            
        </property>
    </bean>

    <mvc:annotation-driven />

    <mvc:resources mapping="/resources/**" location="/resources/" />
    <context:component-scan base-package="mil.navy.navsupbsc" />
    <tx:annotation-driven />
    <jee:jndi-lookup id="NCS" jndi-name="NCS" resource-ref="false"></jee:jndi-lookup>
    <tx:jta-transaction-manager />
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>

</beans>

Meine web.xml Datei

  <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" metadata-complete="false" version="2.5">
      <display-name>Contact Management Suite</display-name>
      <welcome-file-list>
        <welcome-file>contact</welcome-file>
      </welcome-file-list>
      <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    <resource-ref>
        <description>NCS</description>
        <res-ref-name>NCS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>


    </web-app>

Und meine weblogic.xml Datei

    <?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
    xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.2/weblogic-web-app.xsd">
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.hibernate.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
    <wls:weblogic-version>10.3.5</wls:weblogic-version>
    <wls:context-root>ncms2</wls:context-root>
    <wls:resource-description>
        <wls:res-ref-name>dbDataSource</wls:res-ref-name>
        <wls:jndi-name>NCS</wls:jndi-name>

    </wls:resource-description>
</wls:weblogic-web-app>
  • Für den Anfang Ihrer getSession - Methode ist fehlerhaft, verwenden Sie niemals openSession in einer Anwendung verwendet, Spring-verwaltete Transaktionen. Sie werden schließlich verbindungen zur Verfügung. Ich don ' T sehen überall, dass Sie Draht der datasource in die LocalSessionFactoryBean also ich bin mir nicht sicher, wie Sie denken, Ruhezustand verbinden wird. Tun Sie eine Suche von jndi-so müssen Sie sich nicht die hibernate.driverClass Eigenschaft.
  • Ich hatte die get-session vor und Lesen, dass die open-session-problem behoben, durch das für jemanden....Ich werde es wieder ändern. Ich hatte auch gedacht das jndi-lookup kümmerte sich um das autowiring...mit der hibernate-Transaktion hatte ich eine Datenquelle Bohne, dass ich autowired zusammen mit der local session bean factory. Muss ich noch eine Datenquelle erstellen, die bean mit jta-wie auch?
Schreibe einen Kommentar