Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructors in jpa Entity Class

 
vijay shetti
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why should we not use parameterised constructors in Entity class.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Yes, I thought the point might not be clear to a greenhorn. Didn't mean to imply anything else.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic