当前位置: 首页 > 知识库问答 >
问题:

使用GenericDAO插入第二个数据源时出错

养焱
2023-03-14
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")
<?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>
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;
    }
public class ItemDAO extends GenericDAO<Item> {

    private static final long serialVersionUID = 1L;

    @PersistenceContext(unitName="intrasis")
    protected transient EntityManager entityManager;

    protected ItemDAO() {
        super(Item.class);
    }



}

另一个使用另一个bank和tbm的类,我尝试了另一个bank的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个答案

葛宏爽
2023-03-14

1)您可能有一个没有指定单元名称的注入点。如果不是这样,请尝试在persistence.xml中添加这一行:

<property name="wildfly.jpa.default-unit" value="true"/>

2)在GenericDAO中不要使用:

@PersistenceContext
protected transient EntityManager entityManager;

尝试通过构造函数传递实体管理器。

 类似资料:
  • 我有一个使用Spring3.1的web应用程序。1.我们有一个使用JdbcTemplate的genericDao。数据源在GenericDaoImpl中是这样注入的。 这是一把简单的刀。 目前,凭借独特的数据源,它工作得非常完美。applicationContext配置了注释。 现在我必须集成一个新的DAO,仍然使用通用道,但在另一个数据库上工作(所以是另一个数据源)。 我在服务中使用@Trans

  • 我正在尝试从我创建的一个简单的联系人表单中插入数据。我正在使用phpMyAdmin 下面是PHP(出于安全考虑,我删除了define语句,但我可以毫无问题地建立到数据库的链接。) 当有人点击论坛上的submit按钮后,代码就会运行,据我所知,这是正常工作的。 该错误发生在php代码的末尾。正在输出“SLQ Insert Statement FAILD”,但未发布mysql错误。 我的数据库/表的设

  • 我正在开发一个应用程序,当没有移动信号覆盖区域时,将数据保存到数据库中。当服务返回时,它将从数据库中获取所有数据并上传到服务器上。 现在我有两个问题。 IntentService在第一次将数据插入数据库时停止。(当网络服务回来时,它还上传服务器上的数据,用于检查网络连接我使用定时器。(我不想停止服务。 当第二次我再次启动它创建的服务,并给出Nullpointerest xception.因为数据库

  • 我忙于一项学校作业,我有一个由三个表组成的基本access数据库。Book、Reader和BookRated,其中as BookRated是交集表,主键userName来自Reader和ISBN来自Book组成BookRated的复合主键(作为外键)。 我正试图将信息插入书签表中,但出现以下错误

  • 我正在使用Spring Boot和Spring数据,我想主要使用MySQL数据源,但如果连接失败,请转到H2数据源。 到目前为止,我只是在配置中移动@Primary,但如果我将@Primary放入MySQL(主数据源)并停止我电脑中的MySQL服务器,另一个bean就不会出现了。。。我需要什么? 谢谢!

  • 我将数据库解析为RDFlib图。现在我想把这个图中的三元组插入GraphDB三元组存储。当我在Sesame上托管的GraphDB Lite的旧版本上执行时,代码运行良好。然而,我在现在独立的GraphDB 7.0.0上执行相同的查询时出错。在引发错误之前,图形会被部分解析,插入的三元组确实会显示在三元组存储中。 这是代码的一部分: 以下是错误: 导致错误的原因是什么?如何解决?