hibernate连接oracle10g配置

首先配置映射文件,命名为:className(定义的类名).hbm.xml;配置示例如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
		"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.test">
	<class name="News" table="news_table">
		<id name="id" unsaved-value="null">
			<generator class="native"/>////1111
		</id>
		<property name="title"/>
		<property name="content"/>
	</class>
</hibernate-mapping>
特别提醒标号1111的地方,class不能为identify,因为oracle不支持。

配置hibernate.cfg.xml,示例如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--  -->
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate configuration DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
	<property name="hibernate.connection.driver_class">
		oracle.jdbc.OracleDriver
	</property>
	<property name="hibernate.connection.url">
		jdbc:oracle:thin:@localhost:1521:orcl
	</property>
	<property name="hibernate.dialect">
		org.hibernate.dialect.Oracle10gDialect
	</property>  
	<property name="hibernate.connection.username">scott</property>
	<property name="hibernate.connection.password">tiger</property>

	<property name="hbm2ddl.auto">create</property>//2222///
	<property name="c3p0.min_size">1</property>
	<property name="c3p0.max_size">30</property>
	<property name="c3p0.time_out">1800</property>
	<property name="c3p0.max_statement">50</property> 
	<mapping resource="News.hbm.xml" />
</session-factory>
</hibernate-configuration>
在第一次运行程序的时候标示2222的地方可以写create,还有其他值可选,如下:

validate               加载hibernate时,验证创建数据库表结构
create                  每次加载hibernate,重新创建数据库表结构,这就是导致数据库表数据丢失的原因。
create-drop        加载hibernate时创建,退出是删除表结构
update                 加载hibernate自动更新数据库结构

从解释可以明白,如果值一直是create的话,那么每次执行,表中只有一行数据,是因为先前加入的数据的表已被删除,每次执行都是新建表,

所以建议在执行了第一次后把制改为validate。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值