Answer the question
In order to leave comments, you need to log in
Error "No identifier specified for entity" how is it treated?
There is a database:
CREATE TABLE language (
"code" char(2) PRIMARY KEY, -- стандарт ISO 639-1
"laguage" varchar(24) NOT NULL UNIQUE -- Название на локальном (родном) языке
);
-- Основные языки сайта
INSERT INTO language VALUES
('en', 'English'),
('ru', 'Русский'),
('uk', 'Українська');
CREATE TABLE country (
"code" smallint PRIMARY KEY, -- ISO 3166-1 numeric
"locality" varchar(64), -- название страны (на родном языке страны)
"alpha_2" char(2) NOT NULL UNIQUE, -- ISO 3166-1 alpha-2
"alpha_3" char(3) NOT NULL UNIQUE -- ISO 3166-1 alpha-3
);
CREATE TABLE country_translate (
"language_code" char(2) REFERENCES language,
"country_code" smallint REFERENCES country,
"translate" varchar NOT NULL
);
@Data @Entity @Table
public class Language {
@Id
@Column(columnDefinition = "CHAR(2)")
private String code; // Код языка по стандарту ISO 639-1
@Column(unique = true, nullable = false, length = 24)
private String laguage; // Локальное название языка
}
@Data @Entity @Table
public class Country {
@Id
@Column(columnDefinition = "smallint")
private int code; // ISO 3166-1 numeric
@Column(nullable = false, unique = true, length = 64)
private String locality; // Локальное название страны (на родном языке страны)
@Column(columnDefinition = "char(2)", unique = true, nullable = false)
private String codeAlpha2; // ISO 3166-1 alpha-2
@Column(columnDefinition = "char(3)", unique = true, nullable = false)
private String codeAlpha3; // ISO 3166-1 alpha-3
@OneToMany(mappedBy = "country")
private Set<CountryTranslate> translate = new HashSet<>();
}
@Data @Entity @Table
public class CountryTranslate {
@ManyToOne
private Language language;
@ManyToOne
// @JsonIgnoreProperties("translate")
private Country country;
@Column(nullable = false)
private String translate;
}
@IdClass
, but honestly I didn’t understand anything because there @EmbeddedId
is @MapsId
no sensible material in Russian
Answer the question
In order to leave comments, you need to log in
It was necessary to make a composite key.
@Data @Entity @Table
public class Country {
@Id
@Column(columnDefinition = "smallint")
private int code; // ISO 3166-1 numeric
@Column(nullable = false, unique = true, length = 64)
private String locality; // Локальное название страны (на родном языке страны)
@Column(columnDefinition = "char(2)", unique = true, nullable = false)
private String codeAlpha2; // ISO 3166-1 alpha-2
@Column(columnDefinition = "char(3)", unique = true, nullable = false)
private String codeAlpha3; // ISO 3166-1 alpha-3
@OneToMany(mappedBy = "countryTranslatePK.country")
private Set<CountryTranslate> translate = new HashSet<>();
}
...
@Data @Entity @Table
public class Language {
@Id
@Column(columnDefinition = "CHAR(2)")
private String code; // Код языка по стандарту ISO 639-1
@Column(unique = true, nullable = false, length = 24)
private String laguage; // Локальное название языка
}
...
@Data @Entity @Table
public class CountryTranslate {
@EmbeddedId
private CountryTranslatePK countryTranslatePK;
@Column(nullable = false)
private String translate;
}
...
@Data @Embeddable
public class CountryTranslatePK implements Serializable {
@ManyToOne @JoinColumn(name="language_code")
private Language language;
@ManyToOne @JoinColumn(name="country_code")
private Country country;
}
CountryTranslate is missing a field with an annotation @Id
.
Everyone @Entity
should have it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question