7. Why is @Enumerated(EnumType.STRING) preferred over the default ORDINAL?
- Ordinals change meaning when enum constants are reordered or inserted, corrupting existing data
- Strings are faster to compare
- ORDINAL is not supported by Hibernate
- STRING uses less storage
जवाब देखें
जवाब: Ordinals change meaning when enum constants are reordered or inserted, corrupting existing data
Stored ordinals depend on declaration order, which changes as the code evolves.
पाठ: Basic Types, Enums, Embeddables and Converters
8. Why can IDENTITY ID generation prevent Hibernate from batching inserts?
- IDENTITY IDs are random
- IDENTITY is not supported by JDBC
- Batching requires UUIDs
- The ID is only known after each INSERT executes, so Hibernate must insert immediately on persist
जवाब देखें
जवाब: The ID is only known after each INSERT executes, so Hibernate must insert immediately on persist
Hibernate needs the generated key right away, forcing one INSERT per persist.
पाठ: Primary Keys and ID Generation