我有一个实体(Car)映射到db(car)中的表 . pojo Car的id是UUID,car table的列类型是uniqueidentifier .
id字段如下所示:
@ID
@Type(type =“uuid-char”)
@GeneratedValue(generator =“uuid2”)
@GeGeneGenerator(name =“uuid2”,strategy =“uuid2”)
@Column(columnDefinition =“uniqueidentifier”,name =“id”)
私人UUID ID;
@NotNull
@Type(type =“uuid-char”)
@ApiModelProperty(required = true,example =“00000000-0000-0000-0000-000000000000”)
@Column(columnDefinition =“uniqueidentifier”,name =“make_id”)
私人UUID makeId;
我采用了@Type(type =“uuid-char”)解决方案,它确实解决了问题 . id已正确保存到db . 但是当做一个getById时 . 似乎hibernate无法通过id找到记录 .
我正在使用spring boot存储库 . 使用本机查询无法通过id找到 .
@Query(value = QUERY_JOIN“WHERE lv.car_makeId =?1”,nativeQuery = true)public List getCar(UUID makeId);
但是,以下情况很好:
public List findByMakeId(UUID makeId);
我确信本机查询没问题 . 也许hibernate正在做一些转换/格式化到UUID?
喜欢:@Type(type = "uuid-char")告诉hibernate . “不要't do anything with the id. just store it as it is' . 但是当使用正确的id进行获取时 . 它在数据库中就是's not able to find it even it' . 所以,我猜它在使用id进行查找之前 . 它再次出错了 . 所以它可以'找到任何想法我在这里做错了什么?