• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to add annotation to add default value to the Spring JPA property

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a int  property , i need to add a default value via annotation. I am using Spring Data JPA(Spring Boot). I tried with below, but it didn't work. is there any other way to do this ?

 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Column(name="value")
   private int value=1;
Give it a try I guess it may work .. if not let me know
 
priyanshi bhardwaj
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sam liya wrote:


The above way might create a problem (it actually makes your database dependent)while shifting your DB.
Another way is to directly set a default value to param so when the objects get's created the value is in there.like this:

@Column(name="value")
   private int value=1;  

 
reply
    Bookmark Topic Watch Topic
  • New Topic