我需要坚持使用多层嵌套子节点的大型复杂实体。数据来自xml文件,该文件从xml解组为java。坚持不懈是因为我需要一次解决一个问题。此外,在尝试保留数据之前,我需要验证数据。
现在,我只是试图坚持它,但是persist命令只是一行代码。我如何调试它以找出一行代码失败的位置?我可以在调试模式下运行eclipse,但如果我只有在调试器中停止的一行代码,我将不得不做很多挖掘实体的内容。 有没有更好的方法来调试这个,所以我可以精确定位抛出错误的精确位置而不是挖掘密集嵌套的实体结构?这是我的代码:
public Long saveToDatabase(SomeDocument cd){
final EntityManager saveManager = entityManagerFactory.createEntityManager();
saveManager.getTransaction().begin();
saveManager.persist(cd);
saveManager.getTransaction().commit();
saveManager.close();
//After the object is saved, we can get the generated id:
final Long id = cd.getHjid();
return id;
}
作为参考,我将在下面附上当前的堆栈跟踪。它表明数据中有一个Boolean
实体无法转换为特定的应用程序定义的数据类型。问题是cd
实体中至少有75个位置具有错误消息中提到的特定数据类型。 所以这里的堆栈跟踪并不重要。我想要的是嵌套实体结构的深层内容的更细粒度的视图,而不必手动摆动eclipse调试视图的变量选项卡。
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: Unable to resolve entity name from Class [java.lang.Boolean] expected instance/subclass of [org.jvnet.hyperjaxb3.ejb.tests.pocustomized.II]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1154)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678)
at productionmain.DataFunctions.saveToDatabase(DataFunctions.java:261)
at productionmain.Main.main(Main.java:21)
Caused by: org.hibernate.HibernateException: Unable to resolve entity name from Class [java.lang.Boolean] expected instance/subclass of [org.jvnet.hyperjaxb3.ejb.tests.pocustomized.II]
at org.hibernate.tuple.entity.PojoEntityTuplizer.determineConcreteSubclassEntityName(PojoEntityTuplizer.java:360)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassEntityPersister(AbstractEntityPersister.java:3941)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1494)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:202)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:531)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:102)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:799)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:791)
at org.hibernate.engine.EJB3CascadingAction$1.cascade(EJB3CascadingAction.java:48)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
at org.hibernate.engine.Cascade.cascade(Cascade.java:161)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:450)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:282)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672)
... 2 more
答案 0 :(得分:2)
有几件事情需要研究。