简体   繁体   English

无法添加记录,Java,休眠

[英]cant add record, Java, Hibernate

I have table with data. 我有数据表。 for instance I have table user_books. 例如我有表user_books。

id_user | id_user | id_book id_book

I am receiving each request all set of books that tied to current user. 我正在收到每个请求,所有与当前用户相关的书籍集。 (1, 2), (1, 7) So I delete all record from user_books for current user and reinsert them. (1,2),(1,7)因此,我从user_books中删除当前用户的所有记录,然后重新插入它们。

And problem is I keep getting errors from Hibernate, removal successful but I can reinsert them because of this warnings. 问题是我不断从Hibernate中获取错误,删除成功,但是由于此警告,我可以重新插入它们。

2013-04-18 15:48:40,787 INFO : org.hibernate.event.internal.DefaultDeleteEventListener - HHH000114: Handling transient entity in delete processing
2013-04-18 15:48:40,788 INFO : org.hibernate.event.internal.DefaultDeleteEventListener - HHH000114: Handling transient entity in delete processing
2013-04-18 15:48:40,788 INFO : org.hibernate.event.internal.DefaultDeleteEventListener - HHH000114: Handling transient entity in delete processing

Any idea where to look? 知道在哪里看吗? Why I cant reinsert books with userBook.add( ... ) in Java Hibernate environment ? 为什么我不能在Java Hibernate环境中使用userBook.add(...)重新插入书籍?

Probably this arise due not correct your persistent object annotation. 可能是由于不正确的持久对象注释而引起的。 I guess it's connect to annotation of your filed and Cascade Type. 我想它连接到您的字段和级联类型的注释。

Try something like this: 尝试这样的事情:

@ManyToMany(fetch = FetchType.EAGER, cascade=CascadeType.PERSIST)

I think Mapping relationship is not defind properly So you must defind mapping relationship in your POJO.hbm.xml class 我认为映射关系未正确定义,因此您必须在POJO.hbm.xml类中定义映射关系

Try as below, 尝试如下

<many-to-one class="VO.regVO" name="uid" cascade="delete"></many-to-one>

here many-to-one relationship is defind with mapping the regVO POJO class Primarykey 'uid' is now for this current POJO class is work as Foreignkey and cascade 'delete' will about deletion of one object from the database causing deletion of other (dependent) objects 在这里,通过映射regVO POJO类来确定多对一关系。主键'uid'现在适用于此当前POJO类,因为Foreignkey和级联'delete'会从数据库中删除一个对象,导致另一个对象的删除(取决于)物件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM