Reputation: 897
I have entity:
@Entity(name = "Term")
@Table(name = "extra_term")
public class Term implements Cloneable, Serializable{
This entity has ID
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
And this entity has attribute with List of users owned by this entity (users are registered to term)
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "etc. etc. etc. })
private List<TermUser> users = new ArrayList<TermUser>();
Is it possible to declare business method to count the sum of this users registered to concrete term? Something like
public long getUsersCount() {
return QUERY TO THE DATABASE "GET COUNT OF USERS REGISTERED TO TERM WITH ID
(where ID is the id of this entity?)"
}
I need to count the number of users registered to term straight from the entitz but I dont want to have a attribute "registeredUsersCount" in DB.
Upvotes: 1
Views: 881
Reputation: 51030
That's exactly what @Transient
is for.
Every non static non transient property (field or method depending on the access type) of an entity is considered persistent, unless you annotate it as @Transient.
Upvotes: 2