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 (官网 ...
随机推荐
- Zookeeper-Zookeeper可以干什么
在Zookeeper的官网上有这么一句话:ZooKeeper is a centralized service for maintaining configuration information, n ...
- NAT技术
该文摘自百度百科"NAT"中的一部分 NAT(Network Address Translation,网络地址转换)是1994年提出的.当在专用网内部的一些主机本来已经分配到了本地 ...
- jQuery Mobile 列表内容
jQuery Mobile 列表缩略图 对于大于 16x16px 的图像,请在链接中添加 <img> 元素. jQuery Mobile 将自动把图像调整至 80x80px: 实例: &l ...
- Send SqlParameter to Dapper
Question: I' using Dapper in my project. I have a list of SqlParameters and I want to send it to Dap ...
- 网络-->监控-->OID-->BGP
说明:暂时发现只适合cisco设备,h3c的交换机只支持部分OID(支持版本.AS号.ROUTER-ID)
- hdu 5877 (dfs+树状数组) Weak Pair
题目:这里 题意: 给出一个n个结点的树和一个数k,每个结点都有一个权值,问有多少对点(u,v)满足u是v的祖先结点且二者的权值之积小于等于k. 从根结点开始dfs,假设搜的的点的权值是v,我们需要的 ...
- c++ 覆盖、重载与隐藏
成员函数被重载的特征:(1)相同的范围(在同一个类中):(2)函数名字相同:(3)参数不同:(4)virtual 关键字可有可无.覆盖是指派生类函数覆盖基类函数,特征是:(1)不同的范围(分别位于派生 ...
- RHEL7.2
在RHEL7.2中,通过以下命令设置开机进入图形界面或者命令行界面: systemctl set-default graphical.target #设置开机默认进入图形界面 systemctl se ...
- 对ArrayList操作时报错java.util.ConcurrentModificationException null
用iterator遍历集合时要注意的地方:不可以对iterator相关的地方做添加或删除操作.否则会报java.util.ConcurrentModificationException 例如如下代码: ...
- MySQLdb操作mysql的blob值
一般情况下我们是把图片存储在文件系统中,而只在数据库中存储文件路径的,但是有时候也会有特殊的需求:把图片二进制存入数据库. 今天我们采用的是python+mysql的方式 MYSQL 是支持把图片存入 ...