Doctrine 2 ORM 和 MongoDB ODM 映射在同一个类上
是否可以使用注释将同一个类映射到 ORM 和 ODM?
我们正在决定使用什么,因此我们想要进行一些性能测量,并且我们还希望能够轻松切换持久性映射器。我已经完成了经理统一,现在我想统一班级。现在,我在实体和文档的单独命名空间中拥有每个类的副本,我发现这有点多余。
我读了这篇文章 http://www.doctrine-project.org/docs/mongodb_odm/1.0/en/cookbook/mapping-classes-to-orm-and-odm.html,但最后我猜他们使用了两个不同的类,每个类都在自己的命名空间中。
有人尝试过这个吗?
Is it possible to map the same class to both ORM and ODM using annotations?
We are deciding what to use so we want to do some performance measurment and we also want to be able to switch the persistance mappers easily. I have already done the manager unification, now i would like to unify the classes. Now i have a copy of each class in separate namespaces for Entities and Documents which i find kind of redundant.
I read this article http://www.doctrine-project.org/docs/mongodb_odm/1.0/en/cookbook/mapping-classes-to-orm-and-odm.html, but in the end i guess they use two different classes, each in their own namespace.
Has anybody tried this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我从未尝试过,但完全有可能将 ODM 和 ORM 映射放在完全相同的类上。
该问题可能依赖于这两个持久性后端之间的数据同步
和实体 API。例如,如果您有一个 ManyToOne 关联,ODM 将具有与 ORM 不同的内部内存引用。因此它可能会覆盖您正在使用的对象。
I've never tried but it's totally possible to put both ODM and ORM mapping on the exact same class.
The problem will maybe rely on synchronization of data between these two persistence backends
and the Entity API. For example, if you have a ManyToOne association, ODM will have a different internal in memory reference than ORM. So it's possible that it will override objects you were working with.
之前没有尝试过,但是我是否可以建议在 xml/yml 中为您的实体/文档类提供不同的映射?
Didn't try this before but if i could suggest something is to have different mapping in xml/yml for you entity/document class?
是的,你可以。我已经使用 symfony 和注释完成了它,所以我想您可以使用您正在使用的任何环境进行管理。
首先,我在实体上添加了两个注释:
在 symfony 下,ORM 的默认目录是 Entity 目录,对于 ODM 的默认目录是 Document。因此,如果您有一个实体必须同时是文档,则必须手动配置这两个映射中的一个。
Yes you can. I have done it using symfony and annotations, so I guess you could manage just as well using whatever environment you are using.
First, I added both annotations on the entity:
Under symfony the default directory for ORM is the Entity directory, for ODM the default directory is Document. So if you have an entity that has to be a document at the same time, you have to configure either of the two mappings manually.