小编Ale*_*nko的帖子

在IntelliT Idea for Kotlin @ConfigurationProperties类中未生成spring-configuration-metadata.json文件

我正在尝试为基于Spring Boot的项目生成spring-configuration-metadata.json文件.如果我使用Java @ConfigurationProperties类,它会正确并自动生成:

@ConfigurationProperties("myprops")
public class MyProps {

    private String hello;

    public String getHello() {
        return hello;
    }

    public void setHello(String hello) {
        this.hello = hello;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用Kotlin类,则不会生成spring-configuration-metadata.json文件(我已尝试过gradle构建和Idea Rebuild项目).

@ConfigurationProperties("myprops")
class MyProps {
    var hello: String? = null
}
Run Code Online (Sandbox Code Playgroud)

AFAIK Kotlin使用构造函数,getter和setter生成相同的类,并且应该充当常规Java bean.

有什么想法为什么spring-boot-configuration-processor不能与Kotlin类一起使用?

spring intellij-idea gradle kotlin spring-boot

10
推荐指数
2
解决办法
5775
查看次数

Hibernate @Formula中TRIM函数的参数数量错误

我正在尝试制作一个公式来选择用户配置文件的用户友好名称.它选择firstname +''+ lastname,如果它们中至少有一个不为空而不是空白(包含非空白字符),否则它选择短名称(具有相同条件),最后,如果shortname为空或null,则为选择id,转换为字符串.

@Formula("COALESCE(NULLIF(TRIM(BOTH FROM CONCAT(sp.firstname, ' ', sp.lastname)), ''), TRIM(p.shortname), to_char(p.id, 'FM9999999999999999')) " +
   "FROM socialprofile AS sp " +
   "JOIN profile AS p ON sp.id=p.id")
   public String getUserFriendlyName() {
      return super.getUserFriendlyName();
   }
Run Code Online (Sandbox Code Playgroud)

结果是:

org.hibernate.HibernateException: Unexpected number of trim function operands : 10
Run Code Online (Sandbox Code Playgroud)

但是只有3个参数:CONCAT的两个参数和结果.这个问题有解决方法吗?DB是PostgreSQL 9.1,Hibernate版本是4.2.1.以防万一,这是表结构:

Profile
  bigint id
  text shortname

SocialProfile
  bigint id
  text firstname
  text lastname
Run Code Online (Sandbox Code Playgroud)

它们通过id字段与一对一相关,在Java代码中SocialProfile扩展了Profile.在PgAdmin SQL编辑器中,此请求完美无缺.

parameters hibernate trim formula

5
推荐指数
1
解决办法
851
查看次数

如何在 Hibernate 中使用 org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency 类型映射 Joda Money?

试试这个:

@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency")
private org.joda.money.Money price;
Run Code Online (Sandbox Code Playgroud)

得到这个:

org.hibernate.MappingException: property mapping has wrong number of columns:domain.ClientOrderItem.price type: org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency
Run Code Online (Sandbox Code Playgroud)


@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "USD")})
Run Code Online (Sandbox Code Playgroud)

效果很好,但我想将货币存储在数据库中并能够使用不同的货币。

java hibernate joda-money

5
推荐指数
1
解决办法
2017
查看次数