PDA

View Full Version : Hibernate requires blank constructor?



ew0kian
Aug 15th, 2009, 04:35 PM
i read somewhere that hibernate requires your domain objects to have a blank constructor for each one, is this still the case and does spring have anything to not force you to do that for each object?

dr_pompeii
Aug 15th, 2009, 06:14 PM
i read somewhere that hibernate requires your domain objects to have a blank constructor for each one

Thats true, here 1.1.2. The first class (http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#tutorial-firstapp-firstclass)



The no-argument constructor is a requirement for all persistent classes; Hibernate has to create objects for you, using Java Reflection. The constructor can be private, however package or public visibility is required for runtime proxy generation and efficient data retrieval without bytecode instrumentation.



About the other question


does spring have anything to not force you to do that for each object?

Seems, not, I have many projects with my domain objects without a blank constructor (I forgot totally such suggestion by Hibernate) and Spring never did some restriction

If I dont remember a java class by default has an implicitly blank constructor if no one is declared

But is important keep the suggestion for each Framework

HTH