jpa - how to set value to composite primary key which is annotated with @EmbeddedId in java/hibernate application -


i have java bean/model class(ratiofunctionexpression.java) jpa annotation below. class has composite key shown below. in dao.java how set key composite key? example appreciated

@embeddedid @attributeoverrides({         @attributeoverride(name = "ratiofunctionid", column = @column(name = "ratio_function_id", nullable = false, scale = 0)),         @attributeoverride(name = "expressionid", column = @column(name = "expression_id", nullable = false, scale = 0)) }) public ratiofunctionexpressionid getid() {     return this.id; }  public void setid(ratiofunctionexpressionid id) {     this.id = id; } 

in order set value attribute, create new instance , assign it:

ratiofunctionexpressionid newid = new ratiofunctionexpressionid(); newid.setratiofunctionid(afunctionid); newid.setexpressionid(anexpressionid); aratiofunctionexpression.setid(newid); 

remember being ratiofunctionexpressionid @embeddable, doesn't need id of own, because doesn't represent entity on own. it's meant provide grouping of property definitions easy composition , modularity.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -