Why does JPA require a no-arg constructor for domain objects?

怎甘沉沦 提交于 2019-12-01 14:26:14

问题


Why does JPA require a no-arg constructor for domain objects ? I am using eclipselink and just got this exception during deployment.

Exception [EclipseLink-63] (Eclipse Persistence Services-1.1.0.r3639-SNAPSHOT): 
org.eclipse.persistence.exceptions.DescriptorException

Exception Description: The instance creation method   
[com.me.model.UserVO.<Default Constructor>], with no parameters, 
  does not exist, or is not accessible.
Internal Exception: java.lang.NoSuchMethodException: 
  com.me.model.UserVO.<init>()
Descriptor: RelationalDescriptor(com.me.model.UserVO --> 
  [DatabaseTable(user)])

回答1:


Because it often happens that the JPA provider has to instantiate your domain object dynamically. It cannot do so, unless there is a no-arg constructor - it can't guess what the arguments should be.




回答2:


Also notice that this is not provider dependent. It is a JPA specification.

JPA v2.0 JSR-317 and v2.1 JSR-338 says:

The entity class must have a no-arg constructor. The entity class may have other constructors as well. The no-arg constructor must be public or protected.



来源:https://stackoverflow.com/questions/2808747/why-does-jpa-require-a-no-arg-constructor-for-domain-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!