java sqlserver uuid_java中的UUID和sql server中的uniqueidentifier的问题

我有一个实体(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进行查找之前 . 它再次出错了 . 所以它可以'找到任何想法我在这里做错了什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值