一下是我写的一个类,该类通过读取configur.xml文件来生成相应的数据表结构,但是在运行的时候一切正常,后台无任何错误,但是Oracle中依旧无法成功的把表创建出来。
package com.shop.dao;
import java.io.File;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class HibernateSchemaExport{
static Session session;
static Configuration config = null;
static Transaction tx = null;
public static void main(String[] args){
/** *//**
* 根据映射文件创建数据库结构
*/
try {
config = new Configuration().configure(new File("src/hibernate.cfg.xml"));
System.out.println("Creating tables...");
SessionFactory sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
tx = session.beginTransaction();
SchemaExport schemaExport = new SchemaExport(config);
schemaExport.create(true, true);
System.out.println("Table created....");
tx.commit();
} catch (HibernateException e){
e.printStackTrace();
try{
tx.rollback();
} catch (HibernateException e1){
e1.printStackTrace();
}
} finally{
session.close();
}
}
}
程序运行完以后,console台的------
Creating tables...
drop table shop.dbo.customer cascade constraints
drop table shop.dbo.orderDetail cascade constraints
drop table shop.dbo.orders cascade constraints
drop table shop.dbo.shop cascade constraints
drop sequence hibernate_sequence
create table shop.dbo.customer (customerid number(10,0) not null, customername varchar2(20 char), primary key (customerid))
create table shop.dbo.orderDetail (orderDetailId number(10,0) not null, shopid number(10,0), orderNum number(10,0), primary key (orderDetailId))
create table shop.dbo.orders (orderid number(10,0) not null, customerid number(10,0), orderdate timestamp, ordertotal float, primary key (orderid))
create table shop.dbo.shop (shopid number(10,0) not null, shopname varchar2(20 char), shopprice float, primary key (shopid))
alter table shop.dbo.orderDetail add constraint FK46C5593FE1CF842F foreign key (shopid) references shop.dbo.shop
alter table shop.dbo.orders add constraint FKC3DF62E5A2CD9FFF foreign key (customerid) references shop.dbo.customer
create sequence hibernate_sequence
Table created.
我用的数据库是Oracle9i,为什么我的表没有创建成功。。。