стол http://1.z9ls.com/t6/701/1555244797x1822611239.png
одна таблица - статья, другая - категория:
article: article_id, article_title, article_category_id ... и article_category_id
это внешний ключ и ссылки category_id таблицы category.
Когда я удаляю артикул: object references an unsaved transient instance - save the transient instance before flushing: com.wjh.blog.domain.Category
Внимание: когда я УДАЛЯЮ статью, но не вставляю и не обновляю.
//I have already use the @Transactional
//this is the code of ArticleDaoImpl.java
@Override
public void delete(Long article_id) {
Article article = new Article();
article.setArticle_id(article_id);
this.getHibernateTemplate().delete(article);
}
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.wjh.blog.domain.Category" table="category">
<id name="category_id" column="category_id">
<generator class="native"/>
</id>
<property name="category_name" column="category_name"/>
<property name="category_parent_id" column="category_parent_id"/>
<set name="category_articles" inverse="true">
<key column="article_category_id"></key>
<one-to-many class="com.wjh.blog.domain.Article"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.wjh.blog.domain.Article" table="article" >
<id name="article_id" column="article_id">
<generator class="native"/>
</id>
<property name="article_title" column="article_title"/>
<property name="article_content" column="article_content"/>
<property name="article_time" column="article_time"/>
<property name="article_pic" column="article_pic"/>
<property name="article_desc" column="article_desc"/>
<!--category-->
<many-to-one name="article_category" class="com.wjh.blog.domain.Category"
column="article_category_id" cascade="save-update,persist" ></many-to-one>
</class>
</hibernate-mapping>