I have a Java project with MySQL database. I need to fetch entries from database and this is where I get the following error. Not sure why the end column is causing a problem. I checked several similar questions, but still can't see the solution in my case as the name of the column is pretty simple.
SQL Error: 1054, SQLState: 42S22
2021-09-08 14:30:49.190 ERROR 3308 --- [qtp345060426-21] o.h.engine.jdbc.spi.SqlExceptionHelper : Unknown column 'whateverentity0_.end' in 'field list'
2021-09-08 14:30:49.219 ERROR 3308 --- [qtp345060426-21] conf.CommonErrorHandler : Request: uri=/test/information-entries raised org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Here is my entity class:
@Entity(name = "WhateverEntity")
@Table(name = "whatever_table_entry")
@Getter
@Setter
@Immutable
public class WhateverEntity{
@Id
private Long id;
@Column(name = "priority")
private String priority;
@Column(name = "created")
private DateTime created = new DateTime();
@Column(name = "modified")
private DateTime modified = new DateTime();
@Column(name = "start")
private DateTime start = new DateTime();
@Column(name = "end")
private DateTime end = new DateTime();
@Column(name = "notification_sent")
private Date notificationSent;
@OneToOne
@JoinColumn(name = "header_image_id")
private ImageData image;
}
Here is the DTO class:
@Setter
@Getter
@NoArgsConstructor
@Schema(name = "WhateverEntityDto.whateverentity")
public class WhateverEntityDto {
@NotBlank
private Long id;
@Schema
private ImageData headerImage;
@Schema(example = "IMPORTANT")
@NotBlank
private String priority;
@Schema
@NotBlank
private DateTime created;
@Schema
private DateTime modified;
@Schema
private DateTime start;
@Schema
private DateTime end;
@Schema
private Date notificationSent;
public WhateverEntityDto(WhateverEntity whateverEntity) {
this.id = whateverEntity.getId();
this.headerImage = whateverEntity.getHeaderImage();
this.priority = whateverEntity.getPriority();
this.created = whateverEntity.getCreated();
this.modified = whateverEntity.getModified();
this.start = whateverEntity.getStart();
this.end = whateverEntity.getEnd();
this.notificationSent = whateverEntity.getNotificationSent();
}
}
The database table whatever_table_entry looks like this:
id bigint(20) NO PRI auto_increment
header_image_id bigint(20) YES
priority int(11) NO
created datetime NO
modified datetime YES
start datetime YES MUL
end datetime YES MUL
notification_sent date YES
Here is the repository:
public interface WhateverEntityRepository extends CrudRepository<WhateverEntity, Long> {
@Query(value = "select we from WhateverEntity we")
List<WhateverEntity> findActiveWhateverEntities(Long id, Date date);
}
and here controller's method where the error comes:
@GetMapping("/test/information-entries")
@PreAuthorize("hasPermission()")
public @ResponseBody
WhateverEntityListDto getWhateverEntityEntries() {
List<WhateverEntity> whateverEntity = whateverEntityRepository.findActiveWhateverEntities(253L, new Date());
return new WhateverEntityListDto(whateverEntity.stream()
.map(WhateverEntityDto::new)
.collect(toList()));
}