HQLでinsert(準備稿)
HQLでinsertが使えるって?? code:
めちゃくちゃ便利じゃないかこれ…ちょっと開発が立て込んでいるのでとりあえずメモ
後でちゃんと記事にします。
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=002695
OK. Well the reason I ask why you want to do it in HQL, is because HQL only supports insert from another table, so:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String insertStatement = "insert into Object (id, name) select oo.id, oo.name from OtherObject oo";
s.createQuery( insertStatement ).executeUpdate();
tx.commit();
session.close();
would be how you do it.
Looking at your code above however there is no other table to select from.
| 固定リンク

コメント