为什么Hyperjaxb3生成RestItem类?(Why does Hyperjaxb3 generate RestItem classes?)

编程入门 行业动态 更新时间:2024-10-17 00:25:52
为什么Hyperjaxb3生成RestItem类?(Why does Hyperjaxb3 generate RestItem classes?)

我使用maven-hyperjaxb3-plugin(0.6.1)从我的xsd文件生成域类。 除了一个类以外,一切都很好,甚至可以正常工作,直到我添加了超过23个字段。

一旦我超过了这个数量的字段,它会为我的表名为ILT生成两个类:一个名为ILT.java,另一个名为ILTRestItem.java,我认为这与使用这些类与REST API有关(我不喜欢不打算这样做)。

ILTRestItem类有编译错误。 它对XmlAdapterUtils.unmarshallJAXBElement进行了很多调用,错误消息是:

类型XmlAdapterUtils中的marshallJAXBElement(Class,QName,Class,BoundType)方法不适用于参数(Class,QName,Class,String)

我并不太担心这个错误,因为我宁愿它根本没有创建ILTRestItem类。 其他(较小的)班级正常工作,我的目标是让ILT做同样的事情。

如果我运行jaxb2插件(maven-jaxb2-plugin)并使用它来生成类,则不会生成ILTRestItem,并且这些类是正确的,但它们当然缺少JPA注释。 这导致我怀疑Hyperjaxb3负责生成ILTRestItem类,但是我查看了希望通过源代码查看类似'RestItem'的类,并且没有任何类。

一个相关的观点是我在这里使用单表继承。 ILT类和另一个类(IFT)使用相同的基础表(Transaction),它们都扩展了Transaction类。 如果我从事务中分离ILT并将其设置为非继承类,则ILTRestItem不再生成。

对JAXB2和HyperJaxb3的搜索很多,我没有找到任何对RestItem的引用或者它为什么生成(或者它们是做什么的)。 我希望有一些配置开关关闭RestItem代,但到目前为止我看不到它。

为了完整起见,我应该补充一下,我尝试将不同的领域转换出来,看看他们中的一个是否是这种行为的触发器,而事实并非如此。 它看起来好像是字段的数量,或者可能是记录的总长度。

另外:JPA 2.1和相关的maven片段是:

<plugin> <groupId>org.jvnet.hyperjaxb3</groupId> <artifactId>maven-hyperjaxb3-plugin</artifactId> <version>0.6.1</version> <dependencies> <dependency> <groupId>com.xyz</groupId> <artifactId>ims-core-partner</artifactId> <version>${project.version}</version> </dependency> </dependencies> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <variant>jpa2</variant> <extension>true</extension> <args> <arg>-extension</arg> <arg>-XtoString</arg> <arg>-Xannotate</arg> </args> </configuration> </plugin>

依赖关系是使用annox在附件中获得一对自定义注释。

最后,这里是我的xsd文件中的相关片段:

<complexType name="ILT"> <xsd:annotation> <xsd:appinfo> <hj:entity> <orm:inheritance strategy="SINGLE_TABLE"/> <orm:discriminator-value>ILT</orm:discriminator-value> </hj:entity> </xsd:appinfo> </xsd:annotation> <xsd:complexContent> <xsd:extension base="tns:Transaction"> <xsd:sequence> <element name="iltType" type="tns:ItemType"> </element> <element name="investmentOrderId" type="string"> </element> ...

只要我的领域清单足够短,这一切都能奏效。

I'm using maven-hyperjaxb3-plugin (0.6.1) to generate domain classes from my xsd file. Everything works very well except for one class, and even that works fine until I add more than 23 fields onto it.

Once I exceed that number of fields it generates two classes for my table named ILT: one is called ILT.java and one is called ILTRestItem.java, which I assume is something to do with using these classes with a REST API (something I don't plan to do).

The ILTRestItem class has compile errors. It does a lot of calls to XmlAdapterUtils.unmarshallJAXBElement and the error message is:

The method marshallJAXBElement(Class, QName, Class, BoundType) in the type XmlAdapterUtils is not applicable for the arguments (Class, QName, Class, String)

I am not actually too worried about that error because I would rather it just didn't create the ILTRestItem class at all. The other (smaller) classes work fine and my goal is for ILT to do the same thing.

If I run the jaxb2 plugin (maven-jaxb2-plugin) and use that to generate the classes there is no ILTRestItem generated and the classes are the right ones, but they are, of course, missing the JPA annotations. That leads me to suspect that Hyperjaxb3 is responsible for generating the ILTRestItem class, but I've looked through the source code hoping to see classes with something like 'RestItem' in them and there aren't any.

One relevant point is that I am using single table inheritance here. The ILT class and another class (IFT) use the same underlying table (Transaction) and they both extend the Transaction class. If I detach ILT from Transaction and make it a non-inherited class the ILTRestItem no longer generates.

Lots of searches of both JAXB2 and HyperJaxb3 and I don't find any reference to RestItem or just why it is generated (or which of them does it). My hope is there is some config switch to turn off RestItem generation but so far I can't see it.

For completeness I should add I tried switching out different fields to see if one of them was the trigger for this behaviour and it isn't. It really seems to be the number of fields, or possibly the total length of the record.

Also: JPA 2.1 and the relevant maven fragment is:

<plugin> <groupId>org.jvnet.hyperjaxb3</groupId> <artifactId>maven-hyperjaxb3-plugin</artifactId> <version>0.6.1</version> <dependencies> <dependency> <groupId>com.xyz</groupId> <artifactId>ims-core-partner</artifactId> <version>${project.version}</version> </dependency> </dependencies> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <variant>jpa2</variant> <extension>true</extension> <args> <arg>-extension</arg> <arg>-XtoString</arg> <arg>-Xannotate</arg> </args> </configuration> </plugin>

The dependency is to get a couple of custom annotations in that attach using annox.

Finally here is the relevant fragment from my xsd file:

<complexType name="ILT"> <xsd:annotation> <xsd:appinfo> <hj:entity> <orm:inheritance strategy="SINGLE_TABLE"/> <orm:discriminator-value>ILT</orm:discriminator-value> </hj:entity> </xsd:appinfo> </xsd:annotation> <xsd:complexContent> <xsd:extension base="tns:Transaction"> <xsd:sequence> <element name="iltType" type="tns:ItemType"> </element> <element name="investmentOrderId" type="string"> </element> ...

This does all work, as long as my field list is short enough.

最满意答案

有趣的是,一旦你在这里提出问题,答案就会在接下来的30分钟内出现。 无论如何。 我遇到的问题是由我在ILT类(生成ILTRestItem的那个)和Transaction类(它继承的类)中定义了相同的字段触发的。 相当合理地,它试图将其分成单独的表格并进行连接。 当我从ILT中删除该字段时,问题消失了。 我不确定我是如何错过它是由某个特定领域造成的,我想我可能在升级到最新版本之前得出这个结论。

Funny how once you put in a question here the answer turns up in the next 30 minutes. Sort of anyway. The problem I had was triggered by my having defined the same field in the ILT class (the one generating the ILTRestItem) and the Transaction class (the one it inherits from). Quite reasonably it was trying to split that out into a separate table and do a join. When I removed that field from ILT the problem vanished. I'm not sure how I missed that it was being cause by a particular field, I think I may have come to that conclusion before I upgraded to the latest version.

更多推荐

本文发布于:2023-07-04 17:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026956.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:RestItem   classes   generate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!