用注释的方式映射hibernate,报is not mapped

J2EE 码拜 9年前 (2015-04-10) 927次浏览 0个评论
 

报了org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]

package com.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = “t_user”)
public class User {
private int id;
private String name;
private String pwd;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPwd() {
return pwd;
}

public void setPwd(String pwd) {
this.pwd = pwd;
}
}

用注释的方式映射hibernate,报is not mapped
20分
得要让Hibernate的SessionFactory扫到注解的实体啊

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="packagesToScan" value="认真看这里" />
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.show_sql">false</prop>
				<prop key="hibernate.format_sql">false</prop>
				<prop key="hibernate.use_sql_comments">false</prop>
				<prop key="hibernate.max_fetch_depth">2</prop>
				<prop key="hibernate.jdbc.batch_size">100</prop>
				<prop key="hibernate.query.substitutions">true 1, false 0</prop>
				<prop key="hibernate.connection.SetBigStringTryClob">true</prop>
				<prop key="javax.persistence.validation.mode">none</prop>
			</props>
		</property>
	</bean>

另外,你没有配@Id啊,其余的两个字符串也得配上长度吧。

用注释的方式映射hibernate,报is not mapped
楼上说的对, packagesToScan 要包含你的实体类包  
用注释的方式映射hibernate,报is not mapped
没配置好实体映射文件哦
用注释的方式映射hibernate,报is not mapped
20分
出现这中错误可能有以下两种原因:
1:配置文件没有被加载到hibernate的实体列表里面。
2:映射文件的字段与数据库字段不一致,或者名称不一致导致。
用注释的方式映射hibernate,报is not mapped
1楼说的对,配置文件需要映射到实体类

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明用注释的方式映射hibernate,报is not mapped
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!