Hibernate component mapping
A Component is a containted object that is be persisted value type and not an entity.But you can embed the component to entity.
Now We need one-to-one association for husband an wife. We just let the in one table. Then we create one entity, on component.
such as this:
Entity Husband:
@Entity
public class Husband {
private int id;
private String name;
private Wife wife;
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Embedded
public Wife getWife() {
return wife;
}
public void setWife(Wife wife) {
this.wife = wife;
}
}
Component Wife:
public class Wife {
private String wifeName;
private int wifeAge;
public String getWifeName() {
return wifeName;
}
public void setWifeName(String wifeName) {
this.wifeName = wifeName;
}
public int getWifeAge() {
return wifeAge;
}
public void setWifeAge(int wifeAge) {
this.wifeAge = wifeAge;
}
}
We embed the component wife in entity Husband by @Embedded, So we get only one table named Hunband:
create table Husband (
id integer not null auto_increment,
name varchar(255),
wifeAge integer not null,
wifeName varchar(255),
primary key (id)
)
So, Use component can make our program structual more clear in logic.
Hibernate component mapping的更多相关文章
- Eclipse报错An internal error occurred during: "J2EE Component Mapping Update". java.lang.NullPointerException
Eclipse每次打开.java文件时,报错信息如下: An internal error occurred during: "J2EE Component Mapping Update&q ...
- An internal error occurred during: "J2EE Component Mapping Update".
1.错误描写叙述 An internal error occurred during: "J2EE Component Mapping Update". java.lang.Nul ...
- Hibernate 之 Mapping
转自: http://blog.csdn.net/jnqqls/article/details/8372732 从前面的介绍的Hibernate文章中我们已经对Hibernate有了一个初步的认识, ...
- hibernate hibernate.cfg.xml component 组件
1.为什么使用component组件? 当一个表的列数目比较多时,可以根据属性分类,将一个java对象拆分为几个对象. 数据库还是一张表,不过有多个对象与之对应. 2.实例 2.1 Java 对象: ...
- Hibernate对象映射类型
Hibernate understands both the Java and JDBC representations of application data. The ability to rea ...
- Hibernate学习笔记3.2(Hibernate组建映射)
1.组建映射 可以存在一个表里面 Husband.java package com.bjsxt.hibernate; import javax.persistence.Embedded; import ...
- hibernate之单表映射
目录 第一章 Hibernate初识 1-1 课程介绍 1-2 什么是ORM 1-3 Hibnerate简介 1-4 开发前的准备 1-5 编写第一个Hibernate例子 1-6 创建hiberna ...
- hibernate 注解大全
2019年5月1日21:39:55 原文:http://docs.jboss.org/hibernate/orm/5.4/javadocs/ 这个是hibernate 5.4版本 基于hibernat ...
- java学习:Hibernate入门
相对微软的linq-to-sql或EF框架而言,"Hibernate对于eclipse的集成开发“ 新手并不容易掌握,下面是新手上路的步骤: 一.准备工作: 1.先下载eclipse (官网 ...
随机推荐
- 【经验】ansible 批量推送公钥
1.使用 ssh-keygen -t rsa生成密钥对 ssh-keygen -t rsa 2.推送单个公钥到远程机器 格式: ssh-copy-id -i ~/.ssh/id_rsa.pub use ...
- python 正则re模块
re.match re.match 尝试从字符串的开始匹配一个模式,如:下面的例子匹配第一个单词. import re text = "JGood is a handsome boy, he ...
- RVM 多版本Ruby管理-Gentoo
发现了一个非常Amzaing的Ruby的工具RVM,用于安装和管理Ruby的多个版本.相比较于直接在系统中安装不同版本的Ruby,然后使用时切换到对应的版本,这种方式实在是酷毙了,使ruby安装变得非 ...
- B-tree
2-3 Tree 二叉搜索树的每个节点只带有一个值,这个值将数据区间划分成两部分,值左边的部分(也就是小于这个值的数据)保存到节点的左子树,值右边的部分保存到节点的右子树.因此,每个非叶子节最多能够拥 ...
- 使用cookie实现打印浏览记录的功能
可以用cookie知识来实现打印浏览记录.这里面用到的思路是将浏览记录以字符串的方式保存到cookie中,当浏览记录增加时,再将其转化为数组. $uri=$_SERVER['REQUEST_URI'] ...
- iOS通过手势拿到当前的View
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(t ...
- OpenCV linux cmake添加使用
安装好opencv之后: 只需要添加一下,就可以方便的使用opencv了,find_package opencv 会寻找FindOpenCV.cmake find_package(OpenCV REQ ...
- vertx简单客户端创建
import java.util.HashMap;import java.util.Map; import com.yunva.vertx.test.vertproject.util.JsonUtil ...
- Ext开场表单布局设计
var form = new Ext.form.FormPanel({ labelAlign: 'right', labelWidth: 60, buttonAlign: 'center', titl ...
- ZooKeeper事务日志记录器SyncRequestProcessor
SyncRequestProcessor作为一个ZooKeeper中的一个关键线程(ZooKeeperCriticalThread),是ZooKeeper请求处理链中的事务日志记录处理器,其主要用来将 ...