UserType / Hibernate / JodaMoney error : PersistentMoneyAmount requires currencyCode to be defined as a parameter

StackOverflow https://stackoverflow.com/questions/10238016

Question

I'm using UserType 3.0.0.RC1 to map JodaMoney to Hibernate.

I'm stuck with an error when the SessionFactory initialises:

PersistentMoneyAmount requires currencyCode to be defined as a parameter, or the defaultCurrencyCode Hibernate property to be defined

I'm sure I must have some configuration issue — here's the relevant snippets.

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>

The relevant spring config:

<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>

Any tips on what I'm missing?

Was it helpful?

Solution

I ended up solving this using the following configuration in my 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>

The tricky part is that I needed to provide a jadira.usertype.seed in order for the jadira.usertype.currencyCode to be detected.

OTHER TIPS

if you're looking for an annotation based solution, you may try this

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

found here

Email Archive: usertype-discuss (read-only)

Regarding the need to configure seed - this is due to a bug in 3.0.0-RC1 and will be fixed in future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top