1

I have an entity class where I use Lombok, I need to how to exclude certain variables from Lombok @AllArgsConstructor annotation?

@Entity
@Table(name = "customer")
@Data
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@NoArgsConstructor
public class Customer {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "email")
    private String email;

}

from the above code, I need to know how can I exclude 'id' from @AllArgsConstructor.

is there any other annotation which can be used to create a constructor by excluding some variables?

thanks in advance

Sumanth
  • 159
  • 2
  • 15
  • The name already says what it does, create a constructor with all arguments. That is the whole point of that. There isn't another annotation I know of, the only thing would be doing it by hand. – M. Deinum Feb 05 '20 at 09:14
  • There are multiple proposals (including [mine](https://github.com/rzwitserloot/lombok/issues/1376#issuecomment-440462126)), but nothing has been implemented yet (and it make never happen). As there's a single field you want to omit, you can simply pass 0 and be done. Not nice, I know. – maaartinus Feb 05 '20 at 09:19
  • @maaartinus checked your git conversation, it will be very useful if there is exclude and include annotations or parameters for the annotations but none the less it's not been implemented as mentioned, Thank you for taking the time to clarify. – Sumanth Feb 06 '20 at 09:27
  • @M.Deinum thank you for taking the time to clarify – Sumanth Feb 06 '20 at 09:28

0 Answers0