2016-06-07 74 views
0

我想將一個字符串列轉換爲Integer。在@Formula註解中使用保留字

@Formula("CAST(pContactNumber as UNSIGNED)") 
    private Integer contactNumber; 

但是Hibernate的對待UNSIGNED字作爲account0_.UNSIGNED。 任何建議如何防止這種情況。

我已經通過了以下答案。 Hibernate @formula is not supportinng Cast() as int for teradata database

但是有人可以解釋一下在Spring配置中使用這個擴展的Oracle10gDialect的位置。

+1

不是春,你必須重新分配'hibernate.dialect'到創建'Oracle10gDialectExtended'(或者你正在使用的一個擴展名)。您可以在'hibernate.cfg.xml'文件中更改您的方言.... –

+1

@JordiCastilla可以使用Spring配置將'hibernateProperties'設置爲'LocalSessionFactoryBean'。 –

+0

@ v.ladynev你能寫這個建議作爲答案,以便我可以投票。 –

回答

1

hibernate.dialect可以使用LocalSessionFactoryBean

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> 
    <property name="hibernateProperties"> 
     <props> 
     <prop key="hibernate.dialect">com.example.CustomOracle10gDialect</prop> 
     </props> 
    </property> 
    </bean> 

它是休眠5 hibernateProperties屬性,因爲使用包org.springframework.orm.hibernate5.LocalSessionFactoryBean,對Hibernate 4,你需要使用org.springframework.orm.hibernate4.LocalSessionFactoryBean進行設置。