Search code examples
javaspringhibernatespring-boot

The method getId() is undefined for the type ClassName


I am learning Spring boot and got stuck in a problem. I have created an Expense class as following:

@AllArgsConstructor
@NoArgsConstructor
@Entity
@Data
@Table(name="expense")
public class Expense {
    @Id
    private Long id;
    
    private Instant expensedate;
    
    private String description;
    
    private String location;
    
    @ManyToOne
    private Category category;
    
    @JsonIgnore
    @ManyToOne
    private User user;
}

Now I am trying to create a controller to add/delete the Expense objects. Following method is for creating Expense object:

@PostMapping("/expenses")
ResponseEntity<Expense> createExpense(@Valid @RequestBody Expense expense) throws URISyntaxException{
    Expense result = expenseRepository.save(expense);
    return ResponseEntity.created(new URI("/api/expense" + result.getId())).body(result);
}

But here in this method I am getting following error:

The method getId() is undefined for the type Expanse


Solution

  • Did You have install lombok plugin in your IDE?

    If you are using Eclipse:

    Lombok download page

    If you are using Intellij find the plugin there.