java - Hibernate produces incorrect update statement -


i have this:

string hql = "update user u set u.externalid = u.id u.directory.name = 'mysuperawesomename' , u.externalid = null";     query query = session().createquery(hql);     query.executeupdate(); 

and hibernate throws exception saying that:

unexpected token join, requires set in statement [update user cross join  set external_id=id name='mysuperawesomename' , (external_id null)] 

please, me pointing did wrong.

mapping user entity:

<?xml version="1.0"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd//en" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping>     <class name="com.example.user" table="user" lazy="true">         <id name="id" column="id" unsaved-value="null">             <generator class="com.example.mysuperawesomegenerator"/>         </id>         <property name="name" column="user_name" type="string" not-null="true" length="255"/>         <property name="externalid" column="external_id" type="string" not-null="false" length="255" index="idx_external_id"/>         <many-to-one name="directory" column="directory_id" not-null="true" foreign-key="fk_user_dir_id" unique-key="uk_user_name_dir_id" class="com.example.directoryimpl"/>     </class> </hibernate-mapping> 

the answer might changing query query small subquery

update user u set u.externalid = u.id u.directory.id in (select d.id directoryimpl d d.name = 'mysuperawesomename') , u.externalid = null 

it works.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -