Full Hibernate Plugin only working with Hibernate3. Anyway with Hibernate4?

880 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.