SSH整合中sessionFactory创建失败问题

Error creating beanwith name 'sessionFactory' defined in class path resource [bean.xml]

must specify an identifier type

  •  Invocation of init method failed; nestedexception is org.hibernate.boot.MappingException: must specify an identifier type:cn.shash.shop.order.vo.OrderItem : origin(null)


    Causedby: org.hibernate.boot.MappingException: must specify an identifier type: cn.shash.shop.order.vo.OrderItem :origin(null)

    at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindSimpleEntityIdentifier(ModelBinder.java:707)

    at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindEntityIdentifier(ModelBinder.java:342)

    at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindRootEntity(ModelBinder.java:237)

    at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindEntityHierarchy(ModelBinder.java:184)

    从中可以看出错误根本原因是Hibernate的实体映射文件配置出错,并指出出错的映射文件,本人出现错误如图SSH整合中sessionFactory创建失败问题_第1张图片原因是没有配置name属性,column属性在省略的情况下默认与name属性值一样,但name属性是不能省略的解决办法就是配置上name属性就可以 ;在这里因为dao继承了HibrenateDaoSupport所以SessionFactory可以直接使用;不需要再显式注入

  • Invalid property 'sessionFactory' of bean


Causedby:org.springframework.beans.NotWritablePropertyException: Invalidproperty 'sessionFactory' of bean class [cn.shash.shop.adminuser.vo.AdminUser]:Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of thegetter?

   atorg.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:231)

   atorg.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:423)

   atorg.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280)

   atorg.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)

   atorg.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)

   atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)


原因 此处类的全路径写错

   <bean id="adminUserDao" class="cn.shash.shop.adminuser.vo.AdminUser">

      <property name="sessionFactory" ref="sessionFactory">property>

   bean >

解决:修改类的全路径

Dao已经继承HibernateDaoSupport 所以只需在在配置文件中进行配置即可 不需要在dao中再写get set方法

该路径名为:

   <bean id="adminUserDao" class="cn.shash.shop.adminuser.dao.AdminUserDao">

      <property name="sessionFactory" ref="sessionFactory">property>

   bean >


你可能感兴趣的:(JavaEE)