java - osdjpa.repository.query.NamedQuery:在多模块项目中没有找到命名查询...
问题描述
我有多模块项目(* .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);
}
}
模型
- IdMainForEntity
@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 ()等。
但未找到命名查询。
18-03-2020 08:49:39.531 调试 8660 osdjrquery.JpaQueryFactory
:查找方法 findByMsgOwnerId 的查询 18-03-2020 08:49:39.547 调试 8660 osdjpa.repository.query.NamedQuery:查找命名查询 MessageLog.findByMsgOwnerId 18 -03-2020 08:49:39.547 调试 8660 ohetinternal.TransactionImpl:在创建 TransactionImpl 时,JpaCompliance#isJpaTransactionComplianceEnabled == false 18-03-2020 08:49:39.547 调试 8660 osdjpa.repository.query.NamedQuery:未找到命名查询MessageLog.findByMsgOwnerId
@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
但是,它并不能解决问题。
我没有任何错误。我只得到空值,但请求的行在表中,这是肯定的。
有人对此有任何想法吗?
为什么 ?
解决方案
解决方案
我们正在使用的字段具有数据类型CHAR(32 byte)。我们把这个类型改成VARCHAR(32 byte)到Oracle的表数据库中。
现在,Spring 可以很好地构建命名查询。
旧版本 Spring 上的项目是这样工作的 ...( CHAR(32 byte) )
我不明白为什么会这样。
推荐阅读
- javascript - 表单上的 TimeOnly 字段已锁定但未禁用
- java - 带有 Axis2 的存根上的 java.lang.reflect.InvocationTargetException
- django - LoginTestListView 缺少 QuerySet。定义 LoginTestListView.model、LoginTestListView.queryset,或覆盖 LoginTestListView.get_queryset()
- c - 用于 memcpy、strcpy 和 strcpy_s 的 C6387
- javascript - 如何从 JS 数组中获取特定项目?
- react-native - Expo 如何管理已安装的库?
- python - 如何在频道 discord.py 中将 txt 数据作为文本发送
- python - 将多个文件中的多个工作表附加到 excel 文件中的相同工作表名称
- node.js - MailGun - 是否支持HTML 模板中的锚 ( ) 选项卡
- r - 使用 TFBSTools 和 for 循环进行 TFBS 搜索