java columnDefinition = "TEXT" 适用于所有类型的数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15135905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
columnDefinition = "TEXT" for all types of databases
提问by akuzma
Locally I use mysql, so when I use
在本地我使用mysql,所以当我使用
@Column(columnDefinition = "TEXT")
Unfortunately application have to run at different databases too, I've not been told which ones just "at all".
不幸的是,应用程序也必须在不同的数据库上运行,我还没有被告知“根本”是哪些数据库。
Is it possible to make something with similar effect, but working at most of databases? How can I achieve it?
是否可以制作具有类似效果的东西,但可以在大多数数据库中使用?我怎样才能实现它?
回答by Pawe? Wyrwiński
What about something like this:
像这样的事情怎么样:
@Lob
private String someString;
I think it's more portable and should effectively generate TEXT or LONGTEXT data type.
我认为它更便携,应该有效地生成 TEXT 或 LONGTEXT 数据类型。
回答by Salim Hamidi
If you use @LOB you'll have ORA-00932 exception with SQL containing DISTINCT (http://ora-00932.ora-code.com/)
如果您使用@LOB,您将遇到 ORA-00932 异常,SQL 包含 DISTINCT ( http://ora-00932.ora-code.com/)
I think that the solution depends on the bytes size of your string. If its < 4000 bytes, you can try using @Column(name = "...", length = 4000)
我认为解决方案取决于字符串的字节大小。如果它 < 4000 字节,您可以尝试使用 @Column(name = "...", length = 4000)
I suggest 4000 bytes for DB comptibility reason :
出于数据库兼容性的原因,我建议使用 4000 字节:
- In oracle Oracle 8 to Oracle 11g, type VARCHAR2 max size is 4000 (A4 page format)
- In DB2 10 for z/OS, type VARCHAR max size is 32704
- In SQL Server 2012, type TEXT max size is 2,147,483,647 bytes
- 在oracle Oracle 8 到Oracle 11g 中,类型VARCHAR2 max size 为4000(A4 页面格式)
- 在 DB2 10 for z/OS 中,类型 VARCHAR 最大大小为 32704
- 在 SQL Server 2012 中,键入 TEXT 最大大小为 2,147,483,647 字节
回答by EHoltz
I had the same problem and it was resolved only adding a parameter to MySQL Url on application.properties:
我遇到了同样的问题,仅在 application.properties 上向 MySQL Url 添加一个参数就解决了:
spring.datasource.url=jdbc:mysql://localhost:3306/database?jdbcCompliantTruncation=false
The parameter is jdbcCompliantTruncation=false
参数为 jdbcCompliantTruncation=false
Looks like a workaround but only it works...
看起来像一种解决方法,但只有它有效......