Reputation: 35
There is an Entity - 'Parameter' which has an enum filed - 'ValueType'
@Data
@Entity
public class Parameter {
@Id
@Column(name = "id", unique = true, nullable = false)
private UUID id;
@Enumerated(EnumType.String)
private ValueType type;
}
public enum ValueType {
STRING,
NUMBER;
}
What is the best practice to make the 'ValueType' to be a separate table where these tables are related with OneToOne relationship
Upvotes: 0
Views: 390
Reputation: 471
As a best practice you wouldn't use a separate table, if you need an enum - your approach looks very good.
If you want to store the values in a separate table, you need to create it as an entity (maybe with only one field, the enum value, which is the primary key also) and link it with ManyToOne / OneToMany. OneToOne doesn't seem to make a lot of sense. (you may look at Bootify.io to do any of this two variants)
Upvotes: 1