manning Hibernate in Action phần 7

Tham khảo tài liệu 'manning hibernate in action phần 7', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Understanding the Hibernate type system 205 D The UserType is responsible for dirty-checking property values. The equals method compares the current property value to a previous snapshot and determines whether the property is dirty and must by saved to the database. 0 The UserType is also partially responsible for creating the snapshot in the first place. Since MonetaryAmount is an immutable class the deepCopy method returns its argument. In the case of a mutable type it would need to return a copy of the argument to be used as the snapshot value. This method is also called when an instance of the type is written to or read from the second-level cache. F Hibernate can make some minor performance optimizations for immutable types like this one. The isMutable method tells Hibernate that this type is immutable. G The nullSafeGet method retrieves the property value from the JDBC ResultSet. You can also access the owner of the component if you need it for the conversion. All database values are in USD so you have to convert the MonetaryAmount returned by this method before you show it to the user. H The nullSafeSet method writes the property value to the JDBC PreparedState-ment. This method takes whatever currency is set and converts it to a simple BigDecimal USD value before saving. We now map the initialprice property of Item as follows property name initialPrice column INITIAL_PRICE type This is the simplest kind of transformation that a UserType could perform. Much more sophisticated things are possible. A custom mapping type could perform validation it could read and write data to and from an LDAP directory it could even retrieve persistent objects from a different Hibernate Session for a different database. You re limited mainly by your imagination We d prefer to represent both the amount and currency of our monetary amounts in the database especially if the schema isn t legacy but can be defined or updated quickly . We .

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
Đã 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.