2009-06-05 81 views

回答

2

Take a look at UserType。你需要在nullSafeGet()中調用你的工廠,然後自己填充所有的字段。反向工作在nullSafeSet()中完成。

2

如果它不能被映射,並 休眠提供定製 對象創建一個類的類 基礎鉤?

檢出實體監聽器。這些只會添加幫助你的註釋。 Think @PrePersist或@PostLoad。

9

這是可行的使用或者:

我想攔截的方法更容易。這裏是Interceptor.instantiate()的javadoc的:

/** 
* Instantiate the entity class. Return <tt>null</tt> to indicate that Hibernate should use 
* the default constructor of the class. The identifier property of the returned instance 
* should be initialized with the given identifier. 
* 
* @param entityName the name of the entity 
* @param entityMode The type of entity instance to be returned. 
* @param id the identifier of the new instance 
* @return an instance of the class, or <tt>null</tt> to choose default behaviour 
*/ 
public Object instantiate(String entityName, EntityMode entityMode, Serializable id) throws CallbackException; 
+0

這些解決方案都不涉及問題的「反射設置屬性或字段」部分。 – 2011-03-10 22:34:10

0

我不知道我究竟明白你問什麼,但我認爲一個解決方案在此說明(見配液4 - Hibernate的攔截器,方法OnLoad ):「帶Spring和休眠的域驅動設計」http://www.jblewitt.com/blog/?p=129

+0

不,onLoad不允許改變Hibernate實例化實體的方式,這就是問題所在。 – 2010-11-13 11:24:34

相關問題