java - Hibernate - How to persist a property which is mapped with Formula -


this question similar 1 asked here

could shed light why hibernate decides ignore property, has formula, while persisting. if whats alternative persist property has formula ? there additional config ?

query fired hibernate :

insert fighterjet (max_speed, country, jet_id) values (?, ?, ?) 

note how hibernate ignores 'name' property in insert query, has formula in hbm.

hbm :

<hibernate-mapping>     <class name="com.fighterjet.fighterjetdo" table="fighterjet">         <id name="jetid" type="int" column="jet_id">             <generator class="increment" />         </id>         <property name="name" formula="select 'hi' dual" >             <column name="name"/>         </property>         <property name="maxspeed">             <column name="max_speed" />         </property>         <property name="country">             <column name="country" />         </property>     </class> </hibernate-mapping> 

class :

public class fighterjetdo {      private integer jetid;      private string name;      private integer maxspeed;      private string country;      public integer getjetid() {         return jetid;     }      public void setjetid(integer jetid) {         this.jetid = jetid;     }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      public integer getmaxspeed() {         return maxspeed;     }      public void setmaxspeed(integer maxspeed) {         this.maxspeed = maxspeed;     }      public string getcountry() {         return country;     }      public void setcountry(string country) {         this.country = country;     }      @override         public string tostring() {             return "fighterjet [jet_id=" + jetid + ", name=" + name                     + ", max speed=" + maxspeed + ", country=" + country+ "]";         }      } 

as per hibernate documentation says:

5.1.4.2. property mapping hbm.xml

formula (optional): sql expression defines value computed property. computed properties not have column mapping of own.

so property formula cannot have column mapping in db table. alternative can have property can hold value , can map new property db table column.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -