使用GenericGenerator,Elide不支持IdGeneratorType
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.lanyuanxiaoyao.server;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -31,4 +32,10 @@ public class ServerApplication {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApplicationRunner initialRunner() {
|
||||
return args -> {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
@@ -16,6 +17,7 @@ import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
/**
|
||||
* 组织
|
||||
@@ -31,7 +33,8 @@ import lombok.ToString;
|
||||
@Include
|
||||
public class Department {
|
||||
@Id
|
||||
@SnowflakeId.Generator
|
||||
@GeneratedValue(generator = "snowflakeId")
|
||||
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
|
||||
private Long departmentId;
|
||||
private String departmentName;
|
||||
|
||||
@@ -44,6 +47,7 @@ public class Department {
|
||||
private Set<User> users;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private Department parent;
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
|
||||
@ToString.Exclude
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
|
||||
import com.yahoo.elide.annotation.Include;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
@@ -12,6 +13,7 @@ import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
/**
|
||||
* 组织
|
||||
@@ -27,7 +29,8 @@ import lombok.ToString;
|
||||
@Include
|
||||
public class Organization {
|
||||
@Id
|
||||
@SnowflakeId.Generator
|
||||
@GeneratedValue(generator = "snowflakeId")
|
||||
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
|
||||
private Long organizationId;
|
||||
private String organizationName;
|
||||
|
||||
|
||||
@@ -6,14 +6,15 @@ import com.yahoo.elide.annotation.Include;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
@@ -29,7 +30,8 @@ import lombok.ToString;
|
||||
@Include
|
||||
public class User {
|
||||
@Id
|
||||
@SnowflakeId.Generator
|
||||
@GeneratedValue(generator = "snowflakeId")
|
||||
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
|
||||
private Long userId;
|
||||
private String userCode;
|
||||
private String userNickname;
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
### Create
|
||||
POST http://localhost:8080/jsonapi/organization
|
||||
Content-Type: application/vnd.api+json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"type": "organization",
|
||||
"attributes": {
|
||||
"organizationName": "苹果公司"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Create
|
||||
POST http://localhost:8080/graphql
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"type": "organization",
|
||||
"attributes": {
|
||||
"organizationName": "苹果公司"
|
||||
}
|
||||
"query": "mutation {organization(op: UPSERT, data: {organizationName: \"苹果\"}) {edges {node {organizationId organizationName}}}}"
|
||||
}
|
||||
Reference in New Issue
Block a user