I am working on a Java web application that I inherited that uses Spring and Hibernate. This application contains persistence classes that were automatically generated using hbm2java. Included in these classes were constructors with multiple parameters (as well as your typical default constructor). These non-default constructors are not being directly accessed by any other methods. Nor is there any explicit spring definition for calling these classes, so it appears that it is dead code…
Now I know this question is hideously vague, but would there be any normal reason where Hibernate would normally invoke these constructors through reflection? I know it uses Class<T>.getInstance() to invoke the default constructor to create a new instance of the object, but that’s about it…
No, those are not there because the hibernate will use them.
That type of constructors are often useful when you instantiate and initialize the entity class. Instead of using the default constructor and calling multiple setters, it’s easier to use a constructor that takes multiple parameters.