0

错误信息: Book is not mapped [select b.price FROM Book b WHERE b.isbn=?]
实体类:

public class Account {

    private Integer id;
    private String username;
    private int balance;

    public Integer getId() {
        return id;
    }

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

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getBalance() {
        return balance;
    }

    public void setBalance(int balance) {
        this.balance = balance;
    }

}
public class Book {

    private Integer id;
    private String bookName;
    private String isbn;
    private int price;
    private int stock;

    public Integer getId() {
        return id;
    }

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

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getIsbn() {
        return isbn;
    }

    public void setIsbn(String isbn) {
        this.isbn = isbn;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

}```
表的格式:
create table `SH_ACCOUNT`(`ID` int(20),`USERNAME` varchar(20),`BALANCE` int(20))

create table `sh_book`(`ID` int(20),`BOOK_NAME` varchar(20),`ISBN` varchar(20),`PRICE` int(20),`stock` int(20))


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.sh.entities.Account" table="SH_ACCOUNT">

        <id name="id" type="java.lang.Integer">
            <column name="ID" />
            <generator class="native" />
        </id>

        <property name="username" type="java.lang.String">
            <column name="USERNAME" />
        </property>

        <property name="balance" type="int">
            <column name="BALANCE" />
        </property>

    </class>
</hibernate-mapping>



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.sh.entities.Book" table="SH_BOOK">

        <id name="id" type="java.lang.Integer">
            <column name="ID" />
        </id>

        <property name="bookName" type="java.lang.String">
            <column name="BOOK_NAME" />
        </property>

        <property name="isbn" type="java.lang.String">
            <column name="ISBN" />
        </property>

        <property name="price" type="int">
            <column name="PRICE" />
        </property>

        <property name="stock" type="int">
            <column name="STOCK" />
        </property>

    </class>
</hibernate-mapping>

为什么会映射不了呢?

撰写答案