生成具有复合主键的实体时出错
今天我意识到我丢失了我的一个实体。我生成了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你正在谈论 命令行工具 从注释生成类和代理。一般来说,该工具不是很好。它在继承方面存在很多问题,并且在您的情况下似乎存在复合(非双)键。
尝试手动更正实体类中的注释,不要使用该工具。如果您非常想使用它,请只在第一次生成所有内容,纠正工具无法解决的错误,然后忘记该工具曾经存在过:)
顺便说一句。尽管 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.