Insertable = False, use of updatable = False

Source: Internet
Author: User

Turn from:insertable = false, updatable = False use

When using JPA to configure an entity, if there are two attributes (one is a generic attribute and one is a many-to-one property), the error will be indicated when mapping to the same column in the database.

At this point, add insertable = False, updatable = False, in the @joincolumn annotation of the many-to-one to resolve.

For example:

/*** User Class*/@Entity @Table (name= "Tbl_sys_user")   Public classsysuser{@Id @GeneratedValue (Generator= "System-uuid") @GenericGenerator (name= "System-uuid", strategy = "UUID") @Column (name= "user_id", unique =true, length = 40) @CsvColumn (imported=false)      PrivateString ID;//User ID@Column (Name= "User_code", nullable =false, length = 40)      PrivateString Usercode;//User Account@CsvColumn (desc= "User name", required=true) @Column (name= "user_name", length = 60)      PrivateString UserName;//User name@Column (Name= "dept_id", length = 40)      PrivateString DeptID;//Department ID (is_org=0)@ManyToOne @JoinColumn (name= "dept_id", insertable =false, updatable =false, nullable=true)      Privatesysorg Dept;//Department Object  }  

As we can see, DeptID and Dept all map to the dept_id field inside the database, but with insertable = false, updatable = False, Dept will not be saved to the database when the data is saved.

Insertable = False, use of updatable = False

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.