【问题标题】:struts2-fullhibernatecore-plugin-2.2.2-GA not workingstruts2-fullhibernatecore-plugin-2.2.2-GA 不工作
【发布时间】:2012-09-07 01:19:05
【问题描述】:

我在一个带有 Hibernate 的演示 strut2 项目中使用 struts2-fullhibernatecore-plugin-2.2.2-GA。我尽力而为,但无法使其发挥作用。我正在使用所有最新的罐子。

我错过了什么吗?

请帮忙

错误日志

2012-09-14 02:06:50 - [  INFO - SessionTransactionInjectorInterceptor:41 ] --> Full Hibernate Plugin Validation could not detect Hibernate Validator 3.x
2012-09-14 02:06:50 - [  INFO - SessionTransactionInjectorInterceptor:46 ] --> Full Hibernate Plugin Validation using Hibernate Validator 4.x

我项目中的库

当我访问页面时出现错误

java.lang.NullPointerException

    com.myapp.dao.CustomerDAOImpl.listCustomer(CustomerDAOImpl.java:26)
    com.myapp.web.CustomerAction.listCustomer(CustomerAction.java:47)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)......

我的 CustomerDAOImpl.java

package com.myapp.dao;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
import com.myapp.model.Customer;
import org.hibernate.Session;
import org.hibernate.Transaction;

import java.util.List;

public class CustomerDAOImpl implements CustomerDAO {

    @SessionTarget
    Session session;

    @TransactionTarget
    Transaction transaction;

    //add the customer
    public void addCustomer(Customer customer) {
        session.save(customer);
    }

    //return all the customers in list
    public List<Customer> listCustomer() {
        return session.createQuery("from Customer").list();
    }
}

**已编辑 *********************

 @SessionTarget
        Session session;

        @TransactionTarget
        Transaction transaction;

上面的代码在注入Session和Transaction的时候有问题。我想知道这可能是 struts2-fullhibernatecore-plugin-2.2.2-GA 不支持的问题

hibernate-release-4.1.6.Final
hibernate-validator-4.3.0.Final

因为插件站点http://code.google.com/p/full-hibernate-plugin-for-struts2/提到只有支持的版本是

此插件兼容 Hibernate Validator 3.1.0 和 4.0.2(从 2.2 版本开始)

这就是问题所在。有没有人在上面提到的版本中使用过这个插件?

还有一个问题:我们可以在生产环境中使用这个插件吗?

【问题讨论】:

  • 这看起来与 Hibernate Validator 无关。看起来您的注入机制根本不起作用。你在用什么? CDI ?检查/调试您的 DI 机制启用登录。确保它是引导和注释处理涵盖扫描此类。
  • @darryl-miles,感谢您的回复。我已经编辑了我的问题。请阅读最后编辑的内容。
  • 如果你使用hibernate 3.6.10+,一个NPE应该很容易通过CustomerDAOImpl中的调试中断来检查你说的'session'和'transaction'的值是什么IS 注入但 NPE 另有说明。将语句拆分为 2 'Query q = session.createQuery(...);返回 q.list();' NPE 现在是哪一行?
  • 我的问题是你为什么要这个?为什么你将你的 DB 层暴露给 UI 任何特定的好处或你得到的任何东西?
  • @umesh-awasthi,你问我为什么要使用 struts2-fullhibernatecore-plugin-2.2.2-GA OR HibernateSessionInterceptor?

标签: hibernate jakarta-ee struts2 struts2-s2hibernate


【解决方案1】:

我认为你必须使用 Hibernate 3 作为插件。

因为在 Hibernate 4 DTDEntityResolver 类的包被插件使用改变了。在 Hibernate 3 中,这个类在 org.hibernate.util 包中,而在 Hibernate4 中,这个类在 org.hibernate.internal.xml.util 包中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多