完整的Hibernate插件仅适用于Hibernate3。用Hibernate4怎么样?

完整的Hibernate插件仅适用于Hibernate3。用Hibernate4怎么样?,hibernate,jakarta-ee,struts2,struts2-s2hibernate,Hibernate,Jakarta Ee,Struts2,Struts2 S2hibernate,为了学习CRUD演示项目,我一直在努力学习struts2-fullhibernatecore-plugin-2.2.2-GA。下面是我遇到的错误,不同的hibernate依赖关系试图使其正常工作。见下文 错误 java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session; com.googlecode.s2hibernate.struts2.plu

为了学习CRUD演示项目,我一直在努力学习struts2-fullhibernatecore-plugin-2.2.2-GA。下面是我遇到的错误,不同的hibernate依赖关系试图使其正常工作。见下文

错误

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)
我从这条线索中理解了答案

然后,我启动了不同的maven dependeces来检查hibernate版本,并找到了插件

无法从下面的版本工作

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

org.hibernate
冬眠核心
4.1.6.最终版本
一直工作到这个版本

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

org.hibernate
冬眠核心
3.6.10.最终版本
问题:显然不想使用Hibernate3,那么有没有一种方法可以将最新的hibernate4+与struts2-fullhibernatecore-plugin-2.2.2-GA一起使用

问题:struts2中hibernate最广泛使用的DI是什么。如果上面的插件不起作用,我应该选择Spring还是google juice?。除了viewpattern之外,没有其他可行的管理hibernate会话的解决方案,但是说它是反模式的,并且有很多缺点。

使用此配置

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

org.codehaus.mojo
hibernate3 maven插件
2.2
hbm2ddl
JPA配置
schema.ddl
真的
假的
真的
真的
真的
目标/测试类/jdbc.properties
${skipTests}
org.hibernate
休眠实体管理器
${hibernate.maven.plugin.version}
cglib
cglib
公用记录
公用记录
org.hibernate
冬眠核心
${hibernate.maven.plugin.version}
cglib
cglib
公用记录
公用记录
org.hibernate
休眠验证器
4.2.0.4最终版本
${jdbc.groupId}
${jdbc.artifactId}
${jdbc.version}

并将
3.6.10.Final
添加到您的pom属性中。

正如您链接到的答案所示,Hibernate 4与Hibernate 3存在一些API不兼容之处,因此不,Hibernate 4与您尝试使用的插件版本不兼容。@steven benitez,谢谢。我应该做什么呢?。你能回答我的最后一个问题吗?。希望得到更多的反馈。@steven benitez,我认为视图中的开放式会话模式是最常用的方式?视图中的开放式会话是一种很好的模式。还有,我更喜欢用GoogleGuice来表示DI,但每个人都有自己的。@steven benitez,你有没有关于GoogleGuice和hibernate来表示DI的代码示例?。我正在找它。你能分享你自己的实现吗。谢谢