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. NSArray转json字符串

    func arrayToJson(arr:NSArray) -> String { let jsonData: NSData = try! NSJSONSerialization.dataWit ...

  2. Android开发学习---使用XmlPullParser解析xml文件

    Android中解析XML的方式主要有三种:sax,dom和pull关于其内容可参考:http://blog.csdn.net/liuhe688/article/details/6415593 本文将 ...

  3. sql 将查询结果为多行一列合并为一行一列

    使用sql stuff函数 /*         stuff(param1, startIndex, length, param2)说明:将param1中自startIndex(SQL中都是从1开始, ...

  4. Mac 安装mysql5.7 注意事项

    下载与安装  去mysql官网(http://dev.mysql.com/downloads/mysql/)下载自己Mac相对应 MySQL Community  下载下来接压之后你会发现mysql就 ...

  5. 【如何快速的开发一个完整的iOS直播app】(采集篇)

    原文转自:袁峥Seemygo    感谢分享.自我学习 前言 在看这篇之前,如果您还不了解直播原理,请查看这篇文章如何快速的开发一个完整的iOS直播app(原理篇) 开发一款直播app,首先需要采集主 ...

  6. PHP中phar包的使用

    PHP5.3之后支持了类似Java的jar包,名为phar.用来将多个PHP文件打包为一个文件. 首先需要修改php.ini配置将phar的readonly关闭,默认是不能写phar包的,includ ...

  7. OpenMP并行构造的schedule子句详解 (转载)

    原文:http://blog.csdn.net/gengshenghong/article/details/7000979 schedule的语法为: schedule(kind, [chunk_si ...

  8. RTP在。net中的使用(资料)

    开源组件:lumisoft 网址:http://www.lumisoft.ee/lswww/download/downloads/Examples/ 非开源的免费组建:rtp.net (微软推荐)

  9. OpenVPN 通过服务器上网

    在Windows环境中架设OpenVPN服务相对比较简单,网上这方面的教程也比较丰富,照葫芦画瓢即可.但是大部分教程都只讲了如何将client与Server通过VPN管道连接起来,使client可以正 ...

  10. html5新特性之拖放

    1.元素是否可拖动可放置 draggable="true" 设置元素可以拖动 ondragover="allowDrop(event)"  元素默认不能放置,加 ...