• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: How to prevent insert and delete?

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1- How can I prevent insert and delete functions on a specific table/class?

2- How can I instruct hibernate not to persist the changes in an entity without call 'Update' explicitly?

I ran into a situation where a property of an entity is changed, but no the update function was not called. When the transaction is committed, hibernate persisted the changes to the database. Can this feature be disabled?
 
sangram mhatre
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using proper combination of
session.evict() and session.clear() before session.update() or session.save()
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using proper combination of
session.evict() and session.clear() before session.update() or session.save()


Did you mean to call session.clear() or session.evict() before I commit my transaction?

Because my point was the data is persisted even if I don't call update.
 
sankar singh
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please check this property hibernate.connection.autocommit property in hibernate.cfg.xml file

and also please have a look on the following link, search string is "automatic dirty checking"

http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html

Regards,
Sankar. S
 
sangram mhatre
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check setreadOnly() method.
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#setReadOnly(java.lang.Object,%20boolean)

Else you can write you own wrapper class to control the dirty checking .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic