简体   繁体   English

持久性类中的构造函数

[英]Constructor in persistance class

I am using HIbernate version 3.2.5. 我使用的是HIbernate版本3.2.5。

I read the below line in hibernate tutorials: 我在hibernate教程中阅读了以下内容:

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 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). 但是当我编写一个没有no-arg构造函数的持久化类时,它也可以正常工作(我只尝试检索部分)。

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. 如果在持久化类中没有任何构造函数,JVM默认为您创建no-arg构造函数,这就是为什么代码工作正常的原因。

Read this tutorial to understand more about constructors. 阅读本教程以了解有关构造函数的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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