我正在使用 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,但我仍然得到同样的错误..