Hibernate.Envers:@Audited at @ManyToOne 抛出异常

发布于 2024-09-14 22:09:01 字数 2211 浏览 5 评论 0原文

有以下两个类,通过 Manytoone-annotation 相关:

@Entity
public class Firma {
  @Id
  @GeneratedValue
  private int id;

  @OneToMany(mappedBy = "firma")
  private List<Mitarbeiter> mitarbeiter;

  //getter und setter methods
}

@Entity
public class Mitarbeiter {
  @Id
  @GeneratedValue
  private int id;

  @Audited()
  private String name;

  @ManyToOne
  @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
  private Firma firma;

  //getter und setter methods
}

如果我删除 @Audited(...) 然后保存 Mitarbeiter,一切正常。但是使用 @Audited-Annotation 会引发以下异常:

java.lang.NoSuchMethodError: org.hibernate.persister.entity.EntityPersister.getIdentifier(Ljava/lang/Object;Lorg/hibernate/engine/SessionImplementor;)Ljava/io/Serializable; org.hibernate.envers.tools.Tools.getIdentifier(Tools.java:67) org.hibernate.envers.tools.Tools.entitiesEqual(Tools.java:50) org.hibernate.envers.entities.mapper.relation.ToOneIdMapper.mapToMapFromEntity(ToOneIdMapper.java:71) org.hibernate.envers.entities.mapper.MultiPropertyMapper.map(MultiPropertyMapper.java:86) org.hibernate.envers.synchronization.work.ModWorkUnit。(ModWorkUnit.java:48) org.hibernate.envers.event.AuditEventListener.onPostUpdate(AuditEventListener.java:165) org.hibernate.action.EntityUpdateAction.postUpdate(EntityUpdateAction.java:200) org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:179) org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263) org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168) org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027) org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365) org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)

有什么问题?`

非常感谢! 李维斯

there are following two classes, related by manytoone-annotation:

@Entity
public class Firma {
  @Id
  @GeneratedValue
  private int id;

  @OneToMany(mappedBy = "firma")
  private List<Mitarbeiter> mitarbeiter;

  //getter und setter methods
}

@Entity
public class Mitarbeiter {
  @Id
  @GeneratedValue
  private int id;

  @Audited()
  private String name;

  @ManyToOne
  @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
  private Firma firma;

  //getter und setter methods
}

If i remove the @Audited(...) and then save a Mitarbeiter, all works ok. But with the @Audited-Annotation following exception is thrown:

java.lang.NoSuchMethodError:
org.hibernate.persister.entity.EntityPersister.getIdentifier(Ljava/lang/Object;Lorg/hibernate/engine/SessionImplementor;)Ljava/io/Serializable;
org.hibernate.envers.tools.Tools.getIdentifier(Tools.java:67)
org.hibernate.envers.tools.Tools.entitiesEqual(Tools.java:50)
org.hibernate.envers.entities.mapper.relation.ToOneIdMapper.mapToMapFromEntity(ToOneIdMapper.java:71)
org.hibernate.envers.entities.mapper.MultiPropertyMapper.map(MultiPropertyMapper.java:86)
org.hibernate.envers.synchronization.work.ModWorkUnit.(ModWorkUnit.java:48)
org.hibernate.envers.event.AuditEventListener.onPostUpdate(AuditEventListener.java:165)
org.hibernate.action.EntityUpdateAction.postUpdate(EntityUpdateAction.java:200)
org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:179)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)

What's the problem?`

Thanks so much!
Levis

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守望孤独 2024-09-21 22:09:01

检查运行时使用的 jar 与用于编译代码的 jar 的版本是否相同。

如果它不能解决您的问题(很可能不会),请将 Hibernate Tools 提供的 jar 放在您的类路径中,而不是您现在正在使用的 jar。从技术上讲,如果您使用的其中一个 jar 包含使用另一个 jar 的特定版本编译的类(该版本与类路径中的版本不同),则可能会发生这种情况。

Check that the jars used at runtime are at the same version than the jars used to compile your code.

If it doesn't solve your problem (and most likely, it won't), put the jars provided with Hibernate Tools in your classpath, instead of the ones you're using right now. Technically, thi can happen if one of the jar you're using contains classes that have been compiled using a specific version of another jar, which differs from the one you have in your classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文