I try to persist a knowledge session using the example code from Drools
5.5.0-Final Documentation. And I am stuck with following exception:

javax.persistence.PersistenceException: [PersistenceUnit:
org.drools.persistence.jpa] Unable to build EntityManagerFactory
        at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
        at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
        [...]
Caused by: org.hibernate.service.jndi.JndiException: Error parsing JNDI name
[jdbc/BitronixJTADataSource]
        at
org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92)
        at
org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:63)
        [...]
Caused by: javax.naming.OperationNotSupportedException
        at 
bitronix.tm.jndi.BitronixContext.getNameParser(BitronixContext.java:147)
        at javax.naming.InitialContext.getNameParser(InitialContext.java:480)
        at
org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86)
        ... 42 more


Probably I did some configuration mistake. This is my setup:

1) I added following dependencies (via maven)
drools-persistence-jpa, btm (bitronix), h2 (database),
hibernate-entitymanager
2) I created a hibernate.cfg.xml, persistence.xml and jndi.properties file
(I put the jndi.properties file in resources/META-INF ( is this correct/
related to the error ?))
3) I made all my fact classes serializable 
4) I added this code:

        PoolingDataSource ds = new PoolingDataSource();
        ds.setUniqueName( "jdbc/BitronixJTADataSource" );
        ds.setClassName( "org.h2.jdbcx.JdbcDataSource" );
        ds.setMaxPoolSize( 3 );
        ds.setAllowLocalTransactions( true );
        ds.getDriverProperties().put( "user", "sa" );
        ds.getDriverProperties().put( "password", "sasa" );
        ds.getDriverProperties().put( "URL", "jdbc:h2:mem:mydb" );
        ds.init();

        org.drools.runtime.Environment env =
KnowledgeBaseFactory.newEnvironment();        
        EntityManagerFactory emf =
Persistence.createEntityManagerFactory("org.drools.persistence.jpa");
        
        env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
        env.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
        env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
        
        StatefulKnowledgeSession ksession =
JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);


This is my Hibernate config:

<!DOCTYPE hibernate-configuration PUBLIC &quot;-//Hibernate/Hibernate
Configuration DTD 3.0//EN&quot; 
&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;>
<hibernate-configuration>
        <session-factory>
                <property 
name="dialect">org.hibernate.dialect.H2Dialect</property>
                <property 
name="connection.driver_class">org.h2.Driver</property>
                <property name="connection.username">sa</property>
                <property name="connection.password">sa</property>
                <property 
name="connection.url">jdbc:h2:file:db/drools</property>
        </session-factory>
</hibernate-configuration>

This is my persistence.xml:  

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
        xmlns="http://java.sun.com/xml/ns/persistence";
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm";
        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_1_0.xsd 
        http://java.sun.com/xml/ns/persistence/orm 
        http://java.sun.com/xml/ns/persistence/orm_1_0.xsd";>
        <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.H2Dialect" />
                        <property name="hibernate.max_fetch_depth" value="3" />
                        <property name="hibernate.hbm2ddl.auto" value="update" 
/>
                        <property name="hibernate.show_sql" value="true" />
                        <property 
name="hibernate.transaction.manager_lookup_class"
                                
value="org.hibernate.transaction.BTMTransactionManagerLookup" />
                </properties>
        </persistence-unit>
</persistence>

jndi.properties:

java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory






--
View this message in context: 
http://drools.46999.n3.nabble.com/ksession-persistence-from-docs-not-getting-it-to-work-tp4026151.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to