I tried to populate the database tables with random data and using Hibernate.
But my code fills in incompatible data in the tables (not completely incompatible - this is the index of this element declared in enum, for example: at ApartmentState - FREE is the first element that it sets in the corresponding column, index is 0. But I want to put or FREE as enum or as a string).
I could not understand why this was happening.
Here is the code snippet:
private List<Apartment> generateApartments() { for (int i = 1; i <= 3; i++) { for (int j = 2; j <= 5; j++) { Apartment apartment = new Apartment(); // fill apartment apartment.setRoomName(generateRoomName()); apartment.setPricePerHour(generatePrice()); apartment.setApartmentState(FREE); apartment.setRating(getDesiredRating(j)); apartment.setSleepPlaces(getDesiredPlaces(i)); apartment.setActive(true); // save apartment apartments.add(apartment); } } return apartments; } private Apartment.SleepPlaces getDesiredPlaces(int i) { switch (i) { case 1: return ONE_PLACE; case 2: return TWO_PLACES; case 3: return THREE_PLACES; } return ONE_PLACE; } private Apartment.StarRating getDesiredRating(int j) { switch (j) { case 2: return TWO_STARS; case 3: return THREE_STARS; case 4: return FOUR_STARS; case 5: return FIVE_STARS; } return TWO_STARS; }
I need to fill out some enumeration values ββin the table, like rating (2, 3, 4) and places of sleep (1, 2 ..).
But this puts some incorrect data in the table.
Here are the contents on the desktop:

Why does it only put an index, and not as a string or as an enumeration.
How can I restore this to the desired value in the future.
Here is an excerpt from the Apartment class:
@Entity @Table(name = "Apartments") public class Apartment extends AbstractEntity implements Comparable<Apartment> { private Integer id; private String roomName; private Double pricePerHour; private ApartmentState apartmentState; private StarRating rating; private SleepPlaces sleepPlaces; private Boolean active; public enum ApartmentState { FREE, REQUESTED, BOOKED, LIVED, CLEANING, PROCESSING } public enum StarRating { TWO_STARS("2 stars"), THREE_STARS("3 stars"), FOUR_STARS("4 stars"), FIVE_STARS("5 stars"); private String description; private StarRating(String description) { this.description = description; } public String getDescription() { return description; } } public enum SleepPlaces { ONE_PLACE("1 person"), TWO_PLACES("2 persons"), THREE_PLACES("3 persons"), FOUR_PLACES("4 persons"); private String count; private SleepPlaces(String count) { this.count = count; } public String getCount() { return count; } }
For me it is best to put enum as enum (possibly in MySql workbench) or as a string (and use name() and valueOf() from the Enum class).
But how to implement it with sleep mode.
How to solve this problem?