Hi,
I have an object that use a one-to many relation
--------------------------------
@OneToMany(cascade={CascadeType.ALL}, mappedBy="segnalazione",
fetch=FetchType.LAZY)
public List<Sub> getSub() { return sub; }
public void setSub(List<Sub> sub) { this.sub = sub;}
@Transient
public int getCounter() {
return this.getSub().size();
}
--------------------------------
sometimes I need to know only the number of Sub but getCounter()
retrieve from DB a lot of not useful data.
I found this fragment of code in openJpa manual
--------------------------------
EntityManager em = ...
Query q = em.createQuery("SELECT MAX(x.price) FROM Magazine x WHERE
x.title = 'JDJ'");
Number result = (Number) q.getSingleResult();
--------------------------------
This is usefull in a java program but I need to use the counter in a JSP
(a servlet retrieves the data and a JSP write a summary of data
retrieved whit the counter), It is more useful to me to use a property
of my object (like getCounter() ).
I can't figure how to write it, can someone help me?
thank you
Edoardo