2012-04-19 64 views
1

我使用UserType 3.0.0.RC1将JodaMoney映射到Hibernate。UserType/Hibernate/JodaMoney错误:PersistentMoneyAmount要求将currencyCode定义为参数

我卡以错误时的SessionFactory初始化:

PersistentMoneyAmount CURRENCYCODE需要被定义为一个 参数,或要定义

我是defaultCurrencyCode休眠属性确定我必须有一些配置问题 - 这里是相关的片段。

的persistence.xml:

<persistence-unit name="spring-jpa"> 
    <properties> 
     <property name="hibernate.format_sql" value="true"/> 
     <property name="hibernate.hbm2ddl.auto" value="update"/> 
     <property name="jadira.usertype.autoRegisterUserTypes" value="true"/> 
    </properties> 
</persistence-unit> 

相关的Spring配置:

<bean id="entityManagerFactory" 
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="packagesToScan"> 
     <list> 
      <value>com.mangofactory.concorde</value> 
      <value>com.mangofactory.moolah</value> 
     </list> 
    </property> 
    <property name="persistenceUnitName" value="spring-jpa" /> 
    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
      <property name="showSql" value="true" /> 
      <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /> 
     </bean> 
    </property> 
</bean> 

对我缺少什么,我有什么建议?

回答

2

我最终解决这个用我persistence.xml以下配置:

<persistence-unit name="spring-jpa"> 
    <properties> 
     <property name="hibernate.format_sql" value="true"/> 
     <property name="hibernate.hbm2ddl.auto" value="update"/> 
     <property name="jadira.usertype.autoRegisterUserTypes" value="true"/> 
     <property name="jadira.usertype.currencyCode" value="AUD"/> 
     <property name="jadira.usertype.seed" value="org.jadira.usertype.spi.shared.JvmTimestampSeed"/> 
    </properties> 
</persistence-unit> 

棘手的部分是,我需要为了提供jadira.usertype.seedjadira.usertype.currencyCode被检测到。

0

关于需要配置种子 - 这是由于3.0.0-RC1中的一个错误,将来会被修复。

1

,如果你正在寻找一个基于注解的解决方案,您可以尝试这个

@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount", parameters = { @Parameter(name="currencyCode", value="USD") }) 
private Money price; 

这里找到

Email Archive: usertype-discuss (read-only)

相关问题