Hibernate - 不成功:创建表

时间:2014-07-21 07:13:22

标签: java database hibernate intellij-12

当我创建hibernate数据库时,Hibernate会识别除一个表之外的所有表。所以,当我尝试在那里保存一些东西时,我得到一个异常,因为该对象不存在。 无法创建的表是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>

此外,如果它有用,则错误:

  

jul 21,2014 4:04:45 am org.apache.catalina.core.AprLifecycleListener   init WARN:遇到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,deliver boolean,   order_price float,address_id double,user_id double,主键   (order_id))jul 21,2014 4:05:15 AM   org.hibernate.tool.hbm2ddl.SchemaUpdate执行错误:palabra no   esperado:订购2014年7月21日上午4:05:15   org.hibernate.tool.hbm2ddl.SchemaUpdate执行错误:HHH000388:   不成功:alter table INORDER添加约束FK9F407529258ABBD5   外键(order_id)引用ORDER jul 21,2014 4:05:15 AM   org.hibernate.tool.hbm2ddl.SchemaUpdate执行错误:palabra no   esperado:订购2014年7月21日上午4:05:15   org.hibernate.tool.hbm2ddl.SchemaUpdate执行错误:HHH000388:   不成功:alter table ORDER添加约束FK47F8F2E1433E755   外键(address_id)引用ADDRESS 2014年7月21日上午4:05:15   org.hibernate.tool.hbm2ddl.SchemaUpdate执行错误:usuario no   tiene privilegios suficientes o objeto no encontrado:PUBLIC.ORDER jul   21,2014 4:05:15 AM org.hibernate.tool.hbm2ddl.SchemaUpdate执行   错误:HHH000388:不成功:alter table ORDER add constraint   FK47F8F2E858D485F外键(user_id)引用CLIENT 2014年7月21日   上午4:05:15 org.hibernate.tool.hbm2ddl.SchemaUpdate执行错误:   usuario no tiene privilegios suficientes o objeto no encontrado:   PUBLIC.ORDER 2014年7月21日上午4:05:15   org.hibernate.tool.hbm2ddl.SchemaUpdate执行WARN:SQL错误:   -5501,SQLState:42501 jul 21,2014 4:05:17 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions错误:   usuario no tiene privilegios suficientes o objeto no encontrado:ORDER

0 个答案:

没有答案