---
title: "Hibernate异常(1)：Associations marked as mappedBy must not define database mappings"
author: "mfan"
date: "2013-03-19T16:18:00Z"
tags: []
categories: ["企业架构"]
slug: "hibernate-1-associations-marked-as-mappedby-must-not-define-database-mappings"
draft: false
lastmod: "2013-03-19T16:18:00Z"
id: 1831930
url: "https://mfan.iteye.com/blog/1831930"
---

**异常：Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn**

hibernate升级到3.5版本或者更新的版本时出现这样的异常，举个例子：

 

private List&lt;User&gt; user;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "dept")

@JoinColumn(name = "dept\_id")

public List&lt;User&gt; getUser() {

    return user;

}

public void setUser(List&lt;User&gt; user) {

    this.user = user;

}

 

在3.5版本之后@JoinColumn与mappingBy是互斥的，而在更早版本的hibernate是允许这两个互相存在。所以升级到hibernate3.5之后，mappBy="dept",就应该去掉，正确的写法如下：

private List&lt;User&gt; user;

@OneToMany(fetch = FetchType.LAZY)

@JoinColumn(name = "dept\_id")

public List&lt;User&gt; getUser() {

    return user;

}

public void setUser(List&lt;User&gt; user) {

    this.user = user;

}