Hibernate: how can I call a column create with @Formula annotation -


i want execute left_join between 2 columns:

  • 'codicespedizione' column of 'provaind' table

  • 'idcod' concatenation of 2 columns of 'provariep' table (so, idcod isn't existing column)

i execute concatenation @formula annotation inside dataobject (java class mapped database):

@formula("concat(id,substr(codicespedizione,6))")

private string idcod;

now want call idcod in dbozzo.java:

@manytoone @joincolumn(name="codice", referencedcolumnname="idcod", nullable=false) public dbotivo getdbotivo() {     return dbotivo; } 

but if call 'idcod' in referencedcolumnname, error:

org.hibernate.annotationexception: @onetoone or @manytoone on dataobject.requezzo.dbozzo references unknown entity: dataobject.dbozzo

can explain me error? i'm not sure..the formula annotation create virtual column? otherwise, 'idcod' virtual column?

thank attention , sorry bad english :)

i not totally sure, think use @joincolumnorformula

see "5.1.7.1. using foreign key or association table" on documentation: http://docs.jboss.org/hibernate/orm/3.6/reference/en-us/html/mapping.html

you can use sql fragment simulate physical join column using @joincolumnorformula / @joincolumnorformulas annotations (just can use sql fragment simulate property column via @formula annotation).

@entity public class ticket implements serializable {     @manytoone     @joincolumnorformula(formula="(firstname + ' ' + lastname)")     public person getowner() {         return person;     }     ... }  

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -