王美 (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZTRjZTY0MTcx...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17053?atlOrigin=eyJpIjoiZTRjZT...
) HHH-17053 (
https://hibernate.atlassian.net/browse/HHH-17053?atlOrigin=eyJpIjoiZTRjZT...
) spring boot 3.1.2 use hibernate 6.2.6 final use CompositeUserType to mapping JodaMoney,
cannot work , in hibernate 5 use userType can work, joda-money version is 1.0.1 (
https://hibernate.atlassian.net/browse/HHH-17053?atlOrigin=eyJpIjoiZTRjZT...
)
Issue Type: Bug Affects Versions: 6.2.6 Assignee: Unassigned Components: hibernate-core
Created: 09/Aug/2023 00:27 AM Environment:
implementation('org.joda:joda-money:1.0.1')
id 'org.springframework.boot' version '3.1.2'
ext['spring-framework.version'] = '6.0.11'
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
Priority: Major Reporter: 王美 (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
public class JodaMoneyType implements CompositeUserType<Money> {
@Override public Object getPropertyValue(Money component, int property) throws
HibernateException {
switch (property) {
case 0:
return component.getCurrencyUnit().getCode(); case 1:
return component.getAmount(); default:
throw new HibernateException("unknown property"); }
}
@Override public Money instantiate(ValueAccess values, SessionFactoryImplementor
sessionFactory) {
String currency = values.getValue(0, String.class); BigDecimal amount =
values.getValue(1, BigDecimal.class); if (currency == null || amount == null) {
return null; }
return Money.of(CurrencyUnit.of(currency), amount); }
@Override public Class<?> embeddable() {
return Money.class; }
@Override public Class<Money> returnedClass() {
return Money.class; }
@Override public boolean equals(Money x, Money y) {
if (x == y) {
return true; }
if (x == null || y == null) {
return false; }
return x.equals(y); }
@Override public int hashCode(Money x) {
if (x == null) {
return 0; }
return x.hashCode(); }
@Override public Money deepCopy(Money value) {
if (value == null) {
return null; }
return Money.of(value.getCurrencyUnit(), value.getAmount()); }
@Override public boolean isMutable() {
return false; }
@Override public Serializable disassemble(Money value) {
return value; }
@Override public Money assemble(Serializable cached, Object owner) {
return cached == null ? null : (Money) cached; }
@Override public Money replace(Money detached, Money managed, Object owner) {
return detached; }
}
@Entity(name = "Salary")
@Table(name = "salary")
@Datapublic static class Salary {
@Id @GeneratedValue private Long id; private String other; @AttributeOverride(name =
"amount", column = @Column(name = "salary_amount"))
@AttributeOverride(name = "currency", column = @Column(name =
"salary_currency"))
@CompositeType(value = JodaMoneyType.class)
private org.joda.money.Money salary;}
compositeType mapping salary cannot mapping two columns, only one .
(
https://hibernate.atlassian.net/browse/HHH-17053#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-17053#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100234- sha1:9e2db29 )