生成具有复合主键的实体时出错

发布于 2024-12-12 06:15:22 字数 1417 浏览 0 评论 0原文

今天我意识到我丢失了我的一个实体。我生成了 XML 元数据,然后生成了实体。我尝试重新生成实体,但仍然没有成功地重新生成它。

该实体具有复合主键。该密钥的每个部分实际上都是外密钥。

SQL:

CREATE TABLE lajki (
    _wydarzenie_id INT NOT NULL,
    _uzytkownik_id INT NOT NULL,
    _lajk_data DATETIME NOT NULL,
    PRIMARY KEY (_wydarzenie_id, _uzytkownik_id),
    FOREIGN KEY (_uzytkownik_id) REFERENCES uzytkownicy(_uzytkownik_id),
    FOREIGN KEY (_wydarzenie_id) REFERENCES wydarzenia(_wydarzenie_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;

XML 元数据:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Lajki" table="lajki">
    <change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy>
    <id name="wydarzenieId" type="integer" column="_wydarzenie_id"/>
    <id name="uzytkownikId" type="integer" column="_uzytkownik_id"/>
    <field name="lajkData" type="datetime" column="_lajk_data"/>
    <lifecycle-callbacks/>
  </entity>
</doctrine-mapping>

我需要做什么才能使其正常工作?我自己编写实体还是只需要更改一些内容?

I realized today I was missing one of my entities. I generated the XML metadata and then generated the entity. I tried regenerate the entity, but still I haven't managed to regenerate it successfully.

That entity has composite primary key. And each part of that key is actually foregin key.

SQL:

CREATE TABLE lajki (
    _wydarzenie_id INT NOT NULL,
    _uzytkownik_id INT NOT NULL,
    _lajk_data DATETIME NOT NULL,
    PRIMARY KEY (_wydarzenie_id, _uzytkownik_id),
    FOREIGN KEY (_uzytkownik_id) REFERENCES uzytkownicy(_uzytkownik_id),
    FOREIGN KEY (_wydarzenie_id) REFERENCES wydarzenia(_wydarzenie_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;

XML metadata:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Lajki" table="lajki">
    <change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy>
    <id name="wydarzenieId" type="integer" column="_wydarzenie_id"/>
    <id name="uzytkownikId" type="integer" column="_uzytkownik_id"/>
    <field name="lajkData" type="datetime" column="_lajk_data"/>
    <lifecycle-callbacks/>
  </entity>
</doctrine-mapping>

What I have to do to have it working? Do I have write entity by myself or I have just to change something?

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

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

发布评论

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

评论(1

臻嫒无言 2024-12-19 06:15:22

我猜你正在谈论 命令行工具 从注释生成类和代理。一般来说,该工具不是很好。它在继承方面存在很多问题,并且在您的情况下似乎存在复合(非双)键。

尝试手动更正实体类中的注释,不要使用该工具。如果您非常想使用它,请只在第一次生成所有内容,纠正工具无法解决的错误,然后忘记该工具曾经存在过:)

顺便说一句。尽管 Doctrine 支持复合键,但不鼓励使用它们。因此,如果不是真正必要,请不要使用它们。请参阅文档。

I guess you are talking about the command line tool which generates classes and proxies from annotations. Generally the tool is not very good. It has a lot of problems with inheritance, and it seems, with composite (not dual) keys in your case.

Try to correct the annotations in your entity classes manually, don't use the tool. If you want to use it so badly, generate everything only the first time, correct the errors tool can't resolve, and forget about that tool ever existed :)

Btw. although Doctrine supports composite keys, their usage is discouraged. So don't use them if they are not really necessary. See the documentation.

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