---
title: "Hibernate annotation insertable = false, updatable = false"
author: "taoshi"
date: "2015-01-07T11:43:38Z"
tags: []
categories: ["企业架构"]
slug: "hibernate-annotation-insertable-false-updatable-false"
draft: false
lastmod: "2015-01-07T11:43:32Z"
id: 2173522
url: "https://taoshi.iteye.com/blog/2173522"
---

在做一对多关系映射时，比如一个产品对应多个积分方案

分别为 product 和 interalplan


在PLAN对象中将属性product 和 productID 映射同一张表中同一字段，可以减少相关查询

必须设置insertable = false, updatable = false

@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "INTEGRAL_ID", unique = true, nullable = false, insertable = false, updatable = false)
	public TbParmngIntegralPlan getTbParmngIntegralPlan() {
		return this.tbParmngIntegralPlan;
	}

	public void setTbParmngIntegralPlan(
			TbParmngIntegralPlan tbParmngIntegralPlan) {
		this.tbParmngIntegralPlan = tbParmngIntegralPlan;
	}

	@Column(name = "INTEGRAL_ID")
	public String getIntergralID() {
		return intergralID;
	}

	public void setIntergralID(String intergralID) {
		this.intergralID = intergralID;
	}
在保存值时需要setIntegralID 而不是对象，因为对象insertable 和 updateble 都为false