Grails - 条件映射
目前我正在开发一个使用 Oracle 作为数据库的网络应用程序。我已经被告知我的网络应用程序也必须在 Sybase ASE 上运行。我的 Oracle 数据库使用序列来生成 ID,并且我映射了我的域类以使用这些序列。据我所知,Sybase ASE 没有序列,只有恒等式。这是我的问题。如何使用代码/配置来与 Oracle 和 Sybase 配合使用。每个域的 ID 的一些“条件映射”就可以了。
我只是不想每次为已映射的其他数据库构建 web 应用程序时都注释/取消注释映射中的行。 有人知道该怎么做吗?
还有另一个危险:Oracle和Sybase之间的另一个差异对映射有影响(我不使用dbCreate =“create”生成数据库结构) 。此时我什么也没看到。 有什么经验吗?
编辑: 事实证明,不可能为两个数据库创建一个映射。我的 Oracle 结构在列名和表名中使用引号。 Sybase ASE 中不允许使用引号。我的(不太漂亮)解决方案是在某些特定平台上构建 web 应用程序时更改(注释/取消注释)映射。
顺便说一句,我是 Grails 的忠实粉丝,而这种映射似乎是一个缺点。如果我使用“纯”Hibernate,我会在 xml 文件中有两个映射,并且我会根据底层数据库更改它们。但 Grails 不允许我拥有两个映射。
Currently I'm developing a webapp which uses Oracle as a database. I've already been informed that my webapp has to work also on Sybase ASE. My Oracle database uses sequences to generate IDs and I mapped my domain classes to use those sequences. As far I know Sybase ASE doesn't have sequences but identities. And here is my problem. What to do with code/configuration to work with Oracle and Sybase. Some "conditional mapping" of ID for each domain would do.
I just don't want to comment/uncomment lines in mappings every time when I'm building webapp for other database than already mapped. Have anybody any idea what to do?
There is another danger: another differences between Oracle and Sybase which have influence on mapping (I don't generate database structure using dbCreate = "create"
) . At this point I don't see anything. Any experiences?
EDIT:
It turned out that it's not possible make one mapping for both databases. My Oracle structure uses quotes in column and table names. And quotes are not allowed in Sybase ASE. My (not nice and pretty) solution is changing (comment/uncomment) mapping when building webapp on some particular platform.
Btw I'm huge fan of Grails and this mapping thing seems to be a drawback. If I was using "pure" Hibernate I'd have two mappings in xml files and I'd change them depending on an underlying database. But Grails doesn't give me possibility to have two mappings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道 grails 是否允许您配置 id 生成的条件映射,但我认为也许您不需要使用序列或身份,并使用其他 hibernate id 生成器策略: http://grails.org/doc/1.3.7/ref/Database%20Mapping/id.html。
编辑:
查看 hibernate 文档,我发现可以根据数据库的容量使用序列或标识,来自 http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html#mapping-declaration-id:
所以你可能需要这样的配置:
I don't know if grails enable to you to configure coditional mapping for id generation but I think that maybe you don't need use neither sequences or identities, and use other hibernate id generator strategy: http://grails.org/doc/1.3.7/ref/Database%20Mapping/id.html.
EDIT:
Reviewing the hibernate documentation I found that is possible use sequences or identites according to capacities of database, from http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html#mapping-declaration-id:
So you maybe will need a configuration like this: