- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 GenericDAO 插入第二个数据源时出错
我正在尝试在 persistence.xml 中插入第二个碱基。我已经在jboss中配置了数据源并进行了测试。当在 xml 中插入第二个持久性单元并尝试引发 jboss 时,会发生以下错误。我尝试在每个 DAO 类中设置 @PersistenceContext(unitName = "unit-name") 和 @PersistenceUnit,但无济于事。我尝试遵循一些教程,但我不明白如何逐步适应我的上下文,也不知道是否是这种情况。
我想知道如何针对我的情况进行配置,我认为最大的区别是我有一个来自 GenericDAO 的 EntityManager,这让我很难理解。如果我必须在 DAO 或实体中注释其他内容,如果我必须创建另一个抽象类怎么办?
错误:
The persistent unitName has not been specified and there are persistent drive definitions 2 in the deployment of the deployment application "intranet.war". You can either change the deployment of the application to only have one definition of the persistence unit or specify the unitName for each reference of a persistence unit.
17: 37: 11,411 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
17: 37: 11,491 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Data source limit [java: jboss / datasources / ExampleDS]
17: 37: 11,492 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Data source limit [java: jboss / datasources / intraDS]
17: 37: 11,491 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Data source limit [java: jboss / datasources / intrasis]
17: 37: 11,524 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-4) WFLYDS0013: The FileSystemDeploymentService has been started for the directory C: \ Users \ vinicius.cipolli \ Devlopment \ jboss-eap -7.0 \ standalone \ deployments
17: 37: 11,528 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: c "intranet.war" (runtime-name: "intranet.war")
17: 37: 11,621 INFO [org.infinfin.factories.GlobalComponentRegistry] (MSC service thread 1-8) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.2.Final-redhat-1
JBWS022052: Starting JBossWS 5.1.3.SP1-redhat-1 (Apache CXF 3.1.4.redhat-1) 17:37:11,661 INFO [org.jboss.ws.common.management] (MSC service thread 1-6)
17: 37: 12,706 INFO [org.jboss.as.jpa] (MSC service thread 1-5) WFLYJPA0002: Read the persistence.xml for intranet
17: 37: 12,707 INFO [org.jboss.as.jpa] (MSC service thread 1-5) WFLYJPA0002: Read the persistence.xml for intrasis
17: 37: 12,708 WARN [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0065: Invalid signature for method init annotated with javax.annotation.PostConstruct in br.sp.corpedu.intranet.domain .acod.service.EspecialityService class. The signature must be 'void methodName (InvocationContext ctx)'
17: 37: 12,709 WARN [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0065: Invalid signature for method init annotated with javax.annotation.PostConstruct in br.sp.corpedu.intranet.expose .resources.CourseResource class. The signature must be 'void methodName (InvocationContext ctx)'
17: 37: 12,709 WARN [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0065: Invalid signature for method init annotated with javax.annotation.PostConstruct in br.sp.corpedu.intranet.expose .resources.ResourceSpeciality of the class. The signature must be 'void methodName (InvocationContext ctx)'
17: 37: 12,709 WARN [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0065: Invalid signature for method init annotated with javax.annotation.PostConstruct in br.sp.corpedu.intranet.expose .resources.esto.ItemResource of the class. The signature must be 'void methodName (InvocationContext ctx)'
17: 37: 12,719 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit. "Intranet.war" .DEPENDENCIES: org.jboss.msc .service.StartException in service jboss.deployment.unit. "intranet.war" .DEPENDENCIES: WFLYSRV0153: Failed to process DEPENDENCIES phase of deployment "intranet.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start (DeploymentUnitPhaseService.java:154)
at org.jboss.msc.service.ServiceControllerImpl $ StartTask.startService (ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl $ StartTask.run (ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.IllegalArgumentException: WFLYJPA0061: The persistent unitName has not been specified and there are persistent drive definitions 2 in the deployment of the deployment application "intranet.war". You can either change the deployment of the application to only have one definition of the persistence unit or specify the unitName for each reference of the persistence unit.
at org.jboss.as.jpa.container.PersistenceUnitSearch.ambiguousPUError (PersistenceUnitSearch.java:187)
at org.jboss.as.jpa.container.PersistenceUnitSearch.findWithinDeployment (PersistenceUnitSearch.java:153)
at org.jboss.as.jpa.container.PersistenceUnitSearch.findPersistenceUnitSupplier (PersistenceUnitSearch.java:75)
at org.jboss.as.jpa.container.PersistenceUnitSearch.resolvePersistenceUnitSupplier (PersistenceUnitSearch.java:64)
at org.jboss.as.jpa.processor.JPAAnnotationProcessor.getPersistenceUnit (JPAAnnotationProcessor.java:372)
at org.jboss.as.jpa.processor.JPAAnnotationProcessor.getBindingSource (JPAAnnotationProcessor.java:296)
at org.jboss.as.jpa.processor.JPAAnnotationProcessor.processField (JPAAnnotationProcessor.java:171)
at org.jboss.as.jpa.processor.JPAAnnotationProcessor.processPersistenceAnnotations (JPAAnnotationProcessor.java:138)
at org.jboss.as.jpa.processor.JPAAnnotationProcessor.deploy (JPAAnnotationProcessor.java:100)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start (DeploymentUnitPhaseService.java:147)
... more
17:37:12:17 ERROR [org.jboss.as.controller.management-operation]
(Controller Boot Thread) WFLYCTL0013: Deploy Failure -
address ([("deployment" = "intranet.war"])) - failure to describe:
{"WFLYCTL0080: Service Failure" =
{"jboss.deployment.unit. \" intranet.war \ "DEPENDENCIES" =
"org.jboss.msc.service.StartException in service
jboss.deployment.unit. \ "intranet.war \" DEPENDENCIES: WFLYSRV0153:
Failed to process DEPENDENCIES phase of deployment \ "intranet.war \"
Caused by: java.lang.IllegalArgumentException: WFLYJPA0061: The persisted unitName has not been specified and there are
Persistent Drive 2 in Deployment Deployment
\ "intranet.war \". You can either change the application deployment
to have only one
specify the unit for each reference of a unit of
persistence. "}} 17: 37: 12,752 INFO [org.jboss.as.server]` enter code here`
(ServerService Thread Pool - 34) WFLYSRV0010: Deployed
"intranet.war" (runtime-name: "intranet.war")
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="intranet" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/intraDS</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
<persistence-unit name="intrasis" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/intrasis</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
GenericDAO 类
public abstract class GenericDAO<T> implements Serializable {
private static final long serialVersionUID = -4843781544193464186L;
private static Logger logger = LogManager.getLogger(GenericDAO.class);
protected Class<T> classe;
@PersistenceContext
protected transient EntityManager entityManager;
protected GenericDAO(final Class<T> classe) {
this.classe = classe;
}
public T save(final T entity) {
try {
entityManager.persist(entity);
entityManager.flush();
} catch (Exception e) {
logger.error("Falha ao persistir a entidade: " + entity.toString(), e);
throw TypeApplicationException.PERSISTENCIA.buildException("Ocorreu uma falha na persistencia");
}
return entity;
}
应该使用基础 Intrasis 的类 itemDAO。在其中我尝试使用 @PersistenceContext (unitName = "intrasis")
public class ItemDAO extends GenericDAO<Item> {
private static final long serialVersionUID = 1L;
@PersistenceContext(unitName="intrasis")
protected transient EntityManager entityManager;
protected ItemDAO() {
super(Item.class);
}
}
另一个使用其他银行和 tbm 的类我尝试了其他银行的 PersistenceContext。
public class CursoDAO extends GenericDAO<Curso> {
private static final long serialVersionUID = 5659645428769766934L;
@PersistenceContext(unitName="intranet")
protected transient EntityManager entityManager;
protected CursoDAO() {
super(Curso.class);
}
public List<Curso> buscarTodos() {
String jpql = "SELECT e FROM Curso e";
TypedQuery<Curso> typedQuery = entityManager.createQuery(jpql, Curso.class);
return typedQuery.getResultList();
}
最佳答案
1) 您可能有一个未指定单元名称的注入(inject)点。如果不是这种情况,请尝试将此行添加到 persistence.xml 中:
<property name="wildfly.jpa.default-unit" value="true"/>
2)在您的 GenericDAO 中不要使用:
@PersistenceContext
protected transient EntityManager entityManager;
尝试通过构造函数传递实体管理器。
关于java - 使用 GenericDAO 插入第二个数据源时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53281973/
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
使用 GenericDAO 插入第二个数据源时出错 我正在尝试在 persistence.xml 中插入第二个碱基。我已经在jboss中配置了数据源并进行了测试。当在 xml 中插入第二个持久性单元并
我编写了以下 GenericDAO,如下面的代码所示 abstract public class DAO { // CRUD: create, read, update, delete public
我这里需要大脑! :p 我有一个接口(interface) IDAO,T 是实体类,K 是主键类。 我开发了一个具体的类 GenericDAO ,它提供 CRUD 操作和带有自动获取的条件查询(我创建
我有一个接口(interface) DAO , 以及它的通用实现 ( GenericDAO implements DAO )。 我想做这样的事情: public interface UserDao e
我有一个接口(interface) DAO , 以及它的通用实现 ( GenericDAO implements DAO )。 我想做这样的事情: public interface UserDao e
我有一个抽象的 DAO: public abstract class AbstractJpaDAO implements I_AbstractJpaDAO { private Class clazz;
我的问题可能有点基本,但想通过 Stack Overflow 人员来解决这个问题。 通常的做法是拥有域类(具有属性和 getter/setter,例如 User.java)。然后使用 DAO(即扩展
大多数人应该熟悉为 Spring + hibernate 制作通用 DAO。引用来自这里http://www.ibm.com/developerworks/java/library/j-generic
首先,我是 QueryDSL 的新手。 我正在使用 Spring + Hibernate 环境。 我面临的问题是构建一个 GenericDAO 来实现所有基本的 CRUD 操作,但我不确定如何从 QE
在这里查看了几个类似的问题并将逻辑应用于我的情况后,我仍然对我的 Spring/JPA 应用程序中的依赖项注入(inject)失败感到困惑。申请的前提是: 使用基于 JPA2 的注释来减少 xml 配
我希望 UserDao 类扩展 GenericDAO,我将在其中拥有所有 CRUD 方法。我读过 IBM 的文章:http://www.ibm.com/developerworks/java/libr
我正在实现 GenericDao。我有 2 个方法的问题 - getAll() 和 getById(Long id),实体类具有空值。看来类(class)没有设置。我怎么解决这个问题 ? @Repo
我有一个使用 Spring 3.1.1 的 Web 应用程序。我们有一个使用 JdbcTemplate 的 genericDao。数据源在 GenericDaoImpl 中像这样注入(inject)。
我们正在使用 Play! HTTP session 的框架。 tenantId 和 ipAddress 是多个表中通用的列。 当用户登录时,我们将 tenantId 存储在 HttpContextSe
我想利用 Objectify4 的新功能,但是我的应用程序是构建的并且正在使用版本 3。我的应用程序主要基于 ObjectifyGenericDao 模式构建,并且Objectify4 设计模式与此有
我们的web项目使用了spring3,Jpa(hibernate)。 为了保存 CRUD 和其他常用方法,我们将我们的存储库作为 spring JpaRepository 的子类。 有时我只是将存储库
我将我的 Spring MVC 环境更新为版本 4.0.0.RELEASE。阅读本文 (https://spring.io/blog/2013/12/03/spring-framework-4-0-a
我正在寻找 Hibernate 中的通用 DAO 实现,其中包括父/子关系管理(添加、删除、获取子项、设置父项等)。 实际上,网络上最常用的通用 DAO 是我在 jboss.org 上找到的那个。 。
我使用 Spring 3 和 Hibernate 4。我尝试在数据库中保存用户实体,但它不起作用。当我调用方法 finUsersByUsername(String username) 时,它运行良好。
我是一名优秀的程序员,十分优秀!