gpt4 book ai didi

java - JPA 似乎有效但没有返回结果

转载 作者:行者123 更新时间:2023-12-02 03:40:06 25 4
gpt4 key购买 nike

我在 Eclipse 中创建了一个 Web 应用程序,其目标运行时是 WildFly 10.0。本应用程序中使用 JPA 2.1 作为持久层。配置看起来不错,但是当我尝试请求数据时,结果始终为空(大小 = 0)。

EntityManager已被注入(inject),但无法从数据库获取任何数据。而且没有错误日志,所以我无法弄清楚问题出在哪里?

这是一些文件:

io.github.mincongh.session.EmployeeSession

@Stateful
public class EmployeeSession {

@PersistenceContext(unitName = "us-address", type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;

// ...

@SuppressWarnings("unchecked")
public List<Employee> getEmployees() {
List<Employee> employees = entityManager
.createNamedQuery("Employee.findAll")
.getResultList();
if (employees.isEmpty()) {
logger.warn("No result found.");
}
return employees;
}
}

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="us-address" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/MySqlDS-addresses</jta-data-source>
<class>io.github.mincongh.entity.Address</class>
<class>io.github.mincongh.entity.AddressPK</class>
<class>io.github.mincongh.entity.Employee</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>

io.github.mincongh.entity.Employee

@Entity
@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;

private String name;

public Employee() {
}

// ...
}

io.github.mincongh.servlet.ExampleServlet

@WebServlet("/hi")
public class ExampleServlet extends HttpServlet {

@EJB
private EmployeeSession employeeSession;

// ...

protected void service(HttpServletRequest request,
HttpServletResponse response) {

System.out.println("Hello world");
List<Employee> employees = employeeSession.getEmployees();
if (employees != null) {
logger.info("`employees` are not null: " + employees.size() + " rows");
for (Employee e : employees) {
logger.info(e);
}
} else {
logger.info("`employees` are null");
}
}
}

日志

23:02:09,404 INFO  [org.jboss.modules] (main) JBoss Modules version 1.5.1.Final
23:02:09,611 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
23:02:09,678 INFO [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: WildFly Full 10.0.0.Final (WildFly Core 2.0.10.Final) starting
23:02:10,798 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found us-address.war in deployment directory. To trigger deployment create a file called us-address.war.dodeploy
23:02:10,860 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
23:02:10,893 INFO [org.xnio] (MSC service thread 1-6) XNIO version 3.3.4.Final
23:02:10,903 INFO [org.xnio.nio] (MSC service thread 1-6) XNIO NIO Implementation Version 3.3.4.Final
23:02:10,951 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 38) WFLYCLINF0001: Activating Infinispan subsystem.
23:02:10,960 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 54) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
23:02:10,973 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 37) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors
23:02:10,997 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 44) WFLYJSF0007: Activated the following JSF Implementations: [main]
23:02:11,012 INFO [org.jboss.remoting] (MSC service thread 1-6) JBoss Remoting version 4.0.18.Final
23:02:11,037 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 46) WFLYNAM0001: Activating Naming Subsystem
23:02:11,154 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 56) WFLYWS0002: Activating WebServices Extension
23:02:11,162 INFO [org.jboss.as.security] (ServerService Thread Pool -- 53) WFLYSEC0002: Activating Security Subsystem
23:02:11,168 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0003: Undertow 1.3.15.Final starting
23:02:11,168 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0003: Undertow 1.3.15.Final starting
23:02:11,168 INFO [org.jboss.as.security] (MSC service thread 1-1) WFLYSEC0001: Current PicketBox version=4.9.4.Final
23:02:11,170 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
23:02:11,180 INFO [org.jboss.as.connector] (MSC service thread 1-2) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.3.2.Final)
23:02:11,191 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0018: Started Driver service with driver-name = h2
23:02:11,214 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
23:02:11,215 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0018: Started Driver service with driver-name = mysql
23:02:11,304 INFO [org.jboss.as.naming] (MSC service thread 1-2) WFLYNAM0003: Starting Naming Service
23:02:11,304 INFO [org.jboss.as.mail.extension] (MSC service thread 1-1) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
23:02:11,481 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path '/Users/mincong/Documents/wildfly-10.0.0.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
23:02:11,514 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0012: Started server default-server.
23:02:11,515 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0018: Host default-host starting
23:02:11,551 INFO [org.jboss.as.ejb3] (MSC service thread 1-6) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 64 (per class), which is derived from thread worker pool sizing.
23:02:11,550 INFO [org.jboss.as.ejb3] (MSC service thread 1-3) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 16 (per class), which is derived from the number of CPUs on this host.
23:02:11,623 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
23:02:11,825 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
23:02:11,825 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) WFLYJCA0001: Bound data source [java:/MySqlDS-addresses]
23:02:12,107 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-1) WFLYDS0013: Started FileSystemDeploymentService for directory /Users/mincong/Documents/wildfly-10.0.0.Final/standalone/deployments
23:02:12,185 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "us-address.war" (runtime-name: "us-address.war")
23:02:12,435 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-7) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
23:02:12,435 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-2) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
23:02:12,494 INFO [org.jboss.ws.common.management] (MSC service thread 1-6) JBWS022052: Starting JBossWS 5.1.3.Final (Apache CXF 3.1.4)
23:02:15,088 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0059: Class Path entry jaxb-api.jar in /Users/mincong/Documents/wildfly-10.0.0.Final/standalone/deployments/us-address.war/WEB-INF/lib/com.sun.tools.xjc_2.2.0.jar does not point to a valid jar for a Class-Path reference.
23:02:15,088 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0059: Class Path entry jaxb-impl.jar in /Users/mincong/Documents/wildfly-10.0.0.Final/standalone/deployments/us-address.war/WEB-INF/lib/com.sun.tools.xjc_2.2.0.jar does not point to a valid jar for a Class-Path reference.
23:02:15,089 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0059: Class Path entry jsr173_1.0_api.jar in /Users/mincong/Documents/wildfly-10.0.0.Final/standalone/deployments/us-address.war/WEB-INF/lib/com.sun.tools.xjc_2.2.0.jar does not point to a valid jar for a Class-Path reference.
23:02:15,089 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0059: Class Path entry activation.jar in /Users/mincong/Documents/wildfly-10.0.0.Final/standalone/deployments/us-address.war/WEB-INF/lib/com.sun.tools.xjc_2.2.0.jar does not point to a valid jar for a Class-Path reference.
23:02:15,298 INFO [org.jboss.as.jpa] (MSC service thread 1-3) WFLYJPA0002: Read persistence.xml for us-address
23:02:15,583 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 58) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'us-address.war#us-address'
23:02:15,611 INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 58) HHH000204: Processing PersistenceUnitInfo [
name: us-address
...]
23:02:15,641 INFO [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0003: Processing weld deployment us-address.war
23:02:15,713 INFO [org.hibernate.Version] (ServerService Thread Pool -- 58) HHH000412: Hibernate Core {5.0.7.Final}
23:02:15,715 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 58) HHH000206: hibernate.properties not found
23:02:15,715 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-2) HV000001: Hibernate Validator 5.2.3.Final
23:02:15,717 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 58) HHH000021: Bytecode provider name : javassist
23:02:15,755 INFO [org.hibernate.orm.deprecation] (ServerService Thread Pool -- 58) HHH90000001: Found usage of deprecated setting for specifying Scanner [hibernate.ejb.resource_scanner]; use [hibernate.archive.scanner] instead
23:02:15,766 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 58) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
23:02:15,817 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-2) WFLYEJB0473: JNDI bindings for session bean named 'AddressSession' in deployment unit 'deployment "us-address.war"' are as follows:

java:global/us-address/AddressSession!io.github.mincongh.session.AddressSession
java:app/us-address/AddressSession!io.github.mincongh.session.AddressSession
java:module/AddressSession!io.github.mincongh.session.AddressSession
java:global/us-address/AddressSession
java:app/us-address/AddressSession
java:module/AddressSession

23:02:15,818 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-2) WFLYEJB0473: JNDI bindings for session bean named 'EmployeeSession' in deployment unit 'deployment "us-address.war"' are as follows:

java:global/us-address/EmployeeSession!io.github.mincongh.session.EmployeeSession
java:app/us-address/EmployeeSession!io.github.mincongh.session.EmployeeSession
java:module/EmployeeSession!io.github.mincongh.session.EmployeeSession
java:global/us-address/EmployeeSession
java:app/us-address/EmployeeSession
java:module/EmployeeSession

23:02:16,085 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 58) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:02:16,087 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 58) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:02:16,090 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 58) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:02:16,090 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 58) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:02:16,097 INFO [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0006: Starting Services for CDI deployment: us-address.war
23:02:16,131 INFO [org.jboss.weld.Version] (MSC service thread 1-6) WELD-000900: 2.3.2 (Final)
23:02:16,178 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0009: Starting weld service for deployment us-address.war
23:02:16,381 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 59) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'us-address.war#us-address'
23:02:16,607 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 58) WFLYCLINF0002: Started client-mappings cache from ejb container
23:02:16,919 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 59) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
23:02:16,981 INFO [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 59) Envers integration enabled? : true
23:02:17,413 INFO [org.hibernate.search.engine.Version] (ServerService Thread Pool -- 59) HSEARCH000034: Hibernate Search 5.5.3.Final
23:02:17,578 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 59) HHH000227: Running hbm2ddl schema export
23:02:17,585 INFO [stdout] (ServerService Thread Pool -- 59) Hibernate: drop table if exists Address
23:02:17,605 INFO [stdout] (ServerService Thread Pool -- 59) Hibernate: drop table if exists Employee
23:02:17,607 INFO [stdout] (ServerService Thread Pool -- 59) Hibernate: create table Address (id varchar(255) not null, seq varchar(255) not null, endlat float not null, endlong float not null, leftaddr1 varchar(255), leftaddr2 varchar(255), leftzip integer not null, name varchar(255), name_dtmf varchar(255), prefix varchar(255), prefix_dtmf varchar(255), rightaddr1 varchar(255), rightaddr2 varchar(255), rightzip integer not null, startlat float not null, startlong float not null, type varchar(255), type_dtmf varchar(255), primary key (id, seq))
23:02:17,627 INFO [stdout] (ServerService Thread Pool -- 59) Hibernate: create table Employee (id integer not null auto_increment, name varchar(255), primary key (id))
23:02:17,644 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 59) HHH000230: Schema export complete
23:02:17,652 INFO [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (ServerService Thread Pool -- 59) HHH000397: Using ASTQueryTranslatorFactory
23:02:17,809 WARN [org.hibernate.search.engine.impl.ConfigContext] (ServerService Thread Pool -- 59) HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified: using LUCENE_CURRENT.
23:02:19,435 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002225: Deploying javax.ws.rs.core.Application: class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,436 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.JAXBExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,436 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.RollbackExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,436 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.TransactionRequiredExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,436 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.unversioned.QueryResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,436 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.InvocationTargetExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,437 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.NoResultExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,437 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.EntityNotFoundExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,437 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.IOExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,437 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.EntityExistsExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,437 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.NoSuchMethodExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,437 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.IllegalArgumentExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,438 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.IllegalStateExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,438 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceUnitResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,438 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.JPARSExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,438 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.MalformedURLExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,438 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.SingleResultQueryResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,438 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.QueryTimeoutExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,438 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.PessimisticLockExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,438 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.ConversionExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.NamingExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.EntityResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.PersistenceExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.unversioned.EntityResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.PersistenceResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.QueryResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.IllegalAccessExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.PersistenceUnitResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.ClassNotFoundExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,439 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.NonUniqueResultExceptionExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,440 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.OptimisticLockExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,440 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.DatabaseExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,440 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.unversioned.SingleResultQueryResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,440 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002200: Adding class resource org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceResource from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,440 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 62) RESTEASY002205: Adding provider class org.eclipse.persistence.jpa.rs.exceptions.JPARSConfigurationExceptionMapper from Application class org.eclipse.persistence.jpa.rs.service.JPARSApplication
23:02:19,664 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 62) WFLYUT0021: Registered web context: /us-address
23:02:19,694 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "us-address.war" (runtime-name : "us-address.war")
23:02:19,806 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
23:02:19,807 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
23:02:19,807 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.0.0.Final (WildFly Core 2.0.10.Final) started in 10792ms - Started 434 of 702 services (383 services are lazy, passive or on-demand)
23:02:21,761 INFO [stdout] (default task-2) Hello world
23:02:21,781 INFO [stdout] (default task-2) Hibernate: select employee0_.id as id1_1_, employee0_.name as name2_1_ from Employee employee0_
23:02:21,810 WARN [io.github.mincongh.session.EmployeeSession] (default task-2) No result found.
23:02:21,812 INFO [io.github.mincongh.servlet.ExampleServlet] (default task-2) `employees` are not null: 0 rows

至于数据源,我使用管理界面直接在 WilfFly 容器中创建它。其JNDI值为java:/MySqlDS-addresses,已测试连接本地数据库。

那么,为什么我的实体管理器返回空数据列表,没有错误?我应该怎么做才能找出问题所在?仅供引用,我的表 employee 包含 2 行。

最佳答案

您已设置<property name="hibernate.hbm2ddl.auto" value="create" />persistence.xml 。因此,每次启动服务器时都会重新创建表。

关于java - JPA 似乎有效但没有返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36925773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com