Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在启用lombok的时候似乎不应该使用@Data和@EqualsAndHashCode注解 #123

Open
FourLeafTec opened this issue Jul 31, 2021 · 3 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@FourLeafTec
Copy link

Describe the bug (描述这个Bug)

根据这篇文章的描述,在某些特定行为,比如使用一对多(@onetomany)的情况下lombok的默认的@EqualsAndHashCode似乎会造成严重的内存和性能消耗,并且也应该适当限制@tostring注解的使用

jpa buddy也会对这种使用方式提出警告

我看了看模版,通过修改模版似乎也不好解决这个问题

Expected behavior (期望的行为)

希望把@DaTa换成@getter @Setter @tostring @requiredargsconstructor 的注解组合并且添加单独的equals()和hashCode()实现

equals实现参考:

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
       {className} that = ({className}) o;

        return Objects.equals(ID, that.ID);
    }

而jpa buddy生成的hashCode实现非常简单,就一个数字,我不太明白其中的原理

idea plugin jpa support version (idea plugin jpa support的版本号):
2.0.7

@FourLeafTec FourLeafTec added the bug Something isn't working label Jul 31, 2021
@carter-ya carter-ya added the good first issue Good for newcomers label Aug 2, 2021
@rxxy
Copy link

rxxy commented Aug 7, 2021

+1 现在生成模版后还需要手动改为@getter @Setter等注解

@carter-ya
Copy link
Owner

  1. 想了下即使使用@Data注解,问题应该也不大,常规场景中都是toJSONString(domain),几乎不会直接toString(),debug场景倒是会toString()
  2. equals and hashCode()场景可以在相关关联实体字段上添加 @Exclude注解

在未来的版本倒是可以添加这种关联实体的@Exclude注解检查

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants
@FourLeafTec @rxxy @carter-ya and others