---
title: "mappedBy跟JoinColumn/JoinTable"
author: "east_java"
date: "2010-07-14T10:32:53Z"
tags: []
categories: ["企业架构"]
slug: "mappedby-joincolumn-jointable"
draft: false
lastmod: "2010-07-14T10:32:53Z"
id: 712289
url: "https://japi.iteye.com/blog/712289"
---

在对网站进行升级的时候，hibernate升级为最新的3.5.1版本的时候，发现了有个异常

Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn:\*\*\*\*\*\**

我说明mappedBy跟JoinColumn/JoinTable是互斥的。

在以前的版本中都是可以的，在@ManyToMany 中两个标签都写了。没有发现问题。现在却出现了这个问题~

这是不是hibernate完全支持JPA2的原因呢。。

 

对于mappedBy复习下：

a) 只有OneToOne,OneToMany,ManyToMany上才有mappedBy属性，ManyToOne不存在该属性；

b) mappedBy标签一定是定义在the owned side(被拥有方的)，他指向the owning side(拥有方)；

c) mappedBy的含义，应该理解为，拥有方能够自动维护 跟被拥有方的关系；

 

   当然，如果从被拥有方，通过手工强行来维护拥有方的关系也是可以做到的。

d) mappedBy跟JoinColumn/JoinTable总是处于互斥的一方，可以理解为正是由于拥有方的关联被拥有方的字段存在，拥有方才拥有了被 拥有方。mappedBy这方定义的JoinColumn/JoinTable总是失效的，不会建立对应的字段或者表

[查看全部内容](http://java1995.cn/blog/item/313)