jaxws 和 EclipseLink 拒绝使用 lib 中的枚举
我有一个 Maven 多模块项目,其中包含一个带有 Web 服务、一个库和一个批处理应用程序的 ejb。批处理应用程序和 ejb 模块共享一些枚举,然后这些枚举位于 lib 模块中。当尝试在 Web 服务方法中从库返回这些枚举之一时,它声称 ejb jar 文件中没有有效的 ejb。此外,当使用 @Enumerated(EnumType.STRING)
在 JPA 实体中使用其中另一个枚举作为属性时,我收到一条错误消息
“...不是枚举映射的有效类型。属性必须定义为 Java 枚举。”
我只是想知道为什么以这种方式使用这些枚举是一个问题?除了声明两次之外还有其他解决方法吗?
I have a maven multimodule project with a ejb with a webservice, a lib, and a batch app. The batch app and the ejb module shares some enums, which then is located in the lib module. When attempting to return one of these enums from the lib in a webservice method it claims that there are no valid ejbs in the ejb jar file. Also, when using another one of these enums as attributes in an JPA entity using @Enumerated(EnumType.STRING)
I get an error saying
"...is not a valid type for an enumerated mapping. The attribute must be defined as a Java enum."
I am simply wondering why using these enums in this way is a problem? Are there any workarounds besides declaring them twice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在做的一个项目也遇到了同样的问题。我有一个通用包,其中包含持久性包无法识别的通用接口(和枚举)。结果,我得到了上述异常(即使持久性捆绑包通过导入的包依赖于公共捆绑包。
我通过将公共捆绑包包含在持久性捆绑包的Java构建路径中解决了这个问题:
项目 - >项目property -> Java build path / Projects ;//在此处添加包含枚举的包
I had the same problem with a project i was working on. I have a common bundle which holds the general interfaces (and enums) which the persistence bundle did not recognise. As a result, I got the above exception (even though the persistence bundle had dependencies to the common bundle through the imported packages.
I solved this problem by including the common bundle in the Java build path of the persistence bundle:
project -> project properties -> Java build path / Projects ;//add the bundle that contains the enums here
我遇到了同样的问题,这是因为我正在使用 Arquillian 进行测试,并且由于某种原因我忘记在
中添加包含实际
enum
的包 。所以也许有一些东西阻止持久性提供者(在我的例子中是
eclipselink
)看到你的枚举类 我敢打赌,这就是您的情况,因为您有多个模块。I ran into the same problem, and it was because I was testing with
Arquillian
and for some reason I had forgotten to add the package containing the actualenum
in theshrinkwrap.
So maybe there is something preventing the persistence provider (
eclipselink
in my case) from seeing your enum class. That's what I would bet is happening in your case, because you have multiple modules.