JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-003使用@AttributeOverrides
2016-04-07 11:41
393 查看
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.
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; } // ... }
相关文章推荐
- 如何快速创建一个通用的主流框架
- 安卓倒计时
- iOS KVC & KVO
- Android性能
- iOS 高级开发 KVC(一),ios开发kvc
- 實作解析:微信開發重點摘要 (6) - 兩種用戶信息獲取方式
- 微信扫描下载提示以及js判断用户手机系统
- Android ADB server didn't ACK * failed to start daemon * 简单有效的解决方案
- Android Touch事件传递机制解析
- iOS开发之----KVC的使用
- Objective-c 内存管理-内存泄漏
- 安卓Socket通信
- ios开发之你真的了解了KVC吗?
- Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException
- Objective-C 对 URL 进展 URLEncode 编码
- ORA-12519: TNS:no appropriate service handler found 解决
- Android Studio如何自动 import
- 安卓倒计时秒
- Android动态部署六:如何从插件apk中启动BroadcastReceiver和ContentProvider
- iOS中静态库的使用