« 2008年2月 | トップページ | 2009年2月 »

2008年8月 6日 (水)

HQLでinsert(準備稿)

HQLでinsertが使えるって??
めちゃくちゃ便利じゃないかこれ…ちょっと開発が立て込んでいるのでとりあえずメモ
後でちゃんと記事にします。

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:

code:



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.

| | コメント (0) | トラックバック (0)

« 2008年2月 | トップページ | 2009年2月 »