0

私はliferayを使用していますが、クラスとメソッドは次のとおりです。

EmployeeLocalServiceImpl.java

public class EmployeeLocalServiceImpl extends EmployeeLocalServiceBaseImpl {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never reference this interface directly. Always use {@link com.mallyas.corpserver.emco.mis.service.EmployeeLocalServiceUtil} to access the employee local service.
     */

    public List getEmployee() throws PortalException, SystemException, RemoteException {

        return EmployeeFinderUtil.getEmployee();
    }
 ...
}

EmployeeFinderImpl.java

public class EmployeeFinderImpl extends BasePersistenceImpl<Employee> implements EmployeeFinder {

    // the name of the query
    public static String GET_EMPLOYEE = "getemployee";

    // the method which will be called from the ServiceImpl class

    public List<Employee> getEmployee() throws SystemException {

        Session session = null;
        try {
            // open a new hibernate session
            session = openSession();


            String fetchEmpsqlquery = CustomSQLUtil.get(GET_EMPLOYEE);

            // create a SQLQuery object
            SQLQuery empqueryObj = session.createSQLQuery(fetchEmpsqlquery);

            // replace the "Book" in the query string with the fully qualified java class
            // this has to be the hibernate table name
            empqueryObj.addEntity("Employee", EmployeeImpl.class);


            // Get query position instance
            QueryPos qPos = QueryPos.getInstance(empqueryObj);

            // fill in the "?" value of the custom query
            // this is same like forming a prepared statement
            //qPos.add(pattern);

            // execute the query and return a list from the db
            return (List<Employee>)empqueryObj.list();

            /*
            // use this block if you want to return the no. of rows (count)

            int rows = 0;

            Iterator<Long> itr = q.list().iterator();

            if (itr.hasNext()) { Long count = itr.next();

            if (count != null) { rows = count.intValue(); } }

            return rows;
            */
        } catch (Exception e) {
            throw new SystemException(e);
        } finally {
            closeSession(session);
        }
    }

    ...

}

EmployeeFinder.java

@Transactional
public interface EmployeeFinder {

    public java.util.List<com.mallyas.corpserver.emco.mis.model.Employee> getEmployee()
        throws com.liferay.portal.kernel.exception.SystemException;
}

EmployeeFinderUtil.java

@Transactional
public class EmployeeFinderUtil {

    public static java.util.List<com.mallyas.corpserver.emco.mis.model.Employee> getEmployee()
        throws com.liferay.portal.kernel.exception.SystemException {
        return getFinder().getEmployee();
    }

    public static EmployeeFinder getFinder() {
        if (_finder == null) {
            _finder = (EmployeeFinder)PortletBeanLocatorUtil.locate(com.mallyas.corpserver.emco.mis.service.ClpSerializer.getServletContextName(),
                    EmployeeFinder.class.getName());

            ReferenceRegistry.registerReference(EmployeeFinderUtil.class,
                "_finder");
        }

        return _finder;
    }

    public void setFinder(EmployeeFinder finder) {
        _finder = finder;

        ReferenceRegistry.registerReference(EmployeeFinderUtil.class, "_finder");
    }

    private static EmployeeFinder _finder;

このアプリケーションを実行すると、次のエラーが発生します。

ERROR [http-bio-8080-exec-9][render_portlet_jsp:154] com.liferay.portal.kernel.exception.SystemException: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    at com.mallyas.corpserver.emco.mis.service.persistence.EmployeeFinderImpl.getEmployee(EmployeeFinderImpl.java:69)
    at com.liferay.portal.dao.shard.advice.ShardPersistenceAdvice.invoke(ShardPersistenceAdvice.java:52)
    at com.mallyas.corpserver.emco.mis.service.persistence.EmployeeFinderUtil.getEmployee(EmployeeFinderUtil.java:29)
    at com.mallyas.corpserver.emco.mis.service.impl.EmployeeLocalServiceImpl.getEmployee(EmployeeLocalServiceImpl.java:61)
    at org.apache.jsp.admin.displayData.dbcheck_jsp._jspService(dbcheck_jsp.java:172)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)

何が間違っている可能性がありますか?上記の各クラスに@Transactionalを含めました。また、すべてのクラスから@Transactionalを削除しようとしましたが、それでも同じエラーが発生します。

4

4 に答える 4

0

Hibernate構成に次のプロパティを追加してみてください。

<prop key="hibernate.current_session_context_class">thread</prop>

これは基本的にスレッドごとにセッションをバインドします。

于 2013-03-18T06:05:08.203 に答える
0

FinderImpl または Finder クラスからメソッドを呼び出しているときに、おそらくこれらの例外が発生していると思います。また、Finder クラスを使用してカスタム クエリを実行していると思います。そのメソッドに「getEmployeeByCustom」という名前を付けます

Finder.java または FinderUtil.java クラスを編集する必要はありません。FinderImpl.java クラスのみを編集します。

EmployeeLocalServiceImpl で必ずラッパー関数を使用してください

    public List<Employee> getEmployeeByCustom(.....) 
        throws SystemException {

    return EmployeeFinderUtil.getEmployeeByCustom(....);

}

次に、EmployeeLocalServiceUtil.getEmployeeByCustom(...) を介して「getEmployeeByCustom」を呼び出します。

「トランザクション」関連の編集を元に戻す必要があります。それらを台無しにするつもりはありません。また、必ずこのチュートリアルを確認してください

于 2013-03-19T09:07:24.023 に答える
0

Liferay 6.1.20 を使用し、ビルドには Liferay プラグイン バージョン 6.2.10.9 で maven を使用しました。

EmployeeFinderImpl クラスが service.persistence パッケージ/フォルダーにあることを確認してください。

サービス ビルダーを実行すると、EmployeeFinderImpl のインターフェイスが生成されます。さらに、それをインスタンス化するコードを EmployeeLocalServiceImpl に追加します。

EmployeeLocalServiceImpl には、その中でインスタンス化された EmployeeFinderImpl クラスが既にあるはずであり、コードを次のように変更すると機能します。

public class EmployeeLocalServiceImpl extends EmployeeLocalServiceBaseImpl {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never reference this interface directly. Always use {@link com.mallyas.corpserver.emco.mis.service.EmployeeLocalServiceUtil} to access the employee local service.
     */

    public List getEmployee() throws PortalException, SystemException, RemoteException {

        return employeeFinder.getEmployee();
    }
 ...
}
于 2015-10-02T19:36:30.333 に答える