Hibernate注解加载实体类文件 50
没有Hibernate配置文件,交由Spring配置文件管理!加上Hibernate注解后,怎么加载实体的JAVA文件啊?我这样定义的。<beanid="sessionF...
没有Hibernate配置文件,交由Spring配置文件管理! 加上Hibernate注解后,怎么加载实体的JAVA文件啊?
我这样定义的。
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.formate_sql">true</prop>
</props>
</property>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="Gameen" ref="Gameentity" />
</bean>
<bean id="Gameentity" class="baby.entity.Gameentity" />
上面的 <property name="Gameentity" ref="Gameentity" />就抱错Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
请问是哪里的问题? 请指点下,谢谢
2011-03-12 08:59:22 Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Gameen' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'Gameen' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.NotWritablePropertyException: Invalid property 'Gameen' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'Gameen' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:793) 展开
我这样定义的。
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.formate_sql">true</prop>
</props>
</property>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="Gameen" ref="Gameentity" />
</bean>
<bean id="Gameentity" class="baby.entity.Gameentity" />
上面的 <property name="Gameentity" ref="Gameentity" />就抱错Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
请问是哪里的问题? 请指点下,谢谢
2011-03-12 08:59:22 Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Gameen' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'Gameen' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.NotWritablePropertyException: Invalid property 'Gameen' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'Gameen' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:793) 展开
4个回答
推荐于2016-09-27 · 知道合伙人互联网行家
关注
展开全部
注解加载实体类文件代码如下:
package com.bird.user.entity;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
@Entity
@Table(name = "user")
public class User {
private int id ;
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
如果不用注解 ,需要在spring.xml中增加如下代码。
<property name="mappingResources">
<list>
<value>com/bird/user/entity/User.hbm.xml</value>
</list>
</property>
展开全部
看的我头痛眼花,不过我可以指点你下,你用的注解是吧?那么请问你的配置文件里面有没有引进注解需要的各种头文件:
xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
<context:annotation-config/>
还有你的命名,你的springconfg里面配置的bean名称要和你的action里面的名称一样,假如你配置的dao或者是service、那么就要实现借口。在action里面应是写借口,因为spring是面试借口编程的。
xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
<context:annotation-config/>
还有你的命名,你的springconfg里面配置的bean名称要和你的action里面的名称一样,假如你配置的dao或者是service、那么就要实现借口。在action里面应是写借口,因为spring是面试借口编程的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sessionFactoty这个bean配置有错误? 数据源的配置能不能贴出来看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
去掉
<bean id="Gameentity" class="baby.entity.Gameentity" />
配置文件修改如下:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties" ref="hibernateProperties" />
<property name="packagesToScan" value="baby/entity/"></property>//关键是这句
</bean>
<bean id="Gameentity" class="baby.entity.Gameentity" />
配置文件修改如下:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties" ref="hibernateProperties" />
<property name="packagesToScan" value="baby/entity/"></property>//关键是这句
</bean>
追问
//关键是这句
这句啥意思 定义包下?
追答
意思是把此路径下的所有bean都是自动扫描加载进来,方便后续操作
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询