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

前端 未结 3 1801
孤街浪徒
孤街浪徒 2021-01-24 20:20

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

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

PersistentMoneyAmount r

相关标签:
3条回答
  • 2021-01-24 21:04

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

    0 讨论(0)
  • 2021-01-24 21:07

    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.

    0 讨论(0)
  • 2021-01-24 21:10

    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)

    0 讨论(0)
提交回复
热议问题