I have a table user_services
Column | Type |
---------------+---------+
user_id | integer |
subservice_id | integer |
I have a SortedSet of subservice_ids in Java that I want to insert into my table each with the same user_id. Can this be done in a single INSERT-statement using native Hibernate SQL?
What if I do something like:
String values = StringUtils.join(mySubServiceIds, ',');
Query query = createSQLQuery("INSERT INTO user_subservices " +
"(user_id, subservice_id) " +
"SELECT 1 id, x " +
"FROM unnest(ARRAY["+ values + "]) x");
Would that work and be good?