JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-003使用@AttributeOverrides
Each @AttributeOverride for a component property is “complete”: any JPA or Hibernate annotation on the overridden property is ignored. This means the @Column annotations on the Address class are ignored—all BILLING_* columns are NULL able!(Bean Validation still recognizes the @NotNull annotation on the component property, though; Hibernate only overrides persistence annotations.)
1.
package org.jpwh.model.simple; import org.jpwh.model.Constants; import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal; @Entity
@Table(name = "USERS")
public class User implements Serializable { @Id
@GeneratedValue(generator = Constants.ID_GENERATOR)
protected Long id; public Long getId() {
return id;
} protected String username; public User() {
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} // The Address is @Embeddable, no annotation needed here...
protected Address homeAddress; public Address getHomeAddress() {
return homeAddress;
} public void setHomeAddress(Address homeAddress) {
this.homeAddress = homeAddress;
} @Embedded // Not necessary...
@AttributeOverrides({
@AttributeOverride(name = "street",
column = @Column(name = "BILLING_STREET")), // NULLable!
@AttributeOverride(name = "zipcode",
column = @Column(name = "BILLING_ZIPCODE", length = 5)),
@AttributeOverride(name = "city",
column = @Column(name = "BILLING_CITY"))
})
protected Address billingAddress; public Address getBillingAddress() {
return billingAddress;
} public void setBillingAddress(Address billingAddress) {
this.billingAddress = billingAddress;
} public BigDecimal calcShippingCosts(Address fromLocation) {
// Empty implementation of business method
return null;
} // ...
}
JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-003使用@AttributeOverrides的更多相关文章
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-001Mapping basic properties(@Basic、@Access、access="noop"、@Formula、@ColumnTransformer、@Generated、 @ColumnDefaul、@Temporal、@Enumerated)
一.简介 在JPA中,默认所有属性都会persist,属性要属于以下3种情况,Hibernate在启动时会报错 1.java基本类型或包装类 2.有注解 @Embedded 3.有实现java.io. ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-007UserTypes的用法(@org.hibernate.annotations.Type、@org.hibernate.annotations.TypeDefs、CompositeUserType、DynamicParameterizedType、、、)
一.结构 二.Hibernate支持的UserTypes接口 UserType —You can transform values by interacting with the plain JD ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-006类型转换器( @Converter(autoApply = true) 、type="converter:qualified.ConverterName" )
一.结构 二.代码 1. package org.jpwh.model.advanced; import java.io.Serializable; import java.math.BigDecim ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-005控制类型映射(Nationalized、@LOB、@org.hibernate.annotations.Type)
一.简介 1. 2. 3. 4. to override this default mapping. The JPA specification has a convenient shortcut a ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-004嵌套组件的注解AttributeOverrides
一.数据库 二.代码 1. package org.jpwh.model.advanced; import javax.persistence.AttributeOverride; import ja ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-002使用@Embeddable
一.数据库 二.代码 1. package org.jpwh.model.simple; import javax.persistence.Column; import javax.persisten ...
- JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-003映射实体时的可选操作(<delimited-identifiers/>、PhysicalNamingStrategy、PhysicalNamingStrategyStandardImpl、、、)
一.自定义映射的表名 1. @Entity @Table(name = "USERS") public class User implements Serializable { / ...
- JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-003Table per concrete class with unions(@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)、<union-subclass>)
一.代码 1. package org.jpwh.model.inheritance.tableperclass; import org.jpwh.model.Constants; import ja ...
- JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-002Table per concrete class with implicit polymorphism(@MappedSuperclass、@AttributeOverride)
一.结构 二.代码 1. package org.jpwh.model.inheritance.mappedsuperclass; import javax.persistence.MappedSup ...
随机推荐
- JavaScript构建(编绎)系统大比拼:Grunt vs. Gulp vs. NPM
Nicolas Bevacqua进行了一个比较JavaScript构建(编绎)系统的任务.他对三巨头: Grunt, Gulp and NPM进行了比较,并讨论了每种的优缺点. By Nicolas ...
- python3.4 安装ipython notebook
1.安装python3.4 2.安装pyreadline 3.安装ipython-1.2.1.zip 4.安装pyzmq-14.7.0-cp34-none-win32.whl,ZIP包有问题,下载wh ...
- c/c++中主线程退出,子线程也会退出
#include <windows.h> #include <process.h> /* _beginthread, _endthread */ #include <io ...
- 20145120 《Java程序设计》第6周学习总结
20145120 <Java程序设计>第6周学习总结 教材学习内容总结 java.io.InputStream.java.io.OutputStream实例分别作为输入.输出串流的代表对象 ...
- CRT团队组员博客地址统计
CRT团队GitHub地址:https://github.com/CoffeeRobotTeam/Coffee-Robot-System 洪超 http://www.cnblogs.com/chaoh ...
- Linux 下的类似Windows下Everything的搜索工具
Windows NTFS有个超级快的搜索工具Everything,非常好用,Linux下有几个类似的命令行工具,太难用了,推荐一个catfish,类似Everything,有GUI,可以自定义一个快捷 ...
- My97DatePicker控制开始时间和结束时间区间
开始时间: <input type="text" placeholder=" -请选择- " id="kssj" name=" ...
- 动态生成C# Lambda表达式
转载:http://www.educity.cn/develop/1407905.html,并整理! 对于C# Lambda的理解我们在之前的文章中已经讲述过了,那么作为Delegate的进化使用,为 ...
- Python编码设置
系统编码顺序: 1, a.encode(sys.stdout.encoding) 2, a.encode(default_string) sys.stdout.encoding里的值可以用环境变量PY ...
- Restful API 最佳实践 (理论篇)
参考: http://www.ibm.com/developerworks/cn/web/1103_chenyan_restapi/ 规划好 资源标示结构 和 URI模式, 是API设计成功的关键 原 ...