0

I am using mapstruct to map my DTO to entity,

My Entity

@Entity
@Data
@Table(name = "break")
public class Break {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "native")
    private long id;
    
    private String name;
    private LocalDateTime start;
    private LocalDateTime end;
}

My DTO

@Data
public class BreakDTO {
    private String name;
    private LocalDateTime start;
    private LocalDateTime end;
}

Generated MapStruct Implementation

@Override
    public Break breakDTOtoBreak(BreakDTO breakDTO) {
        if ( breakDTO == null ) {
            return null;
        }

        Break break1 = new Break();

        break1.setName( breakDTO.getName() );
        break1.setStart( breakDTO.getStart() );
        break1.setEnd( breakDTO.getEnd() );

        return break1;
    }

I tried editing the file but it is unable to create break and always gives break1

  • 2
    `break` is reserved word in java, you can't use it to name variables, packages, etc – Andrey B. Panfilov Oct 09 '22 at 16:33
  • 1
    And what is the problem with that? You are only interested in the result of the method, why bother with the implemenation or whatever the name of the variable is? – M. Deinum Oct 10 '22 at 06:34

3 Answers3

2

Break is a reserved keyboard, use different name or it would always add 1 suffix for successful compilation.

0

break is a reserved keyword in java used to terminate loops and switch statements in java and it is reserved for that purpose that is why you are unable to create variable with name break. You can checkout reserved keywords in java from below link:

https://www.thoughtco.com/reserved-words-in-java-2034200

0

I don't get the point; generated code should be left unmodified and you don't care about internal naming (or any other) strategy: your are using a mapping library to perform dto mapping and don't care about writing tedious mapping code. Let the library do its job and use exposed configration to manipulated generated code in a safe way

Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69