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的更多相关文章

  1. 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 ...

  2. An internal error occurred during: "J2EE Component Mapping Update".

    1.错误描写叙述 An internal error occurred during: "J2EE Component Mapping Update". java.lang.Nul ...

  3. Hibernate 之 Mapping

    转自:  http://blog.csdn.net/jnqqls/article/details/8372732 从前面的介绍的Hibernate文章中我们已经对Hibernate有了一个初步的认识, ...

  4. hibernate hibernate.cfg.xml component 组件

    1.为什么使用component组件? 当一个表的列数目比较多时,可以根据属性分类,将一个java对象拆分为几个对象. 数据库还是一张表,不过有多个对象与之对应. 2.实例 2.1 Java 对象: ...

  5. Hibernate对象映射类型

    Hibernate understands both the Java and JDBC representations of application data. The ability to rea ...

  6. Hibernate学习笔记3.2(Hibernate组建映射)

    1.组建映射 可以存在一个表里面 Husband.java package com.bjsxt.hibernate; import javax.persistence.Embedded; import ...

  7. hibernate之单表映射

    目录 第一章 Hibernate初识 1-1 课程介绍 1-2 什么是ORM 1-3 Hibnerate简介 1-4 开发前的准备 1-5 编写第一个Hibernate例子 1-6 创建hiberna ...

  8. hibernate 注解大全

    2019年5月1日21:39:55 原文:http://docs.jboss.org/hibernate/orm/5.4/javadocs/ 这个是hibernate 5.4版本 基于hibernat ...

  9. java学习:Hibernate入门

    相对微软的linq-to-sql或EF框架而言,"Hibernate对于eclipse的集成开发“ 新手并不容易掌握,下面是新手上路的步骤: 一.准备工作: 1.先下载eclipse (官网 ...

随机推荐

  1. SQL2008安装提示"Microsoft visual studio 2008早期之前的版本

    打开注册表管理器(运行 --regedit 依次展开如下项目:   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv 将devdiv项目导出来保存,倒出来之后可 ...

  2. 读取XML 发送网页版邮件

    DataSet ds = new DataSet(); ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory + "XML\\Mail.xml&q ...

  3. intellij,eclipse,vs2013快捷键

    如何跳转到上一次编辑的位置,即如何跳到上一个光标所在的位置? intellij: Command+Alt+左方向键:上一光标的位置 Command+Alt+右方向键:下一光标的位置 定位到最后编辑位置 ...

  4. 去空格 whitespaceAndNewlineCharacterSet和过滤字符串

    一.过滤字符串 可以使用stringByTrimmingCharactersInSet函数过滤字符串中的特殊符号 首先自己定义一个NSCharacterSet, 包含需要去除的特殊符号 NSChara ...

  5. DQL、DML、DDL、DCL的概念与区别

    SQL(Structure Query Language)语言是数据库的核心语言. SQL的发展是从1974年开始的,其发展过程如下:1974年-----由Boyce和Chamberlin提出,当时称 ...

  6. PHP从mysqli中获取的资源$result是不是不能while($row = $result->fetch_assoc())这样两次?【坑】

    PHP从mysqli中获取的资源$result是不是不能while($row = $result->fetch_assoc())这样两次? 因为我这样做,结果后面的查询结果就无法显示了,目前尚不 ...

  7. 【windows 下安装 mysql-server 无法登录问题解决】

    ----------------------------- 无感的首行 ----------------------------- 新版 mysql-server 5.7 安装后发现无法使用 mysq ...

  8. 我开发的SNMP编译器和浏览器

    我开发的SNMP编译器和浏览器 什么是SNMP SNMP(Simple Network Management Protocol,简单网络管理协议)的前身是简单网关监控协议(SGMP),用来对通信线路进 ...

  9. centos 如何清理/dev/vda1系统盘

    df-h检查一台服务器磁盘使用空间,发现磁盘已经使用了100% 思路是: 1.cd /usr 2.du -sh * 看哪个目录占用空间大 3.重复前两步,根据实际情况删除或者移走 4.日志的话可以运行 ...

  10. checkbox标签已有checked=checked属性但是不显示勾选

    点击全选按钮,选中下面的列表,再次点击取消选择. 第一次的使用的方法是$("input[name=xxx]").attr('checked',true); 但是往往刷新页面第一次点 ...