Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not support @IdGeneratorType #3340

Open
lanyuanxiaoyao opened this issue Mar 28, 2025 · 0 comments
Open

Can not support @IdGeneratorType #3340

lanyuanxiaoyao opened this issue Mar 28, 2025 · 0 comments

Comments

@lanyuanxiaoyao
Copy link

GenericGenerator is deprecated since hibernate 6.5
I defined the id generator

public class SnowflakeId {
  @IdGeneratorType(IdGenerator.class)
  @Retention(RUNTIME)
  @Target({FIELD, METHOD})
  public @interface Generator {
  }

  public static final class IdGenerator implements IdentifierGenerator {
    @Override
    public Object generate(SharedSessionContractImplementor session, Object object) {
      try {
        return Snowflake.next();
      } catch (Exception e) {
        log.error("Generate snowflake id failed", e);
        throw new RuntimeException(e);
      }
    }
  }
}

And i use it in here

@Getter
@Setter
@ToString
@Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "organization")
@Include
public class Organization {
  @Id
  @SnowflakeId.Generator
  private Long organizationId;
  private String organizationName;
}

And i receive

No id provided, cannot persist

The request

### Create
POST http://localhost:8080/jsonapi/organization
Content-Type: application/vnd.api+json

{
  "data": {
    "type": "organization",
    "attributes": {
      "organizationName": "Apple"
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant