Search code examples
hibernatespringinserthqlnamed-query

Insert Row Into Composite Table With Hibernate Named Query


Does anyone know the correct syntax in HQL to insert a row into a composite table? or an example somehwere else? Nothing online, man I miss Linq-To-Sql.

@NamedQueries({
@NamedQuery( name = "WebsiteAction.addActionWebsite", query = "INSERT INTO WebsiteAction 
(websiteActionPK, websiteActionPK) SELECT a.Id, w.Id FROM Action a, Website w WHERE a.Id = :actionid AND w.Id = :websiteid")
})

Solution

  • The syntax for bulk insertstatements is described here. But this will only work if you try to insert into a table mapped to en entity. If WebsiteAction is just a join table, I think you'll have to use SQL rather than HQL.