CosId icon indicating copy to clipboard operation
CosId copied to clipboard

如何集成到hibernate使用?

Open meimosor opened this issue 7 months ago • 0 comments

我再hibernate自定义了一个ID生成器,如何在替换这里的逻辑使CosId的雪花ID生成器生效?

public class YuIdGenerator implements IdentifierGenerator {

    static SnowFlake snowFlake;

    static {
        snowFlake = new SnowFlake(1, 1);
    }

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        return snowFlake.nextId();
    }
}
import jakarta.persistence.Id;
/**
* 主键
*/
@Id
@GenericGenerator(name = "yu_id", strategy = "com.xxx.common.jpa.xxx.YuIdGenerator")
@GeneratedValue(generator = "yu_id")
private Long id;

meimosor avatar Jul 17 '24 02:07 meimosor