[英]Hibernate query not returning results but the same query on CLI returns 1 result
I have a class 'Employer' that I added two columns to: eop_filename, eop_directory.我有一个“雇主”类,我在其中添加了两列:eop_filename、eop_directory。 I can get results running locally with a local docker instance of the database but I get no results when I put the code on the test server.
我可以使用数据库的本地 docker 实例在本地运行结果,但是当我将代码放在测试服务器上时我没有得到任何结果。
Java 11爪哇 11
MySQL Server version: 5.7.31-0ubuntu0.18.04.1 (Ubuntu) MySQL 服务器版本:5.7.31-0ubuntu0.18.04.1 (Ubuntu)
I added them using the following我使用以下方法添加了它们
ALTER TABLE Employer ADD eop_filename VARCHAR(16);
ALTER TABLE Employer ADD eop_directory VARCHAR(24);
I added data to one of the rows for each so that when I run the following query I get 1 result我将数据添加到每一行的其中一行,以便在运行以下查询时得到 1 个结果
mysql> select eop_filename, eop_directory FROM Employer WHERE eop_filename is not null and eop_directory is not null;
+--------------+---------------+
| eop_filename | eop_directory |
+--------------+---------------+
| XYZ_2222 | demogroup |
+--------------+---------------+
In my Java code I do the following in the Repository在我的 Java 代码中,我在存储库中执行以下操作
@Repository
public class EmployerDaoImpl implements EmployerDao {
private static final Logger log = LoggerFactory.getLogger(EmployerDaoImpl.class);
private final SessionFactory sessionFactory;
@Autowired
public EmployerDaoImpl(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
public List<EopSftp> getEOPFilenamePatterns() {
try {
String query = "SELECT eop_filename, eop_directory FROM Employer WHERE eop_filename is not null AND eop_directory is not null";
Query q = sessionFactory.getCurrentSession().createQuery(query);
List<Object[]> results = q.getResultList();
log.info("results size: " + results.size());
...
And I get the following in the logs.我在日志中得到以下信息。
2020-09-25 10:51:14.403 [ajp-nio-8009-exec-193] INFO c.a.service.EOPFileProcessingService - Begin processing EOP Files.
2020-09-25 10:51:14.566 [ajp-nio-8009-exec-193] INFO com.als.dao.EmployerDaoImpl - results size: 0
My Employer class (I hate the underscores but it's following the convention of the other variable names).我的雇主类(我讨厌下划线,但它遵循其他变量名称的约定)。
@Entity
public class Employer() {
...
@Column(length=16)
private String eop_filename;
@Column(length=24)
private String eop_directory;
...
public String getEop_filename() {
return eop_filename;
}
public void setEop_filename(String eop_filename) {
this.eop_filename = eop_filename;
}
public String getEop_directory() {
return eop_directory;
}
public void setEop_directory(String eop_directory) {
this.eop_directory = eop_directory;
}
List<Object[]> results = q.getResultList(); List<Object[]> results = q.getResultList();
=> List results = q.getResultList(); => 列出结果 = q.getResultList();
btw show EopSftp
class? btw 显示
EopSftp
类?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.