为什么JPA要求域对象使用无参数构造函数?

问题描述 投票:11回答:2

为什么JPA要求域对象使用无参数构造函数?我正在使用eclipselink,并且在部署期间遇到了此异常。

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)])
java jpa persistence
2个回答
14
投票

因为通常会发生JPA提供者必须动态实例化域对象的情况。除非有一个无参数的构造函数,否则它不能这样做-它无法猜测参数应该是什么。


7
投票

还请注意,这是not提供商的依赖。这是JPA规范。

JPA v2.0 JSR-317和v2.1 JSR-338说:

实体类必须具有无参数构造函数。实体类也可以具有其他构造函数。no-arg构造函数必须是公共或受保护的]]。

© www.soinside.com 2019 - 2024. All rights reserved.