0

当我创建休眠数据库时,休眠识别除了一个之外的所有表。所以,当我尝试在那里保存一些东西时,我得到一个异常,因为该对象不存在。创建失败的表是 ORDER。这是代码:

@Entity
@Table(name = "ORDER")
public class Order implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    @Column(name = "order_id")
    private double order_id;
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinTable(name = "INORDER", joinColumns = {@JoinColumn(name = "order_id")}, inverseJoinColumns = {
            @JoinColumn(name = "item_id")})
    private List<Item> items;
    @Column(name = "delivered")
    private boolean delivered;
    @Column(name = "current_date")
    private Date current_date;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private Client client;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "address_id")
    private Address address;
    @Column(name = "order_price")
    private float order_price;

    public Order() {

    }

    public Order(Client client, Address address, float order_price, List<Item> items) {
        this.client = client;
        this.address = address;
        this.order_price = order_price;
        this.items = items;
        current_date = new Date();
        delivered = false;
    }

    public double getOrder_id() {
        return order_id;
    }

    public List<Item> getItems() {
        return items;
    }

    public boolean isDelivered() {
        return delivered;
    }

    public void confirmDelivery() {
        delivered = true;
    }

    public Date getCurrent_date() {
        return current_date;
    }

    public Client getClient() {
        return client;
    }

    public Address getAddress() {
        return address;
    }


    public float getOrder_price() {
        return order_price;
    }
}

和 hibernate.cfg.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:hsql://localhost/onlineShop</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>


        <!-- database pooling information -->
        <property name="connection_provider_class">org.hibernate.connection.C3P0ConnectionProvider
        </property>
        <property name="c3p0.minPoolSize">5</property>
        <property name="c3p0.timeout">1000</property>

        <!-- using container-managed JNDI
        <property name="hibernate.connection.datasource">
           java:comp/env/jdbc/LiveDataSource
        </property>   -->


        <property name="hibernate.connection.CharSet">utf8</property>
        <property name="hibernate.connection.characterEncoding">utf8</property>
        <property name="hibernate.connection.useUnicode">true</property>



        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <property name="hibernate.hbm2ddl.auto">update</property>

        <mapping class="model.Address"/>
        <mapping class="model.Admin"/>
        <mapping class="model.Order"/>
        <mapping class="model.Brand"/>
        <mapping class="model.Client"/>
        <mapping class="model.GenericItem"/>
        <mapping class="model.Item"/>
        <mapping class="model.User"/>

    </session-factory>
</hibernate-configuration>

此外,如果它有帮助,错误:

2014 年 7 月 21 日上午 4:04:45 org.apache.catalina.core.AprLifecycleListener init 警告:HHH000022:遇到 c3p0 属性,但找不到 org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider 提供程序类类路径;这些属性将被忽略。2014 年 7 月 21 日上午 4:05:14 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl 配置错误:HHH000388:不成功:创建表 ORDER(order_id double not null,current_date timestamp,delivered boolean,order_price float,address_id double , user_id double, 主键 (order_id)) 2014 年 7 月 21 日上午 4:05:15 org.hibernate.tool.hbm2ddl.SchemaUpdate 执行错误:palabra no esperado: ORDER jul 21, 2014 4:05:15 AM org.hibernate .tool.hbm2ddl.SchemaUpdate 执行错误:HHH000388:不成功:

4

0 回答 0