java - Hibernate: 'Repeated column mapping in entity' vs 'Mixing updatable and non updatable columns in a property is not allowed' -


i have legacy db.

+----+  +------------+ +------------+ |site|  |content     | |program     | +----+  +------------+ +------------+ |id  |  |id:pk       | |siteid:pk,fk| |name|  |siteid:fk   | |code:pk     | +----+  |prog_code:fk| |name        |         |prog_param  | +------------+         +------------+   

table content have 1 pk column. siteid columns not part of pk. table program have 2 pk column(siteid, code). composite pk. table work template. variable in program parameter , on table content's prog_param column.

i want map table object this.

+-----------+  +------------+  +-----------+  +---------------+ |site       |  |program     |  |programid  |  |content        | +-----------+  +------------+  +-----------+  +---------------+ |id:long    |  |id:programid|  |site:site  |  |id:long        | |name:string|  |name:string |  |code:string|  |site:site      | +-----------+  |param:string|  +-----------+  |program:program|                +------------+                 +---------------+ 

but don't know how mapping 'content' , 'program' in complex situation.

so, have tried make situation simple. have mapped prog_param content

+-----------+  +------------+  +-----------+  +-------------------+ |site       |  |program     |  |programid  |  |content            | +-----------+  +------------+  +-----------+  +-------------------+ |id:long    |  |id:programid|  |site:site  |  |id:long            | |name:string|  |name:string |  |code:string|  |site:site          | +-----------+  +------------+  +-----------+  |program:program    |                                               |programparam:string|                                               +-------------------+ 

as code

@entity @table(name = "site") @getter @setter public class site {     @id     @column(name = "site")     protected string id;      @column(name = "name")     protected string name; }   @entity @table(name = "program") @getter @setter public class program {     @embeddedid     protected programid id;     @column(name = "name")     protected string name; }  @embeddable @getter @setter @equalsandhashcode public class programid implements serializable{     @manytoone     @joincolumn(name = "site")     protected site site;      @column(name = "code")     protected string code; }  @entity @table(name="content") @getter @setter public class content {     @id     @column(name = "id")     protected long id;      @manytoone     @joincolumn(name = "siteid",referencedcolumnname="site")     protected site site;       @onetoone     @joincolumns({         @joincolumn(name="siteid",referencedcolumnname="site"),         @joincolumn(name="prog_code",referencedcolumnname="code"),      })     protected program program; } 

but not work. hibernate throw 'repeated column in mapping entity' exception.

so have research solutions. found 'repeated column in mapping entity' exception throwed when hibernated can not determine use property.

stackoverflows's solution set 'insertable=false, updatable=false' @joincolumn, let hibernate can determine use property.

i want use content's property 'site' because used frequently. , site , program property used separately in application.

so try set 'insertable=false, updatable=false' content's property 'program'

    @onetoone     @joincolumns({         @joincolumn(name="siteid",referencedcolumnname="site", insertable=false, updatable=false),         @joincolumn(name="prog_code",referencedcolumnname="code"),      })     protected program program; 

this not work too. 'mixing updatable , non updatable columns in property not allowed' exception throwed.

so have set set 'insertable=false, updatable=false' 'prog_code', of course, hibernate not change prog_code when set different prog_code.

at point, have no idea.

please let me know idea solve situation.

i having same issue, 2 composite keys sharing attribute fails "repeated column in mapping entity". think might bug, ref: https://hibernate.atlassian.net/browse/hhh-4582. using hibernate 3.6.4


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -