根节点包上的唯一约束冲突,Apache Jackrabbit 和 Oracle

Unique Constraint Violation on Root Node Bundle, Apache Jackrabbit with Oracle

目前正在评估将 Apache Jackrabbit 与我们的 Oracle 数据库结合使用的早期阶段。测试 repository.xml 配置的初始设置时,出现此错误:

15:18:32.281 [main] ERROR o.a.j.c.p.p.BundleDbPersistenceManager - FATAL error while writing the bundle: deadbeef-cafe-babe-cafe-babecafebabe
java.sql.SQLException: ORA-00001: unique constraint (REPO_BUNDLE_IDX) violated

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:754) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:219) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:972) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1192) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3415) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3521) ~[ojdbc14-10.2.0.4.jar:Oracle JDBC Driver version - "10.2.0.5.0"]
    at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.3.jar:1.3]
    at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.3.jar:1.3]
    at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.3.jar:1.3]
    at org.apache.jackrabbit.core.util.db.ConnectionHelper.execute(ConnectionHelper.java:515) ~[jackrabbit-data-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.util.db.ConnectionHelper.reallyUpdate(ConnectionHelper.java:344) ~[jackrabbit-data-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.util.db.ConnectionHelper.call(ConnectionHelper.java:331) ~[jackrabbit-data-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.util.db.ConnectionHelper.call(ConnectionHelper.java:327) ~[jackrabbit-data-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.util.db.ConnectionHelper$RetryManager.doTry(ConnectionHelper.java:536) ~[jackrabbit-data-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.util.db.ConnectionHelper.update(ConnectionHelper.java:327) ~[jackrabbit-data-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager.storeBundle(BundleDbPersistenceManager.java:950) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager.putBundle(AbstractBundlePersistenceManager.java:800) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager.storeInternal(AbstractBundlePersistenceManager.java:715) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager.store(AbstractBundlePersistenceManager.java:593) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager.store(BundleDbPersistenceManager.java:482) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.state.SharedItemStateManager.createRootNodeState(SharedItemStateManager.java:1725) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.state.SharedItemStateManager.<init>(SharedItemStateManager.java:217) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.RepositoryImpl.createItemStateManager(RepositoryImpl.java:1396) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.RepositoryImpl$WorkspaceInfo.doInitialize(RepositoryImpl.java:2062) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.RepositoryImpl$WorkspaceInfo.initialize(RepositoryImpl.java:2035) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.RepositoryImpl.initStartupWorkspaces(RepositoryImpl.java:543) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:326) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:615) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.TransientRepository.getRepository(TransientRepository.java:250) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.TransientRepository.startRepository(TransientRepository.java:280) [jackrabbit-core-2.12.4.jar:2.12.4]
    at org.apache.jackrabbit.core.TransientRepository.login(TransientRepository.java:376) [jackrabbit-core-2.12.4.jar:2.12.4]

调试,我可以看到它最初检查这个包 - System Root Node - 是否存在,它确实发现它已经在数据库中,但是当试图插入 Root Node 时,它不在数据库中,然后它也尝试再次插入 System Root Node,这就是它违反约束的地方。

这是我用来创建存储库实例的代码:

Map<String, String> props = new HashMap<>();

props.put(RepositoryFactoryImpl.REPOSITORY_HOME, "jackrabbit");
props.put(RepositoryFactoryImpl.REPOSITORY_CONF, "classpath:jackrabbit/repository.xml");

Repository repository =  JcrUtils.getRepository(props);

repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

还有我的repository.xml:

<FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
    <param name="url" value="jdbc:oracle:thin:@mydb:1521:XE"/>
    <param name="user" value="myuser"/>
    <param name="password" value="mypassword"/>
    <param name="schemaObjectPrefix" value="REPO_"/>
    <param name="schemaCheckEnabled" value="false"/>
</FileSystem>

<DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
    <param name="url" value="jdbc:oracle:thin:@mydb:1521:XE"/>
    <param name="user" value="myuser"/>
    <param name="password" value="mypassword"/>
    <param name="databaseType" value="oracle"/>
    <param name="driver" value="oracle.jdbc.driver.OracleDriver"/>
    <param name="schemaObjectPrefix" value="REPO_"/>
    <param name="schemaCheckEnabled" value="false"/>
</DataStore>

<Security appName="Jackrabbit">
    <SecurityManager class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager"
                     workspaceName="security"/>
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"/>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule"/>
</Security>

<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="ContentRepo"/>
<Workspace name="ContentRepo">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
        <param name="url" value="jdbc:oracle:thin:@mydb:1521:XE"/>
        <param name="user" value="myuser"/>
        <param name="password" value="mypassword"/>
        <param name="schemaObjectPrefix" value="REPO_"/>
        <param name="schemaCheckEnabled" value="false"/>
    </FileSystem>

    <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.OraclePersistenceManager">
        <param name="url" value="jdbc:oracle:thin:@mydb:1521:XE"/>
        <param name="user" value="myuser"/>
        <param name="password" value="mypassword"/>
        <param name="schemaObjectPrefix" value="REPO_"/>
        <param name="schemaCheckEnabled" value="false"/>
    </PersistenceManager>

    <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
        <param name="path" value="${rep.home}/index"/>
        <param name="textFilterClasses" value="org.apache.jackrabbit.extractor.PlainTextExtractor,org.apache.jackrabbit.extractor.MsWordTextExtractor,org.apache.jackrabbit.extractor.MsExcelTextExtractor,org.apache.jackrabbit.extractor.MsPowerPointTextExtractor,org.apache.jackrabbit.extractor.PdfTextExtractor,org.apache.jackrabbit.extractor.OpenOfficeTextExtractor,org.apache.jackrabbit.extractor.RTFTextExtractor,org.apache.jackrabbit.extractor.HTMLTextExtractor,org.apache.jackrabbit.extractor.XMLTextExtractor"/>
        <param name="extractorPoolSize" value="2"/>
        <param name="supportHighlighting" value="true"/>
    </SearchIndex>
</Workspace>

<Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
        <param name="url" value="jdbc:oracle:thin:@mydb:1521:XE"/>
        <param name="user" value="myuser"/>
        <param name="password" value="mypassword"/>
        <param name="schemaObjectPrefix" value="REPO_"/>
        <param name="schemaCheckEnabled" value="false"/>
    </FileSystem>

    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.OraclePersistenceManager">
        <param name="url" value="jdbc:oracle:thin:@mydb:1521:XE"/>
        <param name="user" value="myuser"/>
        <param name="password" value="mypassword"/>
        <param name="schemaObjectPrefix" value="REPO_"/>
        <param name="schemaCheckEnabled" value="false"/>
    </PersistenceManager>
</Versioning>

<SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
    <param name="path" value="${rep.home}/repository/index"/>
    <param name="textFilterClasses" value="org.apache.jackrabbit.extractor.PdfTextExtractor,org.apache.jackrabbit.extractor.OpenOfficeTextExtractor,org.apache.jackrabbit.extractor.RTFTextExtractor,org.apache.jackrabbit.extractor.HTMLTextExtractor,org.apache.jackrabbit.extractor.XMLTextExtractor"/>
    <param name="extractorPoolSize" value="2"/>
    <param name="supportHighlighting" value="true"/>
</SearchIndex>

<Cluster>
    <Journal class="org.apache.jackrabbit.core.journal.OracleDatabaseJournal">
        <param name="url" value="jdbc:oracle:thin:@mydb:1521:XE"/>
        <param name="user" value="myuser"/>
        <param name="password" value="mypassword"/>
        <param name="schemaObjectPrefix" value="REPO_"/>
        <param name="schemaCheckEnabled" value="false"/>
    </Journal>
</Cluster>

版本: Oracle 11.2.0 Java 8 Apache Jackrabbit 2.12.4

感谢任何帮助。

找到了解决方法,但我确信我的配置仍然有问题,而不是 Jackrabbit Oracle 支持中的错误。

无论如何,截止日期就是这样,我能够通过覆盖 OraclePersistenceManager.storeBundle:

让一切正常进行
public class MyPersistenceManager extends OraclePersistenceManager {

    protected synchronized void storeBundle(NodePropBundle bundle) throws ItemStateException {
        if (exists(bundle.getId())) {
            bundle.markOld();
        }
        super.storeBundle(bundle);
    }

}

希望这不仅仅隐藏了一个在路上出现的问题。如果有,我会更新。