简体   繁体   中英

How to do cascade using hql query in hibernate

How to do cascade save or update using hql query in hibernate? also how can i use cascade update for some specific fields instead of updating all child table fields?

for example table User has
userName varchar(10)
Password varchar(10)

table UserAccessRights has
username varchar(10) FK of User table
password varchar(10) FK of User table
Authpassword varchar(10)

cascade update should happen only for username not for password. how can i acheive this?

You don't.

Since the cascade is a Hibernate configuration matter (ie HBM or annotations) the data must be returned to Java for processing of cascades. Doing UPDATE/DELETE row modifications in HQL happens entirely on the SQL server (and the SQL server does not understand JPA cascades, as JPA is a Java API not an SQL API or SQL standard).

You need to specify your cascade setting in your hbm files I suppose.

<set name="columnrecord" cascade="save-update" table="..."...>
      <key>
            <column name="COLUMN_NAME" not-null="true" />
      </key>
      <one-to-many class="..." />
</set>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM