Java Persistence with Hibernate phần 4

Bạn viết một CompositeUserType nếu bạn cần toàn bộ sức mạnh của các truy vấn Hibernate. Giao diện này (hơi phức tạp hơn) cho thấy nhiều đặc tính của MonetaryAmount Hibernate truy vấn. Bây giờ chúng ta sẽ bản đồ nó một lần nữa với điều này tuỳ biến giao diện linh hoạt hơn để hai cột, | 228 CHAPTER 5 Inheritance and custom types You write a CompositeUserType if you need the full power of Hibernate queries. This slightly more complex interface exposes the properties of the MonetaryAmount to Hibernate queries. We ll now map it again with this more flexible customization interface to two columns effectively producing an equivalent to a component mapping. Creating a CompositeUserType To demonstrate the flexibility of custom mappings types you don t change the MonetaryAmount class and other persistent classes at all you change only the custom mapping type as shown in listing . Listing Custom mapping type for monetary amounts in new database schemas public class MonetaryAmountCompositeUserType implements CompositeUserType public int sqlTypes . public Class returnedClass. public boolean isMutable. public Object deepCopy. public Serializable disassemble. public Object assemble. public Object replace. public boolean equals. public int hashCode. public Object nullSafeGet ResultSet resultSet String names SessionImplementor session Object owner throws SQLException BigDecimal value names 0 if return null Currency currency names 1 return new MonetaryAmount value currency e public void nullSafeSet PreparedStatement statement -r Object value int index SessionImplementor session throws SQLException if value null index index 1 else Creating custom mapping types 229 MonetaryAmount amount MonetaryAmount value String currencyCode .getCurrencyCode index index 1 currencyCode o public String getPropertyNames 1 1 return new String amount currency bZ zz zzz zz J public Type getPropertyTypes 1 return new Type public Object getPropertyValue Object component int property

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
6    11    1    16-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.