不同的数据库使用JPA的不同列类型 [英] Different column types for different databases with JPA

查看:767
本文介绍了不同的数据库使用JPA的不同列类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据使用的数据库,是否有可能定义与JPA不同的列类型?

Is there a posibility to define with JPA different column types depending on the used database?

我需要将id存储为uuid,它必须是可以保证的。那就是问题所在。 PostgreSQL有'uuid',MSSQL'uniqueidentifier'和Oracle没有什么,必须使用'RAW',我想。

I need to store the id as uuid and it must be protable. That's the problem. PostgreSQL has 'uuid', MSSQL 'uniqueidentifier' and Oracle has nothing, there must be used 'RAW', I think.

有任何人的想法,可以帮助我吗?

Have anybody an idea and can help me?

编辑:目前,ids是使用java.util.UUID生成的,并以varchar的形式存储在数据库中。但是由于这种数据类型的性能问题,我想将ids存储为uuid类型。
对于Oracle必须使用RAW类型,因为不存在uuid类型。我如何告诉JPA使用PostgreSQ / MSSQL的uuid类型和Oracle的RAW类型?

Currently the ids are generated with java.util.UUID and stored in the database as varchar. But because of performance problems with that data type I want to store the ids as a uuid type. For Oracle must use the RAW type because no uuid type exist. How can I tell JPA use uuid type with PostgreSQ/MSSQL and RAW type with Oracle?

推荐答案

$ c> SequenceGenerator 。有关详情,请查看此答案。你必须做一个seq。生成器,以确保您不会遇到并发问题。
还要确保设置了一个好/不存在的初始值。

I would use a SequenceGenerator. Check this answer for more details. You will have to make one seq. generator per entity in order to make sure you do not get concurrency problems. Also make sure that you set a good/not existent initial value.

这篇关于不同的数据库使用JPA的不同列类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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