Hi,
I'm trying to map enums and I have to use join tables. Note: I altered names for anonymity
Below is my mapping
for entity:
Code:
@ManyToMany (targetEntity=com.somecompany.SomeEnum.class)
@JoinTable(
name = "entity_enum",
joinColumns = { @JoinColumn(name = "entity_id")},
inverseJoinColumns = { @JoinColumn(name = "enum_id") }
)
private Set<SomeEnum> enums = new HashSet<SomeEnum>();
for enum:
Code:
@Id
@Column(name = "id", unique = true, nullable = false, insertable = false, updatable = false)
private int enumId;
@Column(name = "name", unique = true, nullable = false, insertable = false, updatable = false)
private String enumName;
Above code works and runs selects correctly. However throws an exception
Code:
org.springframework.orm.hibernate3.HibernateSystemException: No default constructor for entity: com.somecompany.SomeEnum; nested exception is org.hibernate.InstantiationException: No default constructor for entity: com.somecompany.SomeEnum
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:95)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:212)
at org.springframework.orm.jpa.JpaAccessor.translateIfNecessary(JpaAccessor.java:152)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:189)
at org.springframework.orm.jpa.JpaTemplate.merge(JpaTemplate.java:276)...............
Caused by: org.hibernate.InstantiationException: No default constructor for entity: com.somecompany.SomeEnum
My enum is derived from a custom base enum. Is my approach correct here? and what are my options to get this working?
Thank you very much in advance.