Question about performance which will ultimately result in how I have my table structure set up.
I have Tables A, B, C and D.
Tables B, C and D are mapped to enumerations where all I’m doing is mapping the ordinal value to the enumeration value.
Table B:
ID: 1 String: ENUM_STR_VALUE
ID: 2 String: ENUM_STR_VALUE
Table A has the following schema
Name Null Type
------------------------------
ID Not Null Number(32)
Timestamp Not Null Date
Item_Type Not Null Number (32)
Item2_Type Not Null Number (32)
Item3_Type Not Null Number (32)
In table A…Item_Type, Item2_Type and Item3_Type are the ordinal values of Tables B, C and D respectively.
My problem comes down to how to display things to the user.
In my A.java I have the following code:
@Entity
@Table(name = "a")
public classs A{
private int item_type;
private int item2_type;
private int item3_type;
@Column(name="Item_type")
public nit getItem_type(){
return item_type;
}
Should I just ditch this normalization and make the item_types varchars and leverage the @Enumerated property of Hibernate? Or is there a way I can map back and display the values to the user. The reason being is I want to eventually query on those item types & searching by an int should be faster than a varchar.
Use
@Enumerated(EnumType.ORDINAL), and you’ll have the enum in your entities, mapped as the ordinal int value in the database table. That’s the default mapping for enums, if I’m not mistaken, so you can even remove the@Enumeratedannotation, and Hibernate will persist the enum as an int automatically.PS: you should also respect the Java naming conventions:
item_typeshould beitemType, andgetItem_type()should begetItemType().