无法在Spring Boot中实现Drools KieSession持久性 [英] Cannot implement Drools KieSession Persistence in Spring Boot

查看:501
本文介绍了无法在Spring Boot中实现Drools KieSession持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Spring Boot Maven项目中使用 KieSession 的持久性功能实现Drools。按照


配置类

  @Configuration 
公共类PersistentDroolConfig {

public static Long KIE_SESSION_ID;
私人最终KieServices kieServices = KieServices.Factory.get();

@Bean
public KieSession kieSession(){
KieSession kieSession = kieServices.getStoreServices()。newKieSession(getKieBase(),null,getEnv());
PersistentDroolConfig.KIE_SESSION_ID = kieSession.getIdentifier();
return kieSession;
}

public KieServices getKieServices(){
initDataSource();
return kieServices;
}

public KieBase getKieBase(){
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newClassPathResource( rules / rules.drl)));
final KieRepository kieRepository = kieServices.getRepository();
kieRepository.addKieModule(kieRepository :: getDefaultReleaseId);
KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
kb.buildAll();
KieModule kieModule = kb.getKieModule();
KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
return kieContainer.getKieBase();
}

公共环境getEnv(){
环境env = kieServices.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY,Persistence.createEntityManagerFactory( org.drools.persistence.jpa)));
env.set(EnvironmentName.TRANSACTION_MANAGER,TransactionManagerServices.getTransactionManager());
return env;
}

private void initDataSource(){
PoolingDataSource ds = new PoolingDataSource();
ds.setUniqueName( jdbc / BitronixJTADataSource);
ds.setClassName( com.mysql.cj.jdbc.MysqlXADataSource);
ds.setMaxPoolSize(3);
ds.setAllowLocalTransactions(true);
ds.getDriverProperties()。put( user, root);
ds.getDriverProperties()。put( password, 1234);
ds.getDriverProperties()。put( URL, jdbc:mysql:// localhost:3306 / drool_demo);
ds.init();
}
}

控制器类

  @RestController 
公共类OfferController {

@Autowired
私人KieSession kieSession;

@GetMapping( / order / {card-type} / {price})
公共订单(@PathVariable( card-type)字符串cardType,@ PathVariable int price){
Order order = new Order(cardType,price);
kieSession.insert(order);
kieSession.fireAllRules();
退货单;
}
}

事实类

 公共类Order实现Serializable {

私有字符串名称;
private String cardType;
私人int折扣;
私人int价格;

公共订单(字符串cardType,整数价格){
this.cardType = cardType;
this.price =价格;
}

//设置和获取方法

// toString()
}

persistence.xml

 <持久性版本= 2.0 
xsi:schemaLocation = http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd
http: //java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_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.drools.persistence.jpa;
transaction-type = JTA
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
< jta-data-source> jdbc / BitronixJTADataSource< / jta-data-source>
< class> org.drools.persistence.info.SessionInfo< / class>
< class> org.drools.persistence.info.WorkItemInfo< / class>
< properties>
<属性名称= hibernate.dialect; value = org.hibernate.dialect.MySQLDialect />
<属性名称= hibernate.max_fetch_depth;值= 3 />
<属性名称= hibernate.hbm2ddl.auto;值=创建 />
<属性名称= hibernate.show_sql值=真 />
<属性名称= hibernate.transaction.manager_lookup_class值= org.hibernate.transaction.BTMTransactionManagerLookup; />
< / properties>
< / persistence-unit>
< / persistence>

pom.xml 文件中包含的依赖项如下:

 < dependencies> 
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-data-jpa< / artifactId>
< / dependency>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< / dependency>
< dependency>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< scope>运行时< / scope>
< / dependency>
< dependency>
< groupId> com.github.marcus-nl.btm< / groupId>
< artifactId> btm< / artifactId>
< version> 3.0.0-mk1< / version>
< / dependency>
< dependency>
< groupId> org.drools< / groupId>
< artifactId> drools-decisiontables< / artifactId>
< version> $ {drools-version}< / version>
< / dependency>
< dependency>
< groupId> org.drools< / groupId>
< artifactId> drools-core< / artifactId>
< version> $ {drools-version}< / version>
< / dependency>
< dependency>
< groupId> org.drools< / groupId>
< artifactId> drools-compiler< / artifactId>
< version> $ {drools-version}< / version>
< / dependency>
< dependency>
< groupId> org.drools< / groupId>
< artifactId> drools-persistence-jpa< / artifactId>
< version> $ {drools-version}< / version>
< / 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>
< / dependencies>

错误堆栈跟踪:

 原因:org.hibernate.engine.jndi.JndiException:无法查找JNDI名称[jdbc / BitronixJTADataSource] 

原因:javax.naming.NameNotFoundException:无法找到名称为'jdbc / BitronixJTADataSource'的绑定对象

该项目也可以在此存储库


更新1:


实现@jccampanero的答案后,我有了更新的堆栈跟踪:

 起因:org.hibernate.HibernateException:无法执行孤立的工作

原因:java.sql.SQLSyntaxErrorException:表'drool_demo.sessioninfo_id_seq'不存在

更新2:


进一步挖掘之后,我看到了Drools由于语法错误,无法制作必要的表格。由于Stackoverflow具有文本限制,因此仅在此处发布了重要的异常消息。就是这样:

 休眠:如果存在SessionInfo,则删除表
休眠:如果存在WorkItemInfo $,则删除表b $ b休眠:创建表SessionInfo(id bigint不为null auto_increment,lastModificationDate日期时间,rulesByteArray longblob,startDate日期时间,OPTLOCK整数,主键(id))type = MyISAM
2020-10-09 23:49:59.554 WARN 11376 --- [[main] ohtsiExceptionHandlerLoggedImpl:GenerationTarget遇到异常接受命令:执行DDL时出错创建表SessionInfo(id bigint不为null auto_increment,lastModificationDate日期时间,rulesByteArray longblob,startDate日期时间,OPTLOCK整数,主键(id)) type = MyISAM通过JDBC语句


org.hibernate.tool.schema.spi.CommandAcceptanceException:执行DDL时出错'创建表SessionInfo(id bigint不是null auto_increment,lastModificationDate日期时间,rulesByteArray longblob,startDate日期时间,OPTLOCK整数,主键(id))type = MyISAM通过JDBC语句

原因:java.sql.SQLSyntaxErrorException:SQL语法错误;在第1行

中检查与MySQL服务器版本相对应的手册,以在'type = MyISAM'附近使用正确的语法

休眠:创建表WorkItemInfo(workItemId bigint不为null auto_increment,creationDate日期时间,名称为varchar (255),processInstanceId bigint不为null,state bigint不为null,OPTLOCK整数,workItemByteArray longblob,主键(workItemId))type = MyISAM
2020-10-09 23:49:59.556 WARN 11376 --- [main ] ohtsiExceptionHandlerLoggedImpl:GenerationTarget遇到异常接受命令:执行DDL创建表WorkItemInfo(workItemId bigint不为null auto_increment,createDate日期时间,名称为varchar(255),processInstanceId bigint不为null,状态bigint不为null,OPTLOCK整数,workItemByteArray longblob,主键(workItemId))type = MyISAM通过JDBC语句

org.hibernate.tool.schema.spi.CommandAcceptanceException:执行DDL时出错创建表WorkItemInfo(workItemId bigint不是null auto_increment,creationDate日期时间,名称varchar(255),processInstanceId bigint不是null,状态bigint不为null,OPTLOCK整数,workItemByteArray longblob,主键(workItemId))type = MyISAM通过JDBC语句

原因:java.sql.SQLSyntaxErrorException:SQL语法错误;在第1行的


解决方案

我认为您的配置存在问题。 PersistentDroolConfig 类的 getKieServices 方法永远不会被调用,因此,方法<$ c $也不会被调用。 c> initDataSource 会初始化您的数据源。


也许您可以尝试修改 PersistentDroolConfig ,类似

  @Configuration 
公共类PersistentDroolConfig {

public static Long KIE_SESSION_ID;

私人KieServices kieServices;

@ PostContruct
私人无效init(){
this.initDataSource();
this.kieServices = KieServices.Factory.get();
}

@Bean
public KieSession kieSession(){
KieSession kieSession;
if(KIE_SESSION_ID == null){
kieSession = createNewKieSession();
KIE_SESSION_ID = kieSession.getIdentifier();
return kieSession;
} else {
kieSession = getPersistentKieSession();
KIE_SESSION_ID = kieSession.getIdentifier();
return kieSession;
}
}

public KieBase getKieBase(){
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newClassPathResource( rules / rules.drl)));
final KieRepository kieRepository = kieServices.getRepository();
kieRepository.addKieModule(new KieModule(){
@Override
public ReleaseId getReleaseId(){
return kieRepository.getDefaultReleaseId();
}
} );
KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
kb.buildAll();
KieModule kieModule = kb.getKieModule();
KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
KieBase kieBase = kieContainer.getKieBase();
return kieBase;
}

公共环境getEnv(){
环境env = kieServices.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY,Persistence.createEntityManagerFactory( org.drools.persistence.jpa)));
env.set(EnvironmentName.TRANSACTION_MANAGER,TransactionManagerServices.getTransactionManager());
return env;
}

私人KieSession createNewKieSession(){
KieSession kieSession = kieServices.getStoreServices()。newKieSession(getKieBase(),null,getEnv());
PersistentDroolConfig.KIE_SESSION_ID = kieSession.getIdentifier();
return kieSession;
}

私有KieSession getPersistentKieSession(){
return kieServices.getStoreServices()。loadKieSession(KIE_SESSION_ID,getKieBase(),null,getEnv());
}

private void initDataSource(){
PoolingDataSource ds = new PoolingDataSource();
ds.setUniqueName( jdbc / BitronixJTADataSource);
ds.setClassName( com.mysql.cj.jdbc.MysqlXADataSource);
ds.setMaxPoolSize(3);
ds.setAllowLocalTransactions(true);
ds.getDriverProperties()。put( user, root);
ds.getDriverProperties()。put( password, 1234);
ds.getDriverProperties()。put( URL, jdbc:mysql:// localhost:3306 / drool_demo);
ds.init();
}
}

UPDATE


如不同注释中所述,进行了这些更改之后,出现了与 SESSIONINFO_ID_SEQ 序列有关的问题,该序列用于生成字段 /drools/persistence/info/SessionInfo.java rel = nofollow noreferrer> SessionInfo


问题似乎与使用的Hibernate和MySQL版本有关。


要解决此问题,必须对 persistence.xml 文件。


首先,应包含以下属性:

 <属性名称=" hibernate.id.new_generator_mappings"值=假 /> 

在Drools示例和测试案例。参见很棒的Vlad Mihalcea文章,进行了深入的解释。


包含此配置属性产生了一个与所使用的MySQL语言有关的新问题。应该将其更改为:

 <属性名= hibernate.dialect;值= org.hibernate.dialect.MySQL5Dialect /> 

使用此配置,应用程序应运行平稳。


I was trying to implement Drools with the persistence feature of KieSession, in a Spring Boot Maven project. Followed this documentation for the implementation. Was able to do that in a normal Java application but I am getting exceptions while trying to do that in a Spring Boot application.

Below is the implementation.

The project structure

Configuration class

@Configuration
public class PersistentDroolConfig {

    public static Long KIE_SESSION_ID;
    private final KieServices kieServices = KieServices.Factory.get();

    @Bean
    public KieSession kieSession() {
        KieSession kieSession = kieServices.getStoreServices().newKieSession(getKieBase(), null, getEnv());
        PersistentDroolConfig.KIE_SESSION_ID = kieSession.getIdentifier();
        return kieSession;
    }

    public KieServices getKieServices() {
        initDataSource();
        return kieServices;
    }

    public KieBase getKieBase() {
        KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
        kieFileSystem.write(ResourceFactory.newClassPathResource("rules/rules.drl"));
        final KieRepository kieRepository = kieServices.getRepository();
        kieRepository.addKieModule(kieRepository::getDefaultReleaseId);
        KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
        kb.buildAll();
        KieModule kieModule = kb.getKieModule();
        KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
        return kieContainer.getKieBase();
    }

    public Environment getEnv() {
        Environment env = kieServices.newEnvironment();
        env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, Persistence.createEntityManagerFactory("org.drools.persistence.jpa"));
        env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
        return env;
    }

    private void initDataSource() {
        PoolingDataSource ds = new PoolingDataSource();
        ds.setUniqueName("jdbc/BitronixJTADataSource");
        ds.setClassName("com.mysql.cj.jdbc.MysqlXADataSource");
        ds.setMaxPoolSize(3);
        ds.setAllowLocalTransactions(true);
        ds.getDriverProperties().put("user", "root");
        ds.getDriverProperties().put("password", "1234");
        ds.getDriverProperties().put("URL", "jdbc:mysql://localhost:3306/drool_demo");
        ds.init();
    }
}

Controller class

@RestController
public class OfferController {

    @Autowired
    private KieSession kieSession;

    @GetMapping("/order/{card-type}/{price}")
    public Order order(@PathVariable("card-type") String cardType, @PathVariable int price) {
        Order order = new Order(cardType, price);
        kieSession.insert(order);
        kieSession.fireAllRules();
        return order;
    }
}

Fact Class

public class Order implements Serializable {

    private String name;
    private String cardType;
    private int discount;
    private int price;

    public Order(String cardType, int price) {
        this.cardType = cardType;
        this.price = price;
    }

    // setters and getters

    // toString()
}

persistence.xml

<persistence version="2.0"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd
                      http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_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.drools.persistence.jpa"
        transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/BitronixJTADataSource</jta-data-source>
        <class>org.drools.persistence.info.SessionInfo</class>
        <class>org.drools.persistence.info.WorkItemInfo</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <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>

The dependencies included in pom.xml file is as follows:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.github.marcus-nl.btm</groupId>
            <artifactId>btm</artifactId>
            <version>3.0.0-mk1</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-decisiontables</artifactId>
            <version>${drools-version}</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-core</artifactId>
            <version>${drools-version}</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-compiler</artifactId>
            <version>${drools-version}</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-persistence-jpa</artifactId>
            <version>${drools-version}</version>
        </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>
    </dependencies>

The error stacktrace:

Caused by: org.hibernate.engine.jndi.JndiException: Unable to lookup JNDI name [jdbc/BitronixJTADataSource]

Caused by: javax.naming.NameNotFoundException: unable to find a bound object at name 'jdbc/BitronixJTADataSource'

The project also can be found here in this repository.

UPDATE 1:

After implementing @jccampanero 's answer, I have a newer stacktrace:

Caused by: org.hibernate.HibernateException: Unable to perform isolated work

Caused by: java.sql.SQLSyntaxErrorException: Table 'drool_demo.sessioninfo_id_seq' doesn't exist

UPDATE 2:

After digging further, I have seen Drools isn't making the necessary tables because of some syntax error. Have posted only the important exception messages here since Stackoverflow has a text limit. Here's it is:

Hibernate: drop table if exists SessionInfo
Hibernate: drop table if exists WorkItemInfo
Hibernate: create table SessionInfo (id bigint not null auto_increment, lastModificationDate datetime, rulesByteArray longblob, startDate datetime, OPTLOCK integer, primary key (id)) type=MyISAM
2020-10-09 23:49:59.554  WARN 11376 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "create table SessionInfo (id bigint not null auto_increment, lastModificationDate datetime, rulesByteArray longblob, startDate datetime, OPTLOCK integer, primary key (id)) type=MyISAM" via JDBC Statement


org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table SessionInfo (id bigint not null auto_increment, lastModificationDate datetime, rulesByteArray longblob, startDate datetime, OPTLOCK integer, primary key (id)) type=MyISAM" via JDBC Statement

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=MyISAM' at line 1

Hibernate: create table WorkItemInfo (workItemId bigint not null auto_increment, creationDate datetime, name varchar(255), processInstanceId bigint not null, state bigint not null, OPTLOCK integer, workItemByteArray longblob, primary key (workItemId)) type=MyISAM
2020-10-09 23:49:59.556  WARN 11376 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "create table WorkItemInfo (workItemId bigint not null auto_increment, creationDate datetime, name varchar(255), processInstanceId bigint not null, state bigint not null, OPTLOCK integer, workItemByteArray longblob, primary key (workItemId)) type=MyISAM" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table WorkItemInfo (workItemId bigint not null auto_increment, creationDate datetime, name varchar(255), processInstanceId bigint not null, state bigint not null, OPTLOCK integer, workItemByteArray longblob, primary key (workItemId)) type=MyISAM" via JDBC Statement

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=MyISAM' at line 1

解决方案

I think there is a problem in your configuration. The getKieServices method of the PersistentDroolConfig class is never invoked and, as a consequence, neither is the method initDataSource which initializes your datasource.

Maybe you can try to modify your PersistentDroolConfig, something like this:

@Configuration
public class PersistentDroolConfig {

    public static Long KIE_SESSION_ID;

    private KieServices kieServices;

    @PostContruct
    private void init() {
        this.initDataSource();
        this.kieServices = KieServices.Factory.get();
    }

    @Bean
    public KieSession kieSession() {
        KieSession kieSession;
        if (KIE_SESSION_ID == null) {
            kieSession = createNewKieSession();
            KIE_SESSION_ID = kieSession.getIdentifier();
            return kieSession;
        } else {
            kieSession = getPersistentKieSession();
            KIE_SESSION_ID = kieSession.getIdentifier();
            return kieSession;
        }
    }

    public KieBase getKieBase() {
        KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
        kieFileSystem.write(ResourceFactory.newClassPathResource("rules/rules.drl"));
        final KieRepository kieRepository = kieServices.getRepository();
        kieRepository.addKieModule(new KieModule() {
            @Override
            public ReleaseId getReleaseId() {
                return kieRepository.getDefaultReleaseId();
            }
        });
        KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
        kb.buildAll();
        KieModule kieModule = kb.getKieModule();
        KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
        KieBase kieBase = kieContainer.getKieBase();
        return kieBase;
    }

    public Environment getEnv() {
        Environment env = kieServices.newEnvironment();
        env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, Persistence.createEntityManagerFactory("org.drools.persistence.jpa"));
        env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
        return env;
    }

    private KieSession createNewKieSession() {
        KieSession kieSession = kieServices.getStoreServices().newKieSession(getKieBase(), null, getEnv());
        PersistentDroolConfig.KIE_SESSION_ID = kieSession.getIdentifier();
        return kieSession;
    }

    private KieSession getPersistentKieSession() {
        return kieServices.getStoreServices().loadKieSession(KIE_SESSION_ID, getKieBase(), null, getEnv());
    }

    private void initDataSource() {
        PoolingDataSource ds = new PoolingDataSource();
        ds.setUniqueName("jdbc/BitronixJTADataSource");
        ds.setClassName("com.mysql.cj.jdbc.MysqlXADataSource");
        ds.setMaxPoolSize(3);
        ds.setAllowLocalTransactions(true);
        ds.getDriverProperties().put("user", "root");
        ds.getDriverProperties().put("password", "1234");
        ds.getDriverProperties().put("URL", "jdbc:mysql://localhost:3306/drool_demo");
        ds.init();
    }
}

UPDATE

As stated in the different comments, after making these changes, a problem arose related to the SESSIONINFO_ID_SEQ sequence used to generate the values of the field id of the entity SessionInfo.

The problem seemed to be related to the version of Hibernate and MySQL used.

To solve the problem, it is necessary to make several changes to the persistence.xml file.

First, the following property should be included:

<property name="hibernate.id.new_generator_mappings" value="false" />

It is often used in the Drools examples and test cases. See this great Vlad Mihalcea article for an in depth explanation.

The inclusion of this configuration property generated a new problem related to the MySQL dialect used. It should be changed to:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>

With this configuration, the application should run smoothly.

这篇关于无法在Spring Boot中实现Drools KieSession持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆