У меня есть многомодульный проект (* .war).
Это точка входа в приложение.
@SpringBootConfiguration
@SpringBootApplication
@EnableJpaRepositories(basePackages = {"....dao.repository"})
@EntityScan(basePackages = {"....dao.model"})
@ComponentScan(basePackages = {"..."})
public class ApsTtsApplication
extends SpringBootServletInitializer
implements WebApplicationInitializer {
private static final Logger LOGGER = LoggerFactory.getLogger( ApsTtsApplication.class );
public static void main(String[] args) {
LOGGER.info("Start an application...");
SpringApplication.run(ApsTtsApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
LOGGER.info("There is building the web application!");
return builder.sources(ApsTtsApplication.class);
}
}
модель
@MappedSuperclass
public abstract class IdMainForEntities {
@Id
@GenericGenerator(name="system-uuid", strategy = "uuid")
@GeneratedValue(generator="system-uuid")
@Column(name = "id", nullable = false)
private String ID;
public IdMainForEntities() {
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IdMainForEntities that = (IdMainForEntities) o;
return Objects.equals(ID, that.ID);
}
@Override
public int hashCode() {
return Objects.hash(ID);
}
@Override
public String toString() {
return "IdMainEntity{" +
"ID='" + ID + '\'' +
'}';
}
}
@Entity
@Table(name = "MESSAGESLOG")
public class MessageLog extends IdMainForEntities {
...
@Column(name = "MSG_OWNER_ID")
@Size(message = "MSG_OWNER_ID{MessagesLog.size}", max = 32)
private String msgOwnerId;
public MessageLog() {
}
public String getMsgOwnerId() {
return msgOwnerId;
}
public void setMsgOwnerId(String msgOwnerId) {
this.msgOwnerId = msgOwnerId;
}
....
}
- MessagesLogReadRepository
public interface MessagesLogReadRepository extends CrudRepository <MessageLog, String> {
Optional <MessageLog> findByMsgOwnerId(String msgOwnerId);
MessageLog findMessageLogByMsgOwnerId(String msgOwnerId);
Optional <MessageLog> findByDocument(String documentId);
}
Из этого хранилища могут быть вызваны только стандартные методы : findById () , et c.
Но именованные запросы не найдены.
18-03-2020 08: 49: 39.531 DEBUG 8660 osdjrquery.JpaQueryFactory
: поиск запроса для метода findByMsgOwnerId 18-03-2020 08: 49: 39.547 DEBUG 8660 osdjpa.repository.query.NamedQuery: поиск именованного запроса MessageLog.findByMsgOwnerId 18-03-2020 08: 49: DEBUG 8660 ohetinternal.TransactionImpl: при создании TransactionImpl JpaCompliance # isJpaTransactionComplianceEnabled == false 18-03-2020 08: 49: 39.547 DEBUG 8660 osdjpa.repository.query.NamedQuery: не найден именованный запрос
@Override
public MessageLogDto getByMsgOwnerId(String msgOwnerId) {
if(msgOwnerId == null) throw new MessagesLogException(paramNotNull);
/*It's null*/
Optional<MessageLog> byMsgOwnerId = this.messagesLogReadRepository.findByMsgOwnerId("8a00844170d829040170d82c670b00");
MessageLog messageLog = byMsgOwnerId.orElse(new MessageLog());
/*It's OK*/
Optional<MessageLog> byId = this.messagesLogReadRepository.findById("8a00844170d829040170d82c670b0003");
return transformEntityToDto(messageLog);
}
Обновление
public interface MessagesLogReadRepository extends JpaRepository<MessageLog, String> {
@Query(value = "SELECT * from messageslog where MSG_OWNER_ID = ?1", nativeQuery = true )
Optional <MessageLog> findRowByMsgOwnerId(String msgOwnerId);
...
.. . расширяет JpaRepository
Но, это не решает проблему.
У меня нет ошибок. Я получаю только NULL, но запрошенная строка находится в таблице, это точно.
У кого-нибудь есть идеи по этому поводу?
Почему?