DarkBot
DarkBot

Reputation: 43

DB design. Using Status table

I was told that storing statuses as a table is better than creating Enums for my statuses. So I created a table for CompliantStatus. My question is where to insert these statuses and how to use them in my services classes. When I was using enums I was simply accesing the class Ex: Status.(myStatus). But how can I do this using status entity?

@Table
@Entity
@Getter
@Setter

public class ComplaintStatus extends LookupEntity{

}



@Data
@MappedSuperclass
@EqualsAndHashCode(callSuper = false)
public class LookupEntity extends BaseEntity{

    @Column
    private String nameAr;

    @Column
    private String nameEn;

    @Column
    private Long code;
}


Upvotes: 0

Views: 72

Answers (1)

Sergio
Sergio

Reputation: 36

For creating the statuses in your database you need to use a DB change management framework, such as Liquibase.

And when you define the status column in another data object you can do something like:

@OneToOne(fetch = FetchType.EAGER, optional = false) 
@JoinColumn(name = "statusid", nullable = false, insertable = false, updatable = false)
private ComplaintStatus status;

Upvotes: 1

Related Questions