Hibernate 继承表结构
有Product , Book ,Clothes三张表
Product:id,name
Book: id ,name,pageCount
Clothes: id ,name ,size
创建三张表
产品表
create table product(
id number(2) primary key,
name varchar2(10)
);
书表
create table booktbl(
id number(2) ,
name varchar2(10),
pageCount number(3),
foreign key(id) references product(id)
);
create sequence book_seq
increment by 1
start with 1
nomaxvalue nominvalue nocache; CREATE TRIGGER book_trigger BEFORE
INSERT ON booktbl FOR EACH ROW WHEN(new.id is null)
begin
select book_seq.nextval into:new.id from dual;
end; drop table booktbl;
drop sequence book_seq;
brop trigger book_trigger; 服装表
create table clothestbl(
id number(2) references product(id),
name varchar2(10),
closize number(5)
); create sequence clothes_seq
increment by 1
start with 1
nomaxvalue nominvalue nocache; CREATE TRIGGER clo_trigger
before
INSERT ON clothestbl
FOR EACH ROW
WHEN(new.id is null)
begin
select clothes_seq.nextval into:new.id from dual;
end; drop table clothestbl;
drop sequence clothes_seq;
brop trigger clo_trigger;
Product.hlm.xml
<class name="com.amaker.extendmodel.Product" table="Product">
<id name="id">
<generator class="native"></generator>
</id>
<property name="name"></property> <joined-subclass name="com.amaker.extendmodel.Book" table="booktbl">
<key column="id"></key>
<property name="pageCount"></property>
</joined-subclass> <joined-subclass name="com.amaker.extendmodel.Clothes" table="clothestbl">
<key column="id"></key>
<property name="size" column="closize"></property>
</joined-subclass>
</class>
<mapping resource="com/amaker/extendmodel/Product.hbm.xml"/>
Hibernate 继承表结构的更多相关文章
- Hibernate笔记——表的的4种继承关系
原文:http://justsee.iteye.com/blog/1070588 ===================================== 一.继承关系_整个继承树映射到一张表 对象 ...
- 为什么要用hibernate 与基于数据库表结构的项目开发
最近开始学习hibernate,其实并不知道要学习什么,有什么用.后来问了一下同事,他就说快捷方便简单,很多事情不用自己做他会帮你做好,但是我觉得不应该是这样的,于是我就去搜了一下,就搜到了一篇帖子, ...
- Hibernate之SchemaExport+配置文件生成表结构
首先要生成表,得先有实体类,以Person.java为例: /** * * @author Administrator * @hibernate.class table="T_Person& ...
- 菜鸟学SSH(十一)——Hibernate之SchemaExport+配置文件生成表结构
今天说点基础的东西,说说怎样通过SchemaExport跟Hibernate的配置文件生成表结构.事实上方法很easy,仅仅须要两个配置文件,两个Java类就能够完毕. 首先要生成表,得先有实体类,以 ...
- 菜鸟学SSH(十二)——Hibernate与Spring配合生成表结构
前几天向大家介绍了一种用工具类生成数据表的方法,只是之前的方法须要使用一个跟项目关系不大的工具类.不免让人认为有些多余,所以呢.今天再向大家介绍一种方法.即Hibernate与Spring配合生成表结 ...
- Hibernate由model类自动同步数据库表结构
在开发中遇到了个问题,每次测试数据库增加表结构的时候,本地pull下最新代码导致启动报错,上网搜了快速解决办法---->hibernate 配置属性中,hibernate.hbm2ddl.aut ...
- Hibernate使用自定义脚本替换注解或者xml文件中的自动生成表结构
本文作者:苏生米沿 本文地址:http://blog.csdn.net/sushengmiyan/article/details/50534361 我们都清楚,可以使用hibernate的metada ...
- hibernate.hbm2ddl.auto=update不能自动生成表结构
在写上篇文章<spring整合springmvc和hibernate>的时候,曾遇到一个问题 INFO: Server startup in 8102 ms Hibernate: inse ...
- Hibernate中:不看数据库,不看XML文件,不看查询语句,怎么样能知道表结构?
Hibernate中:不看数据库,不看XML文件,不看查询语句,怎么样能知道表结构? 解答:可以看与XML文件对应的域模型.
随机推荐
- html5 之本地数据存储
HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 session 的数据存储 cookie与webSt ...
- HDU 3691 Nubulsa Expo
无向图的最小割.套了个模板. #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- storm的并发
1 storm并行的基本概念 storm集群中的一个机器可以运行一个或者多个worker,对应于一个或者多个topologies. 1个worker进程运行1个或多个excutor线程.每个worke ...
- meta--------link
<meta http-equiv="refresh" content="20">//每二十秒刷新一次页面: <meta http-equiv= ...
- Ubuntu里字符编码设置
Ubuntu里字符编码设置 Ubuntu系统在默认的状况下只支持中文UTF-8编码,但是我们写的一些文档,还有java代码编译时采用gbk编码.所以需要修改.步骤如下: www.2cto.com ...
- a href="javascript:void(0)" 是什么意思?加不加上有什么区别?
<A href="javascript:void(0)">点击</a>点击链接后不会回到网页顶部<A href="#">点击 ...
- postgres 错误duplicate key value violates unique constraint 解决方案
SELECT setval('tablename_id_seq', (SELECT MAX(id) FROM tablename)+1) 主要是:serial key其实是由sequence实现的,当 ...
- 转 windows 下 Oracle 导出表结构
分析Oracle下导出某用户所有表的方法 可能很多使用Oracle的客户都会遇到想把某用户所有表导出的情况,本文就提供这样一个方法帮你轻松解决这个问题. 首先在sqlplus下以该用户登录到Ora ...
- PAT (Advanced Level) 1091. Acute Stroke (30)
BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...
- Properties 使用,注意编码
private static void setConfig(){ try { // String path = System.getProperty("user.dir") + & ...