吐操一下.Hibernate真心配置麻烦.不是VO. 是sessionFactory
Hibernate版本 支持 hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate3.5以前的版本使用注解使用hibernate-annotations.jar以及ejb-persistence.jar。其实这里的ejb-persistence.jar和前面提到的hibernate-jpa-2.0-api-1.0.0.Final.jar功能一样,实现持久化功能。但hibernate-jpa-2.0-api-1.0.0.Final.jar在ejb-persistence.jar基础上新添了一些类,估计是hibernate官方对jpa的扩展
报错如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibLoginDAOImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/annotations/Entity
ejb3-persistence.jar hibernate-jpa-2.0-api-1.0.1.Final.jarp 这两个是有冲突的.
给出两方配置方式:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="myDataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.danlan.vo.Knowledge</value>
<value>com.danlan.vo.MjhUserinfo</value>
</list>
</property>
</bean>
当然.这里也可以改为目录扫描
<property name="annotatedClasses">
<list>
<value>com.danlan.vo.Knowledge</value>
<value>com.danlan.vo.MjhUserinfo</value>
</list>
</property>
二:
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="myDataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingLocations">
<value>classpath:/com/danlan/vo/*.hbm.xml </value>
</property>