Java 8
Spring 4.3
here class Folder:
@Indexed(index = "Folder")
public class Folder<P extends Folder> extends AbstractEntity {
}
And it's parent:
@MappedSuperclass
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public abstract class AbstractEntity implements JsonSerializable, Serializable, Cloneable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@JsonProperty("_id")
private int id;
protected AbstractEntity() {
}
Here my publisher:
public class MyPublisher {
@Override
public void nextStep() {
getApplicationEventPublisher().publishEvent(new ProcessEvent());
}
}
Here event listener
public class MyClass {
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
@Autowired
private SomeDao someDao;
@EventListener
public void handleProcessEvent(ProcessEvent processEvent) {
LOGGER.info("handleProcessEvent: processEvent = {}", processEvent);
List<GatewayDiversityLink> gatewayDiversityLink = someDao.findAll(); // error herer!!!
LOGGER.info("handleProcessEvent: gatewayDiversityLink = {}", gatewayDiversityLink);
}
}
But throw exception when call method handleProcessEvent
Error:
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: com.myproject.Folder; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.myproject.Folder
at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:190) ~[spring-orm-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.orm.hibernate4.HibernateExceptionTranslator.convertHibernateAccessException(HibernateExceptionTranslator.java:57) ~[spring-orm-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.orm.hibernate4.HibernateExceptionTranslator.translateExceptionIfPossible(HibernateExceptionTranslator.java:44) ~[spring-orm-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:209) ~[spring-tx-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at com.sun.proxy.$Proxy241.findByElementId(Unknown Source) ~[?:?]