简体   繁体   中英

How to update a database record using hibernate with no primary key

I am trying to create a web service using Jersey and connect to the database using Hibernate.

Due to security reasons, I don't want to pass the primary key value from the server to the client or the opposite direction. In that case, how can I update a record? From examples I've seen you should call session.load(key) and change the returned object, but like I said, I won't be having the key value.

You may not pass a primary key to update a record but it implies two things :

  • You must have another way to identify in a unique way a record (maybe a business key or a composite key).
  • it may cost in performance since your PK is automatically indexed, not the other fields. Creating multiple indexes may be a cost.

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