• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

constructors in jpa Entity Class

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why should we not use parameterised constructors in Entity class.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vijay shetti wrote:Why should we not use parameterised constructors in Entity class.



Because JPA will only use no-args constructor when creating an instance of the entity object. You can still have a parameterized constructor, but you also must have a no-args one.

Mark
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And just in case it's not clear, if you have no constructors defined for the class, a default zero-arg constructor is generated for you automatically. If you include any non zero-arg constructors, you must create the zero-arg constructor yourself.

Best Regards,
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark E Hansen wrote:And just in case it's not clear, if you have no constructors defined for the class, a default zero-arg constructor is generated for you automatically. If you include any non zero-arg constructors, you must create the zero-arg constructor yourself.

Best Regards,



Um, isn't that what my last sentence just said. Oh, you are making it clearer. Thanks

Mark
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I thought the point might not be clear to a greenhorn. Didn't mean to imply anything else.
 
reply
    Bookmark Topic Watch Topic
  • New Topic