I just try to create a CRUD Web Application with Spring Boot and I found that there is a problem with using Java Double Brace Initialization in the framework.
Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Unknown entity: com.example.service.impl.FileImageServiceImpl$1; nested exception is java.lang.IllegalArgumentException: Unknown entity:
I have the @Entity
class:
@Entity
public class RandomEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
//Getter and Setter
}
A @RestController
@RestController
public class RandomController{
@Autowired
private RandomRepository randomRepository;
@GetMapping("/create")
public String create(){
RandomEntity rdEntity = new RandomEntity(){{
setName("Bla Bla");
}};
return randomRepository.save();
}
}
Here is the repository
public interface RandomRepository extends CrudRepository<RandomEntity, Long> {
}
But when I change Java Double Brace Initialization to Normal Initialization, the Application run properly.
Do you know why is that? Thank you so much!