hibernate save数据的时候报错:ids for this class must be manually assigned before calling save()...

本文解决了一个关于Eclipse使用JPA工具自动生成实体类时遇到的问题:ID未设置为自增且类型默认为String。通过将ID类型改为Integer并移除get和set方法,实现了自动递增。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个错误是因为eclipse 

这种jpatools 自动生成的实体类内没把id 设置为自增,还有id的值在生成的时候默认为string 即使加上了也所以无法自增 ,所以还需要把string 换成Integer   ,因为是自增所以无需送数,把后边的getid  setid 删除掉酒可以

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
//    private String id;
private Integer id;

 

//    public Integer  getId() {
 //       return this.id;
//    }

//    public void setId(String id) {
//        Integer it =Integer.valueOf(id);
//        //int i = it.intValue();  
//        this.id = it;
//    }

 设置自动model时 

 

转载于:https://www.cnblogs.com/zuochanzi/p/9323308.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值