表article的sectorname 是表 sector(主键名也是sectorname)的外键
Article.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.hibernate123.data">
<class
name="Article"
table="ARTICLE"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Topic"
column="TOPIC"
type="string"
length="40"
>
<generator class="assigned"></generator>
</id>
<!-- <property
name="Sectorname"
column="SECTORNAME"
type="string"
not-null="true"
length="40"
/> -->
<many-to-one
name="sector"
column="sectorname
class="com.struts_learn.data.Sector"
/>
</class>
</hibernate-mapping>
代码:
Sector sector = new Sector();
sector.setSectorname("vu5");
sector.setCreateid("aaa");
sector.setCreatetime(new Date());
Article article = new Article();
article.setTopic("fadg5");
article.setSector(sector);
session.save(article);
tx.commit();
log:Hibernate: insert into ARTICLE (SECTORNAME,TOPIC) values (?, ?)
报错:Caused by: java.sql.BatchUpdateException: ORA-01400: 无法将 NULL 插入 ("AB"."ARTICLE"."SECTORNAME")
<!-- <property
name="Sectorname"
column="SECTORNAME"
type="string"
not-null="true"
length="40"
/> -->
把mapping文件注释去掉
代码:
Sector sector = new Sector();
sector.setSectorname("vu5");
sector.setCreateid("aaa");
sector.setCreatetime(new Date());
Article article = new Article();
article.setTopic("fadg5");
article.setSector(sector);
article.setSectorname("vu5");
session.save(article);
tx.commit();
log:Hibernate: insert into ARTICLE (SECTORNAME, sectorname, TOPIC) values (?, ?, ?)
报错:Caused by: java.sql.BatchUpdateException: ORA-00957: 列名重复
搞半天没明白,到底哪配错了...
相关推荐
关联通常包括以下几种类型:单向`one-to-many`关联、双向`one-to-many`关联、`many-to-one`关联以及`one-to-one`关联。 ##### 单向`one-to-many`关联 - **定义**:单向`one-to-many`关联是指一个实体可以拥有多个...
本文将深入探讨Hibernate5中的映射关系,主要包括多对多(Many-to-Many)和一对多(One-to-Many)这两种关系。 一、多对多映射(Many-to-Many) 多对多关系在数据库中表现为两个表之间存在多个连接记录,而在对象...
在 Hibernate 框架中,`cascade` 和 `inverse` 是两个重要的概念,它们主要用于管理对象之间的持久化关系,特别是涉及到一对一(one-to-one)、一对多(one-to-many)和多对多(many-to-many)关系时。这两个属性都...
这种关系在数据库中可以表现为一对多(One-to-Many)或多对一(Many-to-One)的关系。 1. 一对多映射(One-to-Many): 在这种关系中,一个实体(父实体)可以与多个其他实体(子实体)相关联。在Hibernate中,...
而在子类中,通常会有一个反向引用的`<many-to-one>`标签,指向父类。这样,我们就可以通过父类集合获取所有子类实例,或者通过子类的引用找到父类。 接下来,一对一映射(`<one-to-one>`)代表了两个实体之间一对...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
例如,`<one-to-one>`、`<many-to-one>`、`<one-to-many>`和`<many-to-many>`元素分别对应这四种关系。关联映射通常涉及外键的处理和级联操作。 5. 注解方式的Mapping 除了XML映射,Hibernate还支持注解方式的映射...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
Set映射通常通过`<set>`标签来定义,同样可以包含`<key>`和`<one-to-many>`子标签,但不会包含`<index>`标签,因为Set本身不关心元素的插入顺序。 ### Map映射 Map映射是另一种重要的集合映射方式,它可以处理一对...
一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联,涉及...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联,...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 三重关联...
一对多关联(One-to-many Associations) 7.3. 高级集合映射(Advanced collection mappings) 7.3.1. 有序集合(Sorted collections) 7.3.2. 双向关联(Bidirectional associations) 7.3.3. 三重关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 三重关联...
22.2. 双向的一对多关系(Bidirectional one-to-many) 22.3. 级联生命周期(Cascading lifecycle) 22.4. 级联与未保存值(Cascades and unsaved-value) 22.5. 结论 23. 示例:Weblog 应用程序 23.1. 持久化类 ...
22.2. 双向的一对多关系(Bidirectional one-to-many) 22.3. 级联生命周期(Cascading lifecycle) 22.4. 级联与未保存值(Cascades and unsaved-value) 22.5. 结论 23. 示例:Weblog 应用程序 23.1. 持久化类 ...
<one-to-many class="Address" /> ``` - **cascade="all-delete-orphan"**: 这个属性表示级联操作,当删除父对象时,其子对象也会被删除。 - **多对多映射**: - 描述: 通过一个中间表来...