gpt4 book ai didi

java - 配置 hyperjaxb 以创建 hibernate 映射和 mysql 数据库

转载 作者:行者123 更新时间:2023-12-01 17:04:35 25 4
gpt4 key购买 nike

我正在使用 hyperjaxb 从 xsd 文件生成 Java 类。如何配置它来生成 hibernate 注释,并触发 hbm2ddl 创建一个包含生成类表的 MySQL 数据库?

我下载了 hibernate 的采购订单示例 from this link ,然后导航到 cmd.exe 中的目标目录并运行 mvn clean install,但生成的文件夹不包含任何 java 类,并且也不包含任何 hibernate/MySQL。我想要一个工作示例,它从下载的 xsd 文件创建所有内容,以便我可以将自己的 xsd 文件插入代码中并拥有所有 java/hibernate/mysql 自动生成。这样我就可以花时间调整我的 xsd 文件,以便生成的 java/hibernate/MySQL 正是我需要的。

代码示例或分步说明会非常有帮助。我正在使用 eclipse 。

<小时/>

**编辑:**

这个问题的答案是在发布了其他几个问题后得出的。要找到此问题的完整答案,您需要查看其他问题的答案,特别是 the one at this link .

最佳答案

更新

最后,OP 似乎在项目的根目录中寻找生成的类,而不是 target\generated-source\xjc,尽管 tutorial明确指出要查看的位置:

If you browse the target/generated-sources/xjc directory, you'll find few generated java files, for instance PurchaseOrderType.java.

<小时/>

你说没有生成任何东西,我不明白。我刚刚重新检查了一下,一切正常。

我的步骤是:

  • 下载 hyperjaxb3-ejb-samples-po-initial-0.5.6-maven-src.zip
  • 解压
  • 转到 hyperjaxb3-ejb-samples-po-initial-0.5.6
  • mvn 全新安装

这是我得到的:

[INFO] ------------------------------------------------------------------------
[INFO] Building Hyperjaxb3 Samples [po-initial:maven] 0.5.6
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Deleting C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target
[INFO]
[INFO] --- maven-hyperjaxb3-plugin:0.6.0:generate (default) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Sources are not up-to-date; XJC execution will be executed.
[WARNING] According to the Java Persistence API specification, section 2.1, entities must be top-level classes:
"The entity class must be a top-level class."
Your JAXB model is not customized as with top-level local scoping, please use the <jaxb:globalBinding localScoping="toplevel"/> global bindings customization.
org.jvnet.hyperjaxb3.ejb.plugin.EjbPlugin

[WARNING] According to the Java Persistence API specification, section 2.1, entities must implement the serializable interface:
"If an entity instance is to be passed by value as a detached object
(e.g., through a remote interface), the entity class must implement
the Serializable interface."
Your JAXB model is not customized as serializable, please use the <jaxb:serializable/> global bindings customization element to make your model serializable.
org.jvnet.hyperjaxb3.ejb.plugin.EjbPlugin

[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 5 source files to C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 5 source files to C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Surefire report directory: C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running RoundtripTest
Detected [file:/C:/Projects/workspaces/hj3/dist/hyperjaxb3-ejb-samples-po-initial-0.5.6/target/classes/META-INF/persistence.xml].
RoundtripTest

Loading entity manager factory properties.
RoundtripTest

Loading entity manager factory properties from [file:/C:/Projects/workspaces/hj3/dist/hyperjaxb3-ejb-samples-po-initial-0.5.6/target/test-classes/persistence.properties].
RoundtripTest

Testing samples.
RoundtripTest

Sample directory [C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\src\test\samples].
RoundtripTest

Testing sample [po.xml].
RoundtripTest

Unmarshalling.
RoundtripTest

Opening session.
RoundtripTest

Saving the object.
RoundtripTest

Opening session.
RoundtripTest

Loading the object.
RoundtripTest

Closing the session.
RoundtripTest

Initial object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>

RoundtripTest

Source object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20" Hjid="1">
<shipTo country="US" Hjid="2">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US" Hjid="1">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items Hjid="1">
<item partNum="872-AA" Hjid="1">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA" Hjid="2">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>

RoundtripTest

Result object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20" Hjid="1">
<shipTo country="US" Hjid="2">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US" Hjid="1">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items Hjid="1">
<item partNum="872-AA" Hjid="1">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA" Hjid="2">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>

RoundtripTest

Checking the document identity.
RoundtripTest

Finished testing sample [po.xml].
RoundtripTest

Finished testing samples.
RoundtripTest

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.552 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Building jar: C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\hyperjaxb3-ejb-samples-po-initial-maven-0.5.6.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Installing C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\hyperjaxb3-ejb-samples-po-initial-maven-0.5.6.jar to C:\Repository\org\jvnet\hyperjaxb3\hyperjaxb3-ejb-samples-po-initial-maven\0.5.6\hyperjaxb3-ejb-samples-po-initial-maven-0.5.6.jar
[INFO] Installing C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\pom.xml to C:\Repository\org\jvnet\hyperjaxb3\hyperjaxb3-ejb-samples-po-initial-maven\0.5.6\hyperjaxb3-ejb-samples-po-initial-maven-0.5.6.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.100 s
[INFO] Finished at: 2014-10-09T00:42:10+01:00
[INFO] Final Memory: 22M/96M
[INFO] ------------------------------------------------------------------------

完整的 mvn clean install -X 日志为 here .

所以我希望你看到,它工作得很好。请发布您的mvn clean install -X,也许您做错了什么。

现在,关于您的问题,这里是 MySQL 示例:

https://github.com/highsource/hyperjaxb3/tree/master/ejb/tests/po-mysql

该项目包含 hbm2ddl 生成的片段:

https://github.com/highsource/hyperjaxb3/tree/master/ejb/tests/issues

由于某种原因,hbm2ddl 被注释掉了,不确定它是否有效,但它应该给出方向。

关于java - 配置 hyperjaxb 以创建 hibernate 映射和 mysql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26267272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com