0

I been struggling with struts2-fullhibernatecore-plugin-2.2.2-GA for my CRUD demo project for learning purpose. Below is the error I get and than different hibernate dependencies tried to make it work. See below

ERROR

java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
    com.googlecode.s2hibernate.struts2.plugin.util.HibernateSessionFactory.createAndTestSessionFactory(HibernateSessionFactory.java:284)
    com.googlecode.s2hibernate.struts2.plugin.util.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:227)
    com.googlecode.s2hibernate.struts2.plugin.util.HibernateSessionFactory.getNewSession(HibernateSessionFactory.java:155)

I understand from this thread answer Click Here

Than I started different maven dependeces to check hibernate version working with plugin and found

NOT WORKING FROM BELOW VERSION

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.6.Final</version>
</dependency>

WORKING TILL THIS VERSION

  <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.6.10.Final</version>
        </dependency>

Question: Obviously don't want to use Hibernate3 so is there a way I can use latest hibernate4+ with struts2-fullhibernatecore-plugin-2.2.2-GA?

Question: What is the most widely used DI for hibernate in struts2. Should I go for Spring or google juice if above plugin not working?. Don't see any other viable solution for managing hibernate session except that viewpattern but say its antipattern and has many drawbacks.

Community
  • 1
  • 1
Pirzada
  • 4,685
  • 18
  • 60
  • 113
  • As the answer you linked to indicates, Hibernate 4 has some API incompatibilities with Hibernate 3, so no, Hibernate 4 is not compatible with the version of the plugin you are trying to use. – Steven Benitez Sep 18 '12 at 16:05
  • @steven-benitez, Thanks. What should I do than?. Can you answer my last question?. Hope to get more feedback. – Pirzada Sep 18 '12 at 17:18
  • @steven-benitez, I think Open Session in View pattern is the most common way to be used? – Pirzada Sep 18 '12 at 17:28
  • Open Session in View is an excellent pattern. Also, I prefer Google Guice for DI, but to each his own. – Steven Benitez Sep 20 '12 at 18:51
  • @steven-benitez, Do you have any code sample on Google Guice with hibernate for DI?. I am looking for it. Can you share your own implementation. Thanks – Pirzada Sep 21 '12 at 04:28
  • My implementation is based on the Guice Persist extension, which is for JPA. Take a look at that and it should get you started. – Steven Benitez Sep 21 '12 at 13:28

1 Answers1

0

use this config

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <components>
                        <component>
                            <name>hbm2ddl</name>
                            <implementation>jpaconfiguration</implementation>
                        </component>
                    </components>
                    <componentProperties>
                        <outputfilename>schema.ddl</outputfilename>
                        <create>true</create>
                        <export>false</export>
                        <format>true</format>
                        <drop>true</drop>
                        <jdk5>true</jdk5>
                        <propertyfile>target/test-classes/jdbc.properties</propertyfile>
                        <skip>${skipTests}</skip>
                    </componentProperties>
                </configuration>
                <!--<executions>-->
                <!--<execution>-->
                <!--<phase>process-test-resources</phase>-->
                <!--<goals>-->
                <!--<goal>hbm2ddl</goal>-->
                <!--</goals>-->
                <!--</execution>-->
                <!--</executions>-->
                <dependencies>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-entitymanager</artifactId>
                        <version>${hibernate.maven.plugin.version}</version>
                        <exclusions>
                            <exclusion>
                                <groupId>cglib</groupId>
                                <artifactId>cglib</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>commons-logging</groupId>
                                <artifactId>commons-logging</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-core</artifactId>
                        <version>${hibernate.maven.plugin.version}</version>
                        <exclusions>
                            <exclusion>
                                <groupId>cglib</groupId>
                                <artifactId>cglib</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>commons-logging</groupId>
                                <artifactId>commons-logging</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-validator</artifactId>
                        <version>4.2.0.Final</version>
                    </dependency>
                    <dependency>
                        <groupId>${jdbc.groupId}</groupId>
                        <artifactId>${jdbc.artifactId}</artifactId>
                        <version>${jdbc.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

and add <hibernate.maven.plugin.version>3.6.10.Final</hibernate.maven.plugin.version> to your pom properties.

maziar
  • 581
  • 3
  • 9