我应该如何在项目(使用hibernate)中定义序列,以便项目可以同时使用Oracle和Mysql。 [英] how shall I define sequences in my project (which uses hibernate) in a way that the project works with both Oracle and Mysql.

查看:244
本文介绍了我应该如何在项目(使用hibernate)中定义序列,以便项目可以同时使用Oracle和Mysql。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用Hibernate作为OR映射器的java项目。我们需要该项目与Oracle和Mysql一起工作。因为有些客户不想安装Oracle。我们在实体上添加了@sequenceGenerator注释以获得序列。但该项目无法连接到带有这些注释的Mysql DBMS。有没有什么办法可以在mysql和Oracle模式下都有序列,而且没有任何改变?解析方案

最便携的方法是使用 TableGenerator 。它是可移植的,因为没有使用数据库提供程序特定的结构。最后生成的值存储到数据库表中,并通过SQL查询检索并增加值。



Hibernate中还涵盖了用法

We have a java project that uses Hibernate as the OR Mapper. We need the project to work with both Oracle and Mysql. because some customers don't want to install Oracle. we have added @sequenceGenerator annotation on entities to have sequence. but the project can not connect to Mysql DBMS with these annotations. Is there any way that we can have sequences in both mysql and Oracle mode, without any changes?

Most portable way is to use TableGenerator. It is portable because no database provider specific constructs are used. Last generated value is stored to the database table, and value is retrieved and incremented via SQL queries.

Usage is also covered in Hibernate documentation.

这篇关于我应该如何在项目(使用hibernate)中定义序列,以便项目可以同时使用Oracle和Mysql。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆