2014-09-10 3 views
1

이 질문에 매핑되는 속성을 유지하는 방법 것과 매우 유사하다 물었다 누군가가 최대 절전 수식이있는 부동산, 완전히 동안 무시하기로 결정 이유 등이 되거 수최대 절전 모드 - 공식

here 지속. 그렇다면 수식이있는 속성을 유지하는 대안은 무엇입니까? 추가 구성이 있습니까? 최대 절전 모드로 발사

검색어 : 최대 절전 모드는 HBM의 수식을 가지고 삽입 쿼리의 '이름'속성을 무시하는 방법

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

참고.

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' from dual" > 
      <column name="name"/> 
     </property> 
     <property name="maxSpeed"> 
      <column name="max_speed" /> 
     </property> 
     <property name="country"> 
      <column name="country" /> 
     </property> 
    </class> 
</hibernate-mapping> 

등급 : 그것이 말하는

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+ "]"; 
     } 


} 

답변

0

으로 hibernate documentation 당 :

5.1.4.2. hbm.xml 부동산의 매핑

식 (옵션) : 계산 된 속성 값을 정의하는 SQL 표현식. 계산 된 속성에는 자신의 열 매핑이 없습니다.

따라서 Formula의 속성은 DB 테이블에 열 매핑을 가질 수 없습니다. 다른 방법으로 값을 저장할 수있는 다른 속성을 가질 수 있으며이 속성을 DB 테이블 열에 매핑 할 수 있습니다.

+0

감사합니다. 그러나 레코드를 저장하려고 시도하는 동안 최대 절전 모드는 삽입을 시도하기 전에 선택을 시작하지 않습니다. 그래서 다른 readOnly 필드를 만들더라도 - nameReadOnly라고 말하면 수식을 가지고 그 세터에서 수식을 통해 얻은 값을 이름으로 설정합니다. 이 setter는 절전 모드로 들어가기 전에 선택을 해제하지 않기 때문에 전혀 호출되지 않습니다. – Nohsib