0

This is how I currently have all my Entity classes (Only one shown here for reference)

@Entity
@Data
@Table(name = "songs")
public class Song {
    @Id
    @GeneratedValue
    @Column(name = "song_id")
    private Long id;
    
    @Column(name = "song_name")
    private String songName;
    
    @Column(name = "album_id")
    private Long albumId;
    
    @Column(name = "song_duration")
    private Integer songDuration;
    
    @ManyToOne(targetEntity = Album.class)
    private Album album;

}

From lombok reference:

The @Data annotation is likely the most frequently used annotation in the Project Lombok toolset. It combines the functionality of @ToString, @EqualsAndHashCode, @Getter, and @Setter. Essentially, using @Data on a class is the same as annotating the class with a default @ToString and @EqualsAndHashCode, as well as annotating each field with both @Getter and @Setter. Annotating a class with @Data also triggers Lombok's constructor generation. This adds a public constructor that takes any @NonNull or final fields as parameters. This provides everything needed for a Plain Old Java Object (POJO). While @Data is extremely useful, it does not provide the same granularity of control as the other Lombok annotations. In order to override the default method generation behaviors, annotate the class, field, or method with one of the other Lombok annotations and specify the necessary parameter values to achieve the desired effect.

@Data does provide a single parameter option that can be used to generate a static factory method. Setting the value of the staticConstructor parameter to the desired method name will cause Lombok to make the generated constructor private and expose a a static factory method of the given name.

@Data(staticConstructor="of")
public class Company {
    private final Person founder;
    private String name;
    private List<Person> employees;
}

Is equivalant to:

public class Company {
    private final Person founder;
    private String name;
    private List<Person> employees;
 
    private Company(final Person founder) {
        this.founder = founder;
    }
 
    public static Company of(final Person founder) {
        return new Company(founder);
    }
 
    public Person getFounder() {
        return founder;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(final String name) {
        this.name = name;
    }
 
    public List<Person> getEmployees() {
        return employees;
    }
 
    public void setEmployees(final List<Person> employees) {
        this.employees = employees;
    }
 
    @java.lang.Override
    public boolean equals(final java.lang.Object o) {
        if (o == this) return true;
        if (o == null) return false;
        if (o.getClass() != this.getClass()) return false;
        final Company other = (Company)o;
        if (this.founder == null ? other.founder != null : !this.founder.equals(other.founder)) return false;
        if (this.name == null ? other.name != null : !this.name.equals(other.name)) return false;
        if (this.employees == null ? other.employees != null : !this.employees.equals(other.employees)) return false;
        return true;
    }
 
    @java.lang.Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = result * PRIME + (this.founder == null ? 0 : this.founder.hashCode());
        result = result * PRIME + (this.name == null ? 0 : this.name.hashCode());
        result = result * PRIME + (this.employees == null ? 0 : this.employees.hashCode());
        return result;
    }
 
    @java.lang.Override
    public java.lang.String toString() {
        return "Company(founder=" + founder + ", name=" + name + ", employees=" + employees + ")";
    }
}

Problem: java cannot find the getters and setters

kesarling He-Him
  • 1,793
  • 3
  • 10
  • 32

1 Answers1

0

You need to configure IDE and Project according to documentation.
Example of a configuration for IntelliJ and Eclipse

Eugene
  • 2,332
  • 2
  • 9
  • 14