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

I am using UserType 3.0.0.RC1 to map JodaMoney to Hibernate.

I am stuck in error while initializing SessionFactory:

PersistentMoneyAmount requires that currencyCode be defined as a parameter or property DefaultCurrencyCode Hibernate, which must be defined

I am sure that I should have a setup problem - these are 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> 

Corresponding 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 am missing?

+1
source share
3 answers

I decided to solve this using the following configuration in 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 jadira.usertype.seed to detect jadira.usertype.currencyCode .

+2
source

If you are looking for a solution based on annotations, you can 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)

+1
source

Regarding the need to set up seeds - this is due to a bug in 3.0.0-RC1 and will be fixed in the future.

0
source

Source: https://habr.com/ru/post/915442/


All Articles