I want to transform a simple query into hibernate
INSERT INTO TRXENTRIES (AMOUNT, BALANCE)
VALUES (2500, (SELECT CURRENTBALANCE FROM CUSTOMER WHERE CUSTOMERID=1)+2500))
What is alternative solution in hibernate using save()?
Update Me !
I want to transform a simple query into hibernate
INSERT INTO TRXENTRIES (AMOUNT, BALANCE)
VALUES (2500, (SELECT CURRENTBALANCE FROM CUSTOMER WHERE CUSTOMERID=1)+2500))
What is alternative solution in hibernate using save()?
Update Me !
you must:
Alternatively, you can use method createSqlQuery of session object to execute your SQL query and complete them with session.executeUpdate().
Sample:
Entity TrxEntry:
public class TrxEntry {
private Double amount;
private Double balance;
-- add your get / set properties
public Trxentry (Double amount, Double balance) {
this.amount = amount;
this.balance = balance;
}
}
Hql:
String hql = "select new TrxEntry(o.amount, o.balance)
from otherEntry o";
if you want calculate your o.balance as another subquery you can do without problem
The result of your query goes in
Query q = session.createQuery(hql);
session.merge(q);
Merge provides to save your entity