简体   繁体   English

JSR-310年映射到MySQL中的TINYBLOB

[英]JSR-310 Year mapped to TINYBLOB in MySQL

Well, mine is a silly question. 好吧,我的问题很愚蠢。

With Hibernate 5.1 (5.2 the same) my Year column is mapped to tinyblob instead of the intuitive int column one would expect. 使用Hibernate 5.1(5.2相同),我的Year列映射到tinyblob而不是人们期望的直观int列。 Other JSR-310 columns are successfully mapped. 其他JSR-310列已成功映射。

Eg 例如

@Column(name = "ANNO_PROTOCOLLO", nullable = true)
protected Year annoProtocollo;

@Column(name = "CREATED", nullable = false, updatable = false, insertable = true)
protected LocalDateTime created = LocalDateTime.now();

The first column is mapped to tinyblob but the second is correctly mapped to datetime which is the SQL standard for such values. 第一列映射到tinyblob但第二列正确映射到datetime ,这是此类值的SQL标准。

Again, my question is silly because nothing prevents me to declare that Year column as an int, but I wanted to understand the reason behind this and if there is a way that takes less than 3 lines of code to map Year to int. 再次,我的问题很愚蠢,因为没有什么可以阻止我将Year列声明为int,但是我想了解其背后的原因,以及是否有一种方法可以用不到3行代码将Year映射到int。 Since I need to work on multiple databases, I cannot accept @Column(columnDefinition) and if that is the only solution I will just use Integer and live with that, as I did before 由于我需要处理多个数据库,因此我不能接受@Column(columnDefinition) ,如果这是唯一的解决方案,我将像以前一样使用Integer并使用它

The simple reason is that they didn't provide a specific mapping for Year , so you're getting the default mapping of object serialization to/from bytes, ie a BLOB. 原因很简单,因为它们没有为Year提供特定的映射,所以您将获得对象串行化到字节或从字节提取的默认映射,即BLOB。

You can implement a custom type to provide a mapping. 您可以实现自定义类型以提供映射。
See Hibernate Domain Model Mapping Guide - Custom BasicTypes . 请参见《 Hibernate域模型映射指南-自定义BasicTypes》

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM