新手一个Hibernate奇怪的错误
报告错误:book is not mapped. [from book]
数据库MSSQL Server 2005
Book.java
package com.yourcompany;
public class Book implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
private String id;
private String bookName;
public String getid()
{
return id;
}
public void setid(String id)
{
this.id=id;
}
public String getbookName()
{
return bookName;
}
public void setbookName(String bookname)
{
this.bookName=bookname;
}
}
数据表
CREATE TABLE [dbo].[book]
(
[id] [varchar](36) NOT NULL,
[book_name] [varchar](110) NOT NULL
) ON [PRIMARY]
hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">sa</property>
<property name="connection.url">jdbc:sqlserver://localhost</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="myeclipse.connection.profile">Micrsoft SQL Server 2005</property>
<property name="connection.password">xxxxxxxxxx</property>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<mapping resource="com/yourcompany/Book.hbm.xml" />
</session-factory>
</hibernate-configuration>
映射配置
Book.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.yourcompany.Book" table="book" schema="dbo" catalog="Test">
<id name="id" type="string">
<column name="id" length="36" />
<generator class="uuid.hex"/>
</id>
<property name="bookName" type="string">
<column name="book_name" length="110" />
</property>
</class>
</hibernate-mapping>