Server: JBoss6 Technology: JPA 2, EJB 3.1
I have an entity which has an embeddable class that encapsulates a common group of fields, to be used many times on the same entity, as shown bellow:
@Entity
@Table(name = "form_x")
public class FormX extends SurveyForm implements Serializable {
private static final long serialVersionUID = 1321874423212L;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="data", column = @Column(name = "field01")),
@AttributeOverride(name="metadata", column = @Column(name = "field01_metadata")),
@AttributeOverride(name="metadataComment", column = @Column(name = "field01_metadata_comment"))
})
private SingleSelectionQuestion<Agreement> field1;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="data", column = @Column(name = "field02")),
@AttributeOverride(name="metadata", column = @Column(name = "field02_metadata")),
@AttributeOverride(name="metadataComment", column = @Column(name = "field02_metadata_comment"))
})
private SingleSelectionQuestion<Frequency> field2;
...getters and setters...
}
@Embeddable
public class SingleSelectionQuestion<T> implements Serializable {
private static final long serialVersionUID = -7389172046941228140L;
@Enumerated(EnumType.STRING)
private T data;
@Enumerated(EnumType.STRING)
private QuestionMetaData metadata;
private String metadataComment;
...getters and setters...
}
Where Agreement and Frequency are enumerations.
But when I try to save this form (entityManage#merge on an already persisted entity) I get a ClassCastException, as can be seen in the stacktrace bellow:
Caused by: javax.transaction.RollbackException: ARJUNA-16053 Could not commit transaction.
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1170) [:6.0.0.Final]
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:119) [:6.0.0.Final]
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75) [:6.0.0.Final]
at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:82) [:0.0.1]
... 110 more
Caused by: javax.persistence.PersistenceException: error during managed flush
at org.hibernate.ejb.AbstractEntityManagerImpl$3.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1072) [:3.6.0.Final]
at org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:122) [:3.6.0.Final]
at org.hibernate.transaction.synchronization.HibernateSynchronizationImpl.beforeCompletion(HibernateSynchronizationImpl.java:51) [:3.6.0.Final]
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:97) [:6.0.0.Final]
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:274) [:6.0.0.Final]
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:94) [:6.0.0.Final]
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:159) [:6.0.0.Final]
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1158) [:6.0.0.Final]
... 113 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum
at org.hibernate.type.EnumType.nullSafeSet(EnumType.java:150) [:3.6.0.Final]
at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:146) [:3.6.0.Final]
at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:336) [:3.6.0.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2166) [:3.6.0.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2540) [:3.6.0.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2476) [:3.6.0.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2803) [:3.6.0.Final]
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113) [:3.6.0.Final]
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) [:3.6.0.Final]
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265) [:3.6.0.Final]
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185) [:3.6.0.Final]
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) [:3.6.0.Final]
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) [:3.6.0.Final]
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) [:3.6.0.Final]
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383) [:3.6.0.Final]
at org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:117) [:3.6.0.Final]
... 119 more
Why am I getting this error even using the @Enumerated annotation on the fields of the SingleSelectionQuestion class?
Anyone has a clue what am I doing wrong?
Thanks.