我有一个持久的类:
public class NotifEventGroupRel implements Serializable{
private static final long serialVersionUID = 7616645672995663305L;
private Long eventGroupId;
private String eventName;
private NotifEventGroup notifEventGroup; //// composite id property
private EmailTmplt emailTmplt; // composite id property
private SmsTmplt smsTmplt; // composite id property
....
}
它的 hbm.xml 文件是:
<hibernate-mapping>
<class name="NotifEventGroupRel" table="TBLMEVENTGROUPREL">
<composite-id>
<key-many-to-one name="notifEventGroup" class="NotifEventGroup" lazy="false" >
<column name="EVENTGROUPID" precision="20" scale="0" not-null="true" />
</key-many-to-one>
<key-property name="eventName" type="java.lang.String">
<column name="EVENT" />
</key-property>
</composite-id>
<many-to-one name="emailTmplt" class="EmailTmplt" lazy="false" not-null="false" >
<column name="EMAILTMPLTID"></column>
</many-to-one>
<many-to-one name="smsTmplt" class="SmsTmplt" lazy="false" not-null="false">
<column name="SMSTMPLTID" />
</many-to-one>
</class>
</hibernate-mapping>
形成复合 id 的属性类别是:
public class NotifEventGroup {
private Long eventGroupId;
private String name;
.......
}
public class EmailTmplt {
private Long emailTmpltId;
private String name;
.....
}
public class SmsTmplt {
private Long smsTmpltId;
private String name;
..........
}
- 我是否需要使以下属性瞬态:
(如下图)
private transient NotifEventGroup notifEventGroup; //// composite id property
private transient EmailTmplt emailTmplt; // composite id property
private transient SmsTmplt smsTmplt; // composite id property
因为 findbug 给了我Non-transient non-serializable instance field in serializable class
字段的错误(如果不是瞬态的)。
- 或者我是否必须使他们相应的类可序列化?
做上述两种情况有什么影响?