Datanucleus 模式生成忽略“继承策略=”指示

发布于 2024-10-04 20:13:28 字数 1450 浏览 0 评论 0原文

我正在使用 JDO 的 Datanucleus 教程应用程序, 特别是这个

无论我尝试哪种“继承策略”,表布局都是相同的。我想要两张表,一张用于产品,一张用于书籍,但使用下面的配置,我只能获得包含产品类和书籍类列的产品表。

   <class name="Product" identity-type="sequence">
        <inheritance strategy="complete-table"/>
        <field name="name">
            <column name="PRODUCT_NAME" length="100" jdbc-type="VARCHAR"/>
        </field>
        <field name="description">
            <column length="255" jdbc-type="VARCHAR"/>
        </field>
    </class>

    <class name="Book" identity-type="sequence">
        <field name="author">
            <column length="40" jdbc-type="VARCHAR"/>
        </field>
        <field name="isbn">
            <column length="20" jdbc-type="CHAR"/>
        </field>
        <field name="publisher">
            <column length="40" jdbc-type="VARCHAR"/>
        </field>
    </class> 

目录结构与教程中的完全一样,build.xml 也是如此。我尝试通过 Ant 任务和命令行生成架构。

我使用命令序列:

    ant clean
    ant compile
    ant enhance
    ant createschema

生成架构,但并不像 Datanucleus 文档建议的那样,它应该与继承策略“竞争表”一起使用。

如果重要的话,我的目标数据库是在 Ubuntu 10.04 上运行的 PostgreSQL 8.4。

还有其他人遇到这个问题并找到解决方案吗?

I'm working with the Datanucleus tutorial application for JDO, specifically this one.

Regardless which "inheritance strategy" I try the table layout is the same. I would like two tables, one for PRODUCT and one for BOOK, but using the configuration below I only get the PRODUCT table with columns for both class Product and class Book.

   <class name="Product" identity-type="sequence">
        <inheritance strategy="complete-table"/>
        <field name="name">
            <column name="PRODUCT_NAME" length="100" jdbc-type="VARCHAR"/>
        </field>
        <field name="description">
            <column length="255" jdbc-type="VARCHAR"/>
        </field>
    </class>

    <class name="Book" identity-type="sequence">
        <field name="author">
            <column length="40" jdbc-type="VARCHAR"/>
        </field>
        <field name="isbn">
            <column length="20" jdbc-type="CHAR"/>
        </field>
        <field name="publisher">
            <column length="40" jdbc-type="VARCHAR"/>
        </field>
    </class> 

The directory structure is exactly as in the tutorial, as is the build.xml. I have tried generating the schema via both the Ant task and the command line.

I use the sequence of commands:

    ant clean
    ant compile
    ant enhance
    ant createschema

The schema is generated but not as the Datanucleus documentation suggests that it should be with inheritance strategy "compete-table."

My target database is PostgreSQL 8.4 running on Ubuntu 10.04 if that matters.

Anyone else run into this issue and found a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风蛊 2024-10-11 20:13:28

回答我自己的问题:

在 datanucleus 教程下载中,给出的 build.xml 文件有一个“createschema”目标,例如:

<target name="createschema">
    ...

    <schematool ...>
        <fileset dir="${basedir}/target/classes">
            <include name="**/*.class"/>
        </fileset>
        ...
    </schematool>
</target>

应将其更改为包含所有 .jdo 文件,如下所示:

<target name="createschema">
    ...

    <schematool ...>
        <fileset dir="${basedir}/target/classes">
            <include name="**/*.class"/>
            <include name="**/*.jdo"/>
        </fileset>
        ...
    </schematool>
</target>

此外,package-hsql.orm 文件需要要重命名为 package-hsql.jdo 并且其标头需要更改为:

<?xml version="1.0"?>
<!DOCTYPE jdo PUBLIC
    "-//Sun Microsystems, Inc.//DTD Java Data Objects ORM Metadata 2.0//EN"
    "http://java.sun.com/dtd/orm_2_0.dtd">
<jdo>
    ...
<jdo>

请注意,DOCTYPE 和根元素已更改。根元素是“orm”并更改为“jdo”。

一旦我进行了这些更改,模式生成工具就会遵循“继承策略”指令。

To answer my own question:

In the datanucleus tutorial download, the build.xml file given has a "createschema" target like:

<target name="createschema">
    ...

    <schematool ...>
        <fileset dir="${basedir}/target/classes">
            <include name="**/*.class"/>
        </fileset>
        ...
    </schematool>
</target>

It should be changed to include all .jdo files as shown below:

<target name="createschema">
    ...

    <schematool ...>
        <fileset dir="${basedir}/target/classes">
            <include name="**/*.class"/>
            <include name="**/*.jdo"/>
        </fileset>
        ...
    </schematool>
</target>

In addition the package-hsql.orm file needs to be renamed to package-hsql.jdo and its header needs to be changed to:

<?xml version="1.0"?>
<!DOCTYPE jdo PUBLIC
    "-//Sun Microsystems, Inc.//DTD Java Data Objects ORM Metadata 2.0//EN"
    "http://java.sun.com/dtd/orm_2_0.dtd">
<jdo>
    ...
<jdo>

Notice that the DOCTYPE and root element were changed. The root element was "orm" and changed to "jdo".

Once I made these changes the schema generation tool followed the "inheritance strategy" directive.

暮年慕年 2024-10-11 20:13:28

对于我的自定义应用程序,我遇到了类似的问题,并且在对 jdo 文件的标头进行更改后工作正常。我使用的是3.2.9版本。

For my custom application, I had a similar issue, and it worked fine after making the changes in the header of the jdo file. I am using version 3.2.9.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文