Hibernate Oracle 11g 无法自动生成表

用HIbernate+Oracle整合的时候遇到了一个问题,运行Main方法的时候不报错,也没有任何的提示信息,但是却无法创建表。

public static void main(String[] args) {
		Configuration cfg = new Configuration();
		cfg.configure();
		SessionFactory sessionFactory = cfg.buildSessionFactory();
		Session session = sessionFactory.openSession();
		System.out.println(session.isConnected());
		Transaction tx = session.beginTransaction();
		tx.begin();
		User user = new User();
		user.setAge(10);
		user.setBirthday(new Date());
		user.setSex("man");
		user.setUsername("Jone");
		tx.commit();
		session.close();
		System.out.println("success");
		
	}
相关配置文件如下:


hibernate.cfg.xml


<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
	<hibernate-configuration>
	    <session-factory name="hibernate_oracle">
	        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
	        <property name="hibernate.connection.username">simplelove</property>
	        <property name="hibernate.connection.password">123456</property>
	        <property name="hibernate.hbm2ddl.auto">update</property>
	        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521/app</property>
	        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
	        <property name="hibernate.show_sql">true</property>
	        
	        <mapping resource="com/myHibernate/domain/hbm/User.hbm.xml"/>
	    </session-factory>
	</hibernate-configuration>

User.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">
	<hibernate-mapping package="com.myHibernate.domain">
	    <class name="User" table="User">
	        <id name="id">
	            <generator class="native"></generator>
	        </id>
	        <property name="username"></property>
	        <property name="sex"></property>
	        <property name="age"></property>
	        <property name="birthday"></property>
	    </class>
	</hibernate-mapping>

仔细重复的查看配置文件,没有错误。检查账户权限,拥有所有权限。而且能够链接上数据库,就是无法创建表。后来Google一大圈之后,看到有一篇帖子说“Oracle数据库中,一个数据库下可以有多个表空间,多个用户可以有不同的表空间,如果用户A的表空间中已经存在table1,则使用如上方式在用户B的表空间再自动创建table1是不行的。”然后回头一看,我定义的表名就叫 User,这个名字太普通了,Oracle数据库中已经存在这张表了。把表名改了一下就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值