I have entity that I need some of the fields not to be persisted and some of the fields not to be serialized.
I am using the @Transient on some of the fields but when I want to mark transient for the Gson. The issue is that hibernate picks it up and also not persist it since its also a keyword in Hibernate .
I use Hibernate-jpa-2.1-api javax.persistence.Transient
I am trying prevent addresses
from being serialized and getDefaultAddress
should not be saved.
Code:
@Entity
@Table(name="Business")
public class Business{
@OneToMany(mappedBy="business")
private transient List<Phone> addresses;
@Transient
public Phone getDefaultPhone() {
return phones.get(0);
}
}
Any solution?
You can use
@Expose
In order to be able to work with this annotation,
Source : http://www.javacreed.com/gson-annotations-example/