• Post Reply Bookmark Topic Watch Topic
  • New Topic

Default Value to Property

 
Lakshmi Natarajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Our application needs to update a default value to a property suppose it was supplied or set. This can be done by defining default in DDL, but we cannot change the databse. We need to set this value through xml as this default value might change in future. Is there any provision in hbm file to set default value for a property.
 
Ankit Garg
Sheriff
Posts: 9597
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look here...
 
Lakshmi Natarajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit,

visited the site but the information would not be useful for me. The <meta> tag default value is used while generating the POJO class from hbm file(the POJO class generated with the default value set in setter method of the property) and does not set default value for the property for exisiting POJO class
 
Benjamin Winterberg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at Hibernate EventListeners: http://docs.jboss.org/hibernate/stable/core/reference/en/html/events.html#objectstate-events

You could check if the property is null or empty after the entity has been loaded by hibernate and in that case set your default value.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!