Skip to content

主键生成注解 #97

@icexmoon

Description

@icexmoon

Hibernate 6.5 开始已经弃用GenericGenerator注解,推荐使用IdGeneratorType

@IdGeneratorType(com.blinkfox.fenix.id.SnowflakeIdGenerator.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({METHOD, FIELD})
public @interface SnowflakeIdGenerator {
}

实体类:

@Table(name = "tb_book")
@Entity
@Data
@NoArgsConstructor
public class Book {
    @Id
    @SnowflakeIdGenerator
    private Long id;
    @Column(length = 20)
    private String name;

    public Book(String name) {
        this.name = name;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions