0
我有一些實體,我需要某些字段不能被保留,有些字段不能被序列化。在同一個文件中對Gson和Hibernate使用瞬態
我在一些字段上使用@Transient,但是當我想爲Gson標記瞬態時。問題在於,休眠選取它並且也不會保留它,因爲它也是Hibernate中的關鍵字。
我使用Hibernate,JPA-2.1-API javax.persistence.Transient
我試圖阻止addresses
被序列化和getDefaultAddress
不應該被保存。
代碼:
@Entity
@Table(name="Business")
public class Business{
@OneToMany(mappedBy="business")
private transient List<Phone> addresses;
@Transient
public Phone getDefaultPhone() {
return phones.get(0);
}
}
任何解決方案?