How to insert INSERT using SELECT to hibernate
I need to execute the following query while sleeping:
insert into my_table(....,max_column)
values(...,(select max(id) from special_table where ....))
How can I do this while sleeping using annotations? special_table may not be a child or dependent on my_table, but just a subquery.
+3
source to share
1 answer
You can use HQL INSERT INTO syntax :
String hqlInsert = "insert into MyEntity(....,max_column) select ..., max(id) from SpecialEntity where ....";
int updateCount = session.createQuery(hqlInsert).executeUpdate();
+5
source to share