Код: Выделить всё
[PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Column 'env_id' is duplicated in mapping for entity 'com.sample.app.entity.GroupResourceAllocation' (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)
[img]https:// i.sstatic.net/GPykl7YQ.png[/img]
ниже приведены реализованные классы сущностей:
Код: Выделить всё
import jakarta.persistence.*;
import lombok.Data;
@Entity
@Data
public class Environment {
@Id
@Column(name = "env_id")
private Long envId;
private String name;
private String status;
}
Код: Выделить всё
import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;
@Entity
@Data
public class User {
@EmbeddedId
private UserId id;
private LocalDateTime createdAt;
private String status;
@MapsId("envId")
@ManyToOne
@JoinColumn(name = "env_id")
private Environment environment;
}
Код: Выделить всё
import jakarta.persistence.Embeddable;
import lombok.Data;
import java.io.Serializable;
import java.util.Objects;
@Data
@Embeddable
public class UserId implements Serializable {
private Long envId;
private Long empId;
}
Код: Выделить всё
import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;
@Entity
@Data
public class Group {
@EmbeddedId
private GroupId id;
private LocalDateTime createdAt;
private String status;
@MapsId("envId")
@ManyToOne
@JoinColumn(name = "env_id")
private Environment environment;
}
Код: Выделить всё
import jakarta.persistence.Embeddable;
import lombok.Data;
import java.io.Serializable;
import java.util.Objects;
@Data
@Embeddable
public class GroupId implements Serializable {
private Long envId;
private String groupName;
}
Код: Выделить всё
import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;
@Entity
@Data
public class Resource {
@EmbeddedId
private ResourceId id;
private LocalDateTime createdAt;
private String status;
@MapsId("envId")
@ManyToOne
@JoinColumn(name = "env_id")
private Environment environment;
}
Код: Выделить всё
import jakarta.persistence.Embeddable;
import lombok.Data;
import java.io.Serializable;
import java.util.Objects;
@Data
@Embeddable
public class ResourceId implements Serializable {
private Long envId;
private String resourceName;
}
Код: Выделить всё
import jakarta.persistence.*;
import lombok.Data;
@Entity
@Data
public class GroupResourceAllocation {
@EmbeddedId
private GroupResourceAllocationId id;
private String status;
@MapsId("envId")
@ManyToOne
@JoinColumn(name = "env_id", insertable = false, updatable = false)
private Environment environment;
@MapsId("groupName")
@ManyToOne
@JoinColumns({
@JoinColumn(name = "env_id", insertable = false, updatable = false),
@JoinColumn(name = "group_name")
})
private Group group;
@MapsId("resourceName")
@ManyToOne
@JoinColumns({
@JoinColumn(name = "env_id", insertable = false, updatable = false),
@JoinColumn(name = "resource_name")
})
private Resource resource;
}
Код: Выделить всё
import jakarta.persistence.Embeddable;
import lombok.Data;
import java.io.Serializable;
import java.util.Objects;
@Data
@Embeddable
public class GroupResourceAllocationId implements Serializable {
private Long envId;
private String groupName;
private String resourceName;
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... g-boot-jpa