EnumType.Ordinal vs EnumType.STRING

Posted on Leave a commentPosted in Hibernate

How to Map Enum to hibernate class: @Entity @table(“d_user_group”) public class UserGroup { @Enumerated(EnumType.STRING) @Column(name=”user_group_status”) private UserGroupStatusEnum userGroupStatus; public enum UserGroupStatusEnum{ Active, Draft; } } In the case above we have a table d_user_group, that will have a column user_group_status, that only accepts Enum as a parameter. If you specify EnumType.String it will store the […]

Hibernate – A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

Posted on Leave a commentPosted in Hibernate

Hibernate Class: @Entity @Table(name=”Person”) public class Person{ @OneToMany(mappedBy = “children”, cascade = CascadeType.ALL, orphanRemoval = true) private Set<Child> children; … //setters and getters }   Error occurs when in controller you are trying to set it to null instead of clearing the set/list, the following pseudo code will throw an exception as “A collection with […]