I have an enum class that creates a table called ROLE when using the Hibernate3 Maven plugin:
@Entity
@Table(name = "ROLE")
public enum UserRole {
ADMIN("ADMIN"),
DEVELOPER("DEVELOPER"),
CLIENT("CLIENT");
private long id;
private String role;
UserRole(String role) {
this.role = role;
}
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "ROLE", nullable = false)
@Enumerated(EnumType.STRING)
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
The table is empty when created by the Maven plugin. I’m not sure if I’m doing this right since I have no experience with using enums with Hibernate. What should I do to have the table auto-populated with the values, ADMIN, DEVELOPER, and CLIENT upon creation by the plugin? Is that even possible?
No, it’s not possible using the Hibernate3 Maven plugin.
You’ll need to ensure that your application, on startup, will persist these values into the table. That way, you could be assured of the presence of these values before performing any processing.