简体   繁体   中英

Constructor in persistance class

I am using HIbernate version 3.2.5.

I read the below line in hibernate tutorials:

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

This is the link for the tutorial:

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/tutorial.html

But when I write a persistence class without a no-arg constructor, then also it works fine (I tried only retrieval part).

Hence where lies the validity of the above statement?

Please let me know if I am getting something worng.

Regards,

If you don't have any constructor in persistent class, JVM by default creates no-arg constructor for you, that is the reason why your code is working fine.

Read this tutorial to understand more about constructors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM