hibernate配置文件错误 BasUserInfo is not mapped [from BasUserInfo]

htc2gg 2013-01-24 07:15:22

hibernate的cfg文件如下:
<session-factory>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="hibernate.connection.url">
jdbc:sqlserver://172.16.4.252:1433;databasename=CemsCenter
<!--jdbc:MySQL://172.16.4.187:3306/overtime-->
</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">123</property>
<!-- <property name="connection.driver_class">
org.gjt.mm.mysql.Driver
</property>-->

<property name="hibernate.connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
<!--com.mysql.jdbc.Driver-->
</property>
<!-- C3P0连接池设定-->

<!-- <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider
</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.timeout">120</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">120</property>
<property name="hibernate.c3p0.acquire_increment">2</property> -->

<property name="myeclipse.connection.profile">
sqlServer
</property>

<property name="show_sql">true</property>
<mapping resource="testDao/BasUserInfo.hbm.xml" />

</session-factory>



hibernate的hbm文件如下:
<hibernate-mapping>
<class name="testDao.BasUserInfo" table="Bas_UserInfo" schema="dbo" >
<id name="id" type="java.lang.String">
<column name="ID" length="36" />
<generator class="native" />
</id>
<property name="account" type="java.lang.String">
<column name="Account" />
</property>
<property name="userName" type="java.lang.String">
<column name="UserName" />
</property>
<property name="pwd" type="java.lang.String">
<column name="PWD" />
</property>
<property name="roleId" type="java.lang.String">
<column name="RoleID" />
</property>
<property name="email" type="java.lang.String">
<column name="EMail" />
</property>
<property name="del" type="java.lang.Short">
<column name="Del" />
</property>
</class>
</hibernate-mapping>



java类如下:
public class BasUserInfo implements java.io.Serializable
{

// Fields

private String id;
private String account;
private String userName;
private String pwd;
private String roleId;
private String email;
private Short del;

// Constructors

/** default constructor */
public BasUserInfo()
{
}

/** minimal constructor */
public BasUserInfo(String id, String account, String pwd)
{
this.id = id;
this.account = account;
this.pwd = pwd;
}

/** full constructor */
public BasUserInfo(String id, String account, String userName, String pwd, String roleId, String email, Short del)
{
this.id = id;
this.account = account;
this.userName = userName;
this.pwd = pwd;
this.roleId = roleId;
this.email = email;
this.del = del;
}

// Property accessors

public String getId()
{
return this.id;
}

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

public String getAccount()
{
return this.account;
}

public void setAccount(String account)
{
this.account = account;
}

public String getUserName()
{
return this.userName;
}

public void setUserName(String userName)
{
this.userName = userName;
}

public String getPwd()
{
return this.pwd;
}

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

public String getRoleId()
{
return this.roleId;
}

public void setRoleId(String roleId)
{
this.roleId = roleId;
}

public String getEmail()
{
return this.email;
}

public void setEmail(String email)
{
this.email = email;
}

public Short getDel()
{
return this.del;
}

public void setDel(Short del)
{
this.del = del;
}
}


错误代码如下:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: BasUserInfo is not mapped [from BasUserInfo]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.sdl.dao.HisData.test.main(test.java:47)

各位大侠们 急啊 这问题太奇怪了 我明明映射了hbm文件啊 它怎么会报这个错误呢?
...全文
168 9 点赞 打赏 收藏 举报
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
christopher_19 2013-01-31
引用 8 楼 javawebcza 的回复:
引用 7 楼 zsmj0713 的回复:Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: BasUserInfo is not mapped [from BasUserInfo] 这句话是关键,如果你是用的hql的话,在你的sql语句应该写Statement stmt=stmtF……
都报了BasUserInfo is not mapped竟然还说是hql有问题....再看看最初抛出的at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)。 requireClassPersister 就是缺少持久化类啊 可能是BasUserInfo.hbm.xml,BasUserInfo.java没放一起吧
  • 打赏
  • 举报
回复
javawebcza 2013-01-30
引用 7 楼 zsmj0713 的回复:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: BasUserInfo is not mapped [from BasUserInfo] 这句话是关键,如果你是用的hql的话,在你的sql语句应该写Statement stmt=stmtFactory.createStateme……
非常赞同,明显是 执行hql时候出现了问题,应该是 hql语句的问题
  • 打赏
  • 举报
回复
茜茜你好坏 2013-01-30
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: BasUserInfo is not mapped [from BasUserInfo] 这句话是关键,如果你是用的hql的话,在你的sql语句应该写Statement stmt=stmtFactory.createStatement("from BasUserInfo","where"); from后面接的是实体类名,还有BasUserInfo.hbm.xml,BasUserInfo.java这两个配置文件最好放在一起,在实体类那个包里
  • 打赏
  • 举报
回复
brightyq 2013-01-24
看一下 BasUserInfo.hbm.xml , BasUserInfo.java 两个相对位置对不对。 可能你的BasUserInfo.hbm.xml放错地方了。
  • 打赏
  • 举报
回复
沉默滴狼 2013-01-24
// Fields private String id; private String account; private String userName; Id 没指定主键生成方式 没标明 id为主键 : 如@Id @GeneratorValue(...) ; 实体类 上面 没加上 @Entity
  • 打赏
  • 举报
回复
沉默滴狼 2013-01-24
没看上面的代码 一看错误提示 凭我个人经验 是因为SQL写错了 from 后面的那个名字要大写 或者 此类映射错误
  • 打赏
  • 举报
回复
htc2gg 2013-01-24
个位高手们想想办法啊 一个晚上没研究出来
  • 打赏
  • 举报
回复
htc2gg 2013-01-24
只用到hibernate了啊
  • 打赏
  • 举报
回复
bufan_888 2013-01-24
看看TOMCAT中有没有这个实体类
  • 打赏
  • 举报
回复
相关推荐
发帖
Java EE
加入

6.7w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2013-01-24 07:15
社区公告
暂无公告