0

I am using struts2-fullhibernatecore-plugin-2.2.2-GA in a demo strut2 project with Hibernate. I tried my best but can not make it work. I am using all the latest jars.

Am I missing something?

Please help

ERROR LOG

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

Library in my project

enter image description here

When I access page than get error

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)......

My 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();
    }
}

**EDITED *********************

 @SessionTarget
        Session session;

        @TransactionTarget
        Transaction transaction;

Problem is in the above code when Session and Transaction is injected. I am wondering that this might be problem of struts2-fullhibernatecore-plugin-2.2.2-GA not supporting

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

because plugin site http://code.google.com/p/full-hibernate-plugin-for-struts2/ mentioned that only supported versions are

This plugin is compatible with Hibernate Validator 3.1.0 and 4.0.2 (since 2.2 version).

Is that the problem. Have anyone used this plugin with above mentioned versions?

One more question: Can we use this plugin in the production environment?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Pirzada
  • 4,685
  • 18
  • 60
  • 113
  • 1
    This does not look related to Hibernate Validator. It looks like your Injection mechanism simply is not working. What are you using? CDI ? Check/debug your DI mechanism enable logging on that. Ensure it is bootstrapping and annotation processing covers scanning this class. – Darryl Miles Sep 13 '12 at 22:17
  • @darryl-miles, Thanks for the reply. I have edited my question. Please read edited at the end. – Pirzada Sep 14 '12 at 11:13
  • and if you use hibernate 3.6.10+ a NPE should be easy to check with a debugging breaking in CustomerDAOImpl what is the value of 'session' and 'transaction' you say it _IS_ injected but the NPE says otherwise. Split the statement into 2 'Query q = session.createQuery(...); return q.list();' which line is the NPE now ? – Darryl Miles Sep 14 '12 at 22:41
  • my question is why you want this? why you exposing your DB layer to UI any specific benefits or anything you getting? – Umesh Awasthi Sep 15 '12 at 18:37
  • @umesh-awasthi, You are asking why I want to use struts2-fullhibernatecore-plugin-2.2.2-GA OR HibernateSessionInterceptor? – Pirzada Sep 15 '12 at 18:47
  • well i suggested you the plugin in other question, but IMO i will never prefer that approach and i tend to separate my layers by defining certain set of ModelObject and DTO's. i hope i m clear enough here – Umesh Awasthi Sep 15 '12 at 18:56

1 Answers1

4

I think you have to use Hibernate 3 for plugin.

Beacause in Hibernate 4 DTDEntityResolver class's package is changed which use by plugin. In Hibernate 3 this class is in org.hibernate.util package while in hibernate4 this class is in org.hibernate.internal.xml.util package.

bluish
  • 26,356
  • 27
  • 122
  • 180
Punit Patel
  • 901
  • 1
  • 12
  • 25