Org.hibernate.hql.internal.QueryExecutionRequestException: not supported for DML operations [insert into

I am taking data from one table and want to insert it into another table. The first table containing many fields, I only need some fields if it is stored in a new table. I use the Hibernate query for this. I can get the result from the query, but when I try to insert into another table, it throws

org.hibernate.hql.internal.QueryExecutionRequestException: not supported for DML operations [insert into

Below is the code that throws the exception.

Query query=session.createQuery(" insert into CustomerMailAddress (subs_id,mail_Id) SELECT DISTINCT  subs_id, email_id FROM SubcriberModel WHERE subs_id IS NOT NULL AND email_id IS NOT NULL AND email_id <> ''");
List result = query.list();
int res = query.executeUpdate();
System.out.println("Command successfully executed....");
System.out.println("Numer of records effected...,"+result.size());

and when I run the code below without using query.executeUpdate (); Method

Query query=session.createQuery(" SELECT DISTINCT  subs_id, email_id FROM SubcriberModel WHERE subs_id IS NOT NULL AND email_id IS NOT NULL AND email_id <> ''  UNION ALL SELECT DISTINCT tbl_subscribers_subs_id, email_id FROM SocialProfileModel WHERE tbl_subscribers_subs_id IS NOT NULL AND email_id IS NOT NULL AND email_id <> ''");
List result = query.list();

The output for the above code The command completed successfully .... The number of entries completed ..., 21.

+4
1

,

query.executeUpdate();

query.list();

( , Hibernate subs_id):

Query query=session.createQuery("insert into CustomerMailAddress (subs_id, mail_Id)"+"SELECT DISTINCT m.subs_id, m.email_id FROM SubcriberModel m WHERE m.subs_id IS NOT NULL AND m.email_id IS NOT NULL AND m.email_id <> ''");
int res = query.executeUpdate();
System.out.println("Command successfully executed....");
System.out.println("Numer of records effected...,"+result.size());
+2

All Articles