前几天用AnnotationSessionFactoryBean 注解方式代替*.hbm.xml时扫描映射实休文件后报错

吐操一下.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的扩展

前几天用注解方式代替*.hbm.xml时扫描映射文件的方法


报错如下:       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>


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值