3

I need to execute batch insert select statement:

Query query = em
        .createQuery(
        "insert into EntityA (a,b,entity_field) select t.a, t.b, 
         :entity_field from EntityA t where ...");
query.setParameter("entity_field ", entity);

Field entity_field is not a primitive type in EntityA I am getting java.lang.IllegalArgumentException: org.hibernate.QueryException: number of select types did not match those for insert.

Is there some way to do that?

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
Mark Carmark
  • 167
  • 4
  • 11

1 Answers1

1

when you put in select field a not primitive type it's decomposite in all properties. So you have a query like this:

INSERT INTO (a, b, entity_field)
SELECT t.a, t.b, entity_field.field1, entity_field.field2,...., entity_field.fieldN

When you do an INSERT you put only the primary key of your entity, so you can use only primitive type.

I hope, I was clear ;) Have a nice day

Joe Taras
  • 15,166
  • 7
  • 42
  • 55