Search code examples
jpadroolsjbpm

How can I change table names in KIE / Drools persistence?


My question is pretty straightforward. My persistence.xml looks like this:

<persistence 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_1_0.xsd" version="1.0">
    <persistence-unit name="org.jbpm.domain" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/jbpm</jta-data-source>

        <!-- SessionInfo -->
        <class>org.drools.persistence.info.SessionInfo</class>

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

    </persistence-unit>
</persistence>

And this creates SessionInfo and SESSIONINFO_ID_SEQ tables in my database. However, these names are not in our organisational standards, and I am trying to change the table names at least (and the column names if I could). How can I achieve this? Thanks!


Solution

  • I did it using an orm.xml file under WEB-INF/classes/META-INF, which looked like this:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <entity-mappings
            xmlns="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/orm orm_2_0.xsd"
            version="2.0">
    
        <entity class="org.drools.persistence.info.SessionInfo">
            <table name="session_info"/>
            <attributes>
                <id name="id">
                    <column name="id"/>
                    <generated-value generator="session_info_id_seq" strategy="SEQUENCE"/>
                    <sequence-generator name="session_info_id_seq" sequence-name="session_info_id_seq"/>
                </id>
                <basic name="lastModificationDate">
                    <column name="last_modification_date"/>
                </basic>
                <basic name="rulesByteArray">
                    <column name="rules_byte_array"/>
                </basic>
                <basic name="startDate">
                    <column name="start_date"/>
                </basic>
                <version name="version">
                    <column name="optlock"/>
                </version>
            </attributes>
        </entity>
    </entity-mappings>
    

    For further reference on XML overriding: Here's the official guide.