java .lang.NoSuchMethodError: org / hibernate / cfg / annotations / reflection / XMLContext. <init>(Lorg / hibernate / boot / spi / ClassLoaderAccess; - PullRequest
0 голосов
/ 07 февраля 2020

Я пытаюсь сохранить факты в слюнях "в памяти". Мой код генерирует исключения удара, когда я пытаюсь создать менеджер сущностей. пожалуйста, дайте мне знать, если в постоянстве требуются какие-либо изменения. xml

Исключение в потоке "main" java .lang.NoSuchMethodError:

org/hibernate/cfg/annotations/reflection/XMLContext.<init>(Lorg/hibernate/boot/spi/ClassLoaderAccess;)V
 (loaded from
 file:/C:/.m2/repository/org/hibernate/hibernate-annotations/3.3.1.GA/hibernate-annotations-3.3.1.GA.jar
 by sun.misc.Launcher$AppClassLoader@f05c4fc1) called from class
 org.hibernate.cfg.annotations.reflection.JPAMetadataProvider (loaded
 from
 file:/C:/.m2/repository/org/hibernate/hibernate-core/5.4.10.Final/hibernate-core-5.4.10.Final.jar
 by sun.misc.Launcher$AppClassLoader@f05c4fc1).
            at org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.<init>(JPAMetadataProvider.java:87)
            at org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.<init>(JPAMetadataProvider.java:81)
            at org.hibernate.boot.internal.BootstrapContextImpl.generateHcannReflectionManager(BootstrapContextImpl.java:315)
            at org.hibernate.boot.internal.BootstrapContextImpl.<init>(BootstrapContextImpl.java:89)
            at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:123)
            at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:141)
            at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:226)
            at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:175)
            at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76)
            at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:171)
            at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:119)
            at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
            at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
            at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
            at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
            at com.drools.jpa.jpadrools.TimeCheckClass.test(TimeCheckClass.java:91)
            at com.drools.jpa.jpadrools.JpaDroolsApplication.main(JpaDroolsApplication.java:22)

Ниже предоставлен код и persistence.xml

постоянство. xml

    <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xsi:schemaLocation=
        "http://java.sun.com/xml/ns/persistence
         http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
         http://java.sun.com/xml/ns/persistence/orm
         http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"   xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns="http://java.sun.com/xml/ns/persistence">   <persistence-unit name="org.jbpm.persistence.jpa">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/testDatasource</jta-data-source>
        <class>org.drools.persistence.info.SessionInfo</class>
        <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
        <class>org.drools.persistence.info.WorkItemInfo</class>
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
          <property name="hibernate.max_fetch_depth" value="3"/>
          <property name="hibernate.hbm2ddl.auto" value="create"/>
          <property name="hibernate.show_sql" value="true"/>
          <property name="hibernate.transaction.manager_lookup_class"
                    value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
        </properties>   </persistence-unit> </persistence>

Код слюни для сохранения фактов

    PoolingDataSource dataSource = new PoolingDataSource();
            dataSource.setUniqueName("jdbc/testDatasource");
            dataSource.setMaxPoolSize(1);
            dataSource.setAllowLocalTransactions(true);
            dataSource.setClassName("org.h2.jdbcx.JdbcDataSource");
            dataSource.setMaxPoolSize(3);
            dataSource.getDriverProperties().put("user", "sa");
            dataSource.getDriverProperties().put("password", "sa");
            dataSource.getDriverProperties().put("URL","jdbc:h2:mem:mydb");
            dataSource.close();
            dataSource.init();
            Environment env = KnowledgeBaseFactory.newEnvironment();
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
            env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
            env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
            env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory .newKnowledgeBuilder();
            kbuilder.add(new ClassPathResource("TimeCheckRules/Rule2.drl", getClass()), ResourceType.DRL); 
        if (kbuilder.hasErrors())
        {
            if (kbuilder.getErrors().size() > 0) 
            { 
                for (KnowledgeBuilderError kerror : kbuilder.getErrors())
                { 
                    System.err.println(kerror);
                    } 
                } 
            } 
        KnowledgeBase kbase =kbuilder.newKnowledgeBase(); //kbuilder.newKieBase();
        StatefulKnowledgeSession ksession1 = JPAKnowledgeService .newStatefulKnowledgeSession(kbase, null, env);
        UserTransaction ut = (UserTransaction) new InitialContext() .lookup("java:comp/UserTransaction");       
        ut.begin();
        TimeCheckClass timeCheck = new TimeCheckClass();
        timeCheck.setId("M12345");
        timeCheck.setDiffMinutes(15);
        ksession1.insert(timeCheck);
        ksession1.fireAllRules();
        ut.commit();

Зависимости:

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!--  -->
    <dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-persistence-jpa</artifactId>
    <version>5.2.0.Final</version>
    </dependency>

            <dependency>
    <groupId>org.codehaus.btm</groupId>
    <artifactId>btm</artifactId>
    <version>2.1.4</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.kie/kie-api -->
    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-api</artifactId>
        <version>7.32.0.Final</version>
    </dependency>

            <!--  -->
            <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.200</version>
       <!--  <scope>test</scope> -->
    </dependency>


        </dependencies>
...