I use Java Persistence, and I want a web method to return a 'portion' of an Entity class. For example, I have a Customer class that represents a record in Customer table with many fields, but I want to return just few of them. Is it possible to use mapping to do that? Or the only way is to create a new class (maybe a superclass for Customer) that has only fields I want to return? I tried binding, but it didn't work (apparently I did it in a wrong way):
@Entity
@Table(name = "Customer", catalog = "test", schema = "")
@XmlType(name = "Customer")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
@XmlElement
private Integer accountId;
@Basic(optional = false)
@Column(name = "username")
@XmlElement
private String username;
@Basic(optional = false)
@Column(name = "password")
private String password;
I thought that if I don't add @XmlElement annotation to password field, it won't be included into result. However, I got a bunch of "Class has two properties of the same name" errors during deployment.