I am showing a grid table whit the service names with the last price register. The problem is happen when I use the @Transient in my Service class.
In this case:
I do this:
public List<Service> findAllWithPrice() {
NativeQuery<Service> query =
this.getCurrentSession()
.createSQLQuery(
"select s.*, FORMAT((select ps.price from priceServices ps where ps.idService = s.id order by ps.dateRegister DESC limit 1),2) as currentPrice from service s");
query.addEntity( Service.class );
return query.getResultList();
}
/*********************/
@Entity
@Table(name = "service")
public class Service {
/****/
@Transient
private String currentPrice;
public String getCurrentPrice() {
if ( currentPrice == null ) {
return "$ 0.0";
}
return currentPrice;
}
}
If I leave @Transient both save and select work but ALL prices come as zero. The currentPrice is coming null.
If I remove @Transient the select comes right. It loads the services with the last registered price for each one.
But when I save to the bank, it returns an error saying that it did not find the currentPrice column (Because it really doesn't exist).
I searched here in the forum and on the internet but I didn't find a solution.
How can I solve this problem?