使用JBoss AS 7连接到DB2 db的JPA-Hibernate:HHH000183:没有为查询类找到持久化类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用JBoss AS 7连接到DB2 db的JPA-Hibernate:HHH000183:没有为查询类找到持久化类相关的知识,希望对你有一定的参考价值。
JBoss模块版本1.5.1.Final-redhat-1
接近在对象中返回数据...但到目前为止,没有骰子。我可以连接。我可以执行查询。我可以获得实体经理。但是我收到了这个错误:
[org.hibernate.hql.internal.QuerySplitter] (default task-1) HHH000183: no persistent classes found for query class: SELECT c FROM com.bank.ro.Collateral c where c.Id = 992469
我有以下项目结构;我在使用IntelliJ:
root
- pricingAPI
- main
- java
- com
- bank
- ro
Collateral.java
- dao
JPAUtility.java
JPQLDataAccessor.java
- resource
PricingSvcResource.java
- resources
persistence.xml
- webapp
- META-INF
persistence.xml
- WEB-INF
beans.xml
web.xml
- pricingEAR
- src
- main
hibernate.cfg.xml
- application
- META-INF
persistence.xml
application.xml
文件:
collateral.Java:
package com.bank.ro;
import javax.annotation.ManagedBean;
import javax.persistence.*;
import java.sql.Date;
import java.sql.Timestamp;
@ManagedBean(value = "collateral")
@Table(name = "schema.collateral")
//@Entity(name="com.bank.ro.Collateral")
public class Collateral {
private long id;
private int version;
private Timestamp createDate;
...
public Collateral(){}
@Id
@Column(name = "ID", nullable = false)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Basic
@Column(name = "VERSION", nullable = false)
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
...
}
JP A utility.Java:
package com.bank.dao;
import javax.annotation.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
@ManagedBean(value = "JPAUtility")
@PersistenceContext(unitName="collateral-persistence-unit", name="collateral-persistence-unit")
public class JPAUtility {
private static final EntityManagerFactory emFactory;
static {
emFactory = Persistence.createEntityManagerFactory("collateral-persistence-unit");
}
private static EntityManager entityManager = null;
public JPAUtility(){};
public static void setEntityManager(){
entityManager = emFactory.createEntityManager();
}
public static EntityManager getEntityManager(){
if(entityManager == null) {
setEntityManager();
}
return entityManager;
}
public static void close(){
emFactory.close();
}
}
JP Q l data access or.Java:
package com.bank.dao;
import java.util.ArrayList;
import java.util.List;
import com.bank.ro.Collateral;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaQuery;
public class JPQLDataAccessor
{
public static List<Collateral> retrieveCollateralRecords(EntityManager em, Long id)
{
final StringBuilder queryStringBuilder = new StringBuilder();
String qry = "SELECT c FROM " + Collateral.class.getName() + " c where c.Id = " + id.longValue();
queryStringBuilder.append(qry);
List colls = em.createQuery(qry).getResultList();
return colls;
}
}
pricing SVC resource.Java:
package com.bank.pricing.resource;
import java.util.ArrayList;
import java.util.List;
import com.bank.dao.JPAUtility;
import com.bank.dao.JPQLDataAccessor;
import com.bank.ro.Collateral;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.annotation.security.DenyAll;
import javax.annotation.security.PermitAll;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.bank.ro.Application;
import com.bank.ro.OffersRequest;
import javax.annotation.security.DenyAll;
import javax.annotation.security.PermitAll;
import javax.persistence.EntityManager;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import io.swagger.annotations.*;
import org.hibernate.service.spi.InjectService;
@Path("/") // hello-world
@DenyAll
@Api(value = "/", tags = "PricingSvcResource Operation")
public class PricingSvcResource {
@GET
@Produces({MediaType.TEXT_html})
@Path("hello-world/")
@PermitAll
@ApiOperation(value = "Get Hello world text.")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = String.class)})
public Response getHelloWorld()
{
return Response.ok("Hello world").build();
}
@GET
@PermitAll
@ApiOperation(value = "Get Collateral details by Collateral ID")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = String.class)})
@Path("details/{collateral_id}")
@Produces({ MediaType.TEXT_HTML})
public Response getCollateralDetails(@PathParam("collateral_id") String collateralId) {
if(collateralId==null || collateralId.isEmpty() || !collateralId.matches("^\d+$")) {
return Response.ok("There was no collateralId or it was an unusable value.")
.header("Access-Control-Allow-Origin", "*")
.build();
}
EntityManager em = JPAUtility.getEntityManager();
List<Collateral> collList = JPQLDataAccessor.retrieveCollateralRecords(em, Long.parseLong(collateralId));
Collateral coll = null;
if( collList.size() > 0 )
{
coll = collList.get(0);
}
if(coll != null) {
return Response.ok(coll.getDescription()).build();
}
return Response.ok("No collateral found for that ID").header("Access-Control-Allow-Origin", "*").build();
}
}
persistence.xml(所有这些文件):
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="collateral-persistence-unit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/collateral-ds</jta-data-source>
<class>com.bank.ro.Collateral</class>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="jboss.entity.manager.factory.jndi.name" value="persistence-units/collateral-persistence-unit"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
<property name="hibernate.connection.url" value="jdbc:db2://{host}:{port}/{DB}"/>
<property name="hibernate.connection.driver_class" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="wildfly.jpa.twophasebootstrap" value="false" />
</properties>
</persistence-unit>
</persistence>
veb.hml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>pricing-svc</display-name>
<context-param>
<param-name>resteasy.role.based.security</param-name>
<param-value>false</param-value>
</context-param>
<security-constraint>
<web-resource-collection>
<web-resource-name>Health APIs</web-resource-name>
<url-pattern>/health</url-pattern>
<url-pattern>/health/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Hello World APIs</web-resource-name>
<url-pattern>/hello-world</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>All</web-resource-name>
<url-pattern>/</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Public APIs</web-resource-name>
<url-pattern>/public</url-pattern>
<url-pattern>/public/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>All Secured APIs</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
</security-constraint>
<security-role>
<role-name>A_ROLE</role-name>
</security-role>
</web-app>
application.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" id="Application_ID" version="5">
<display-name>pricing-svcEAR</display-name>
<module id="Module_1404334226710">
<web>
<web-uri>pricing-svc.war</web-uri>
<context-root>v1/collateral2</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
hibernate.cfg.xml中:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.session_factory_name">SessionFactory</property>
<property name="hibernate.connection.url">jdbc:db2://{host}:{port}/{schema}</property>
<property name="hibernate.connection.username">XXXX</property>
<property name="hibernate.connection.password">XXXX</property>
<mapping class="com.bank.ro.Collateral"/>
</session-factory>
</hibernate-configuration>
最后,我的standalone.xml,至少是数据源部分:
<subsystem xmlns="urn:jboss:domain:datasources:4.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/collateral-ds"
pool-name="collateral-ds"
enabled="true"
use-java-context="true"
jta="true">
<datasource-class>com.ibm.db2.jcc.DB2DataSource</datasource-class>
<connection-url>${env.DS_CONNECTION_URL}</connection-url>
<connection-property name="driverType">
4
</connection-property>
<connection-property name="serverName">
${env.DS_CONNECTION_SERVER_NAME}
</connection-property>
<connection-property name="portNumber">
${env.DS_CONNECTION_PORT}
</connection-property>
<connection-property name="databaseName">
${env.DS_CONNECTION_DATABASE_NAME}
</connection-property>
<connection-property name="currentSchema">
${env.DS_CONNECTION_CURRENT_SCHEMA}
</connection-property>
<driver>${env.DS_DRIVER}</driver>
<driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
<pool>
<min-pool-size>${env.DS_POOL_MIN_SIZE}</min-pool-size>
<max-pool-size>${env.DS_POOL_MAX_SIZE}</max-pool-size>
</pool>
<security>
<user-name>${env.DS_USER_NAME}</user-name>
<password>${env.DS_PASSWORD}</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2ValidConnectionChecker"/>
<validate-on-match>true</validate-on-match>
<background-validation>false</background-validation>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2StaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2ExceptionSorter"/>
</validation>
</datasource>
<drivers>
<driver name="com.ibm.db2.jcc" module="com.ibm.db2.jcc">
<datasource-class>com.ibm.db2.jcc.DB2DataSource</datasource-class>
</driver>
<driver name="xxx-db2-driver" module="com.xxx.inf.jdbc.30">
<driver-class>com.xxx.inf.jdbc3.drivers.Db2ThrottledJdbcDriver</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>
....
<subsystem xmlns="urn:jboss:domain:ee:4.0">
<spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>
<concurrent>
<context-services>
<context-service name="default" jndi-name="java:jboss/ee/concurrency/context/default" use-transaction-setup-provider="true"/>
</context-services>
<managed-thread-factories>
<managed-thread-factory name="default" jndi-name="java:jboss/ee/concurrency/factory/default" context-service="default"/>
</managed-thread-factories>
<managed-executor-services>
<managed-executor-service name="default" jndi-name="java:jboss/ee/concurrency/executor/default" context-service="default" hung-task-threshold="60000" keepalive-time="5000"/>
</managed-executor-services>
<managed-scheduled-executor-services>
<managed-scheduled-executor-service name="default" jndi-name="java:jboss/ee/concurrency/scheduler/default" context-service="default" hung-task-threshold="60000" keepalive-time="3000"/>
</managed-scheduled-executor-services>
</concurrent>
<default-bindings
context-service="java:jboss/ee/concurrency/context/default"
managed-executor-service="java:jboss/ee/concurrency/executor/default"
managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default"
managed-thread-factory="java:jboss/ee/concurrency/factory/default"
datasource="java:jboss/datasources/collateral-ds"
/>
</subsystem>
我认为这一切都是密不可分的,尽管我们都知道......事情可以在没有宣布自己的情况下密切相关。
如果有人有任何想法,请告诉我。更多的喋喋不休导致错误:
12:26:03,718 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://0.0.0.0:9990/management
12:26:03,718 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://0.0.0.0:9990
12:26:03,719 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: JBoss EAP 7.0.0.GA (WildFly Core 2.1.2.Final-redhat-1) started in 14587ms - Started 410 of 476 services (116 services are lazy, passive or on-demand)
12:27:00,639 INFO [com.xxx.inf.api.auth.mechanisms.RestAuthenticationMechanism] (default task-1) Non protected resource, ID-Claim not checked
12:27:00,743 INFO [stdout] (default task-1) SELECT c FROM com.bank.ro.Collateral c where c.Id = 992469
12:27:00,758 WARN [org.hibernate.hql.internal.QuerySplitter] (default task-1) HHH000183: no persistent classes found for query class: SELECT c FROM com.bank.ro.Collateral c where c.Id = 992469
更新:修复是.jar up persister类并将其放在EAR_file / lib文件夹中。然后重新部署.ear。
这是不好的。这意味着我必须使.jarring the persister class(es)并将它们复制到EAR_file lib之前.earring up .war等等常规的东西,尤其是。如果我的坚持类改变了,尽管它们可能不会太多。
可能这对于更动态的业务类也是必要的,但也许不是因为我认为这是一个Hibernate范围的问题(好吧,我希望如此)。在我的情况下,我将不得不更新构建脚本,以便每次运行构建时为我执行此操作。
有一个原因是为什么发明了春天。 :)
感谢所有阅读我问题的人。
以上是关于使用JBoss AS 7连接到DB2 db的JPA-Hibernate:HHH000183:没有为查询类找到持久化类的主要内容,如果未能解决你的问题,请参考以下文章
我需要从Oracle Apex连接到DB2 AS / 400数据库。
jboss as 7 无法连接到 oracle 11.2.0.1.0