Skip to main content



      Home
Home » Modeling » EMF » Relation doesn't exists when executing CDOServerUtil.addRepository()
Relation doesn't exists when executing CDOServerUtil.addRepository() [message #1860877] Thu, 07 September 2023 00:44 Go to next message
Eclipse UserFriend
I'm using CDO 4.10. When I try to execute the following code, I get an exception while the last line is executing CDOServerUtil.addRepository( container, registerRepository );
Quote:

org.eclipse.net4j.db.DBException: org.postgresql.util.PSQLException: ERROR: relation "battery_level_mapping" does not exist
Position: 15


        IDBAdapter dbAdapter = new PostgreSQLAdapter();
        PGSimpleDataSource dataSource = new PGSimpleDataSource();
        dataSource.setServerName( IP);
        dataSource.setPortNumber( port);
        dataSource.setDatabaseName( DB );
        dataSource.setUser( User);
        dataSource.setPassword( Pass );
        IMappingStrategy mappingStrategy = null; 
        mappingStrategy = new HorizontalAuditMappingStrategy();        
        IDBConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource);        
        Map<String, String> registerProperties = new HashMap<String, String>();
        registerProperties.put( Props.OVERRIDE_UUID, "public" );
        registerProperties.put( Props.SUPPORTING_AUDITS, String.valueOf( true ) );
        IDBStore store = CDODBUtil.createStore( mappingStrategy, dbAdapter, connectionProvider );
        IRepository registerRepository = CDOServerUtil.createRepository("public", store, registerProperties );
        IManagedContainer container = ContainerUtil.createContainer();
        JVMUtil.prepareContainer(container);
        LifecycleUtil.activate( container );
        CDOServerUtil.addRepository( container, registerRepository );


The battery_level_mapping table from the exception located in another schema, not in public but DBAdatper.readSchema() ignores the schema name I passed. Actually, DBAdatper.readSchema() recieves the schema name in UPPER case and then drops schema name to null and tries to read all tables in all schemas. It happens in the last if statement, in the code below Icopied from org.eclipse.net4j.spi.db.DBAdatper class because schemaName is in UPPER case and schemaNames contains schema names in lower case as they are in the database.

    public void readSchema(Connection connection, IDBSchema schema) {
        boolean wasTrackConstruction = DBField.isTrackConstruction();
        DBField.trackConstruction(false);

        try {
            String schemaName = schema.getName();
            DatabaseMetaData metaData = connection.getMetaData();
            Set<String> schemaNames = DBUtil.getAllSchemaNames(metaData);
            if (!schemaNames.contains(schemaName)) {
                schemaName = null;
            }
       ///////////////////////////////////////////

How can I pass schema name and avoid using other schemas other than public?

P.S. Also, you ca6n find the problem from the screenshot attached.
index.php/fa/43487/0/

[Updated on: Thu, 07 September 2023 00:47] by Moderator

Re: Relation doesn't exists when executing CDOServerUtil.addRepository() [message #1860878 is a reply to message #1860877] Thu, 07 September 2023 02:10 Go to previous messageGo to next message
Eclipse UserFriend
You didn't paste a stacktrace that shows how exactly you end up with the upper case schema name in readSchema(), so I can only guess that the call stack looks similar to this:
org.eclipse.net4j.spi.db.DBAdapter.readSchema(Connection, IDBSchema)
org.eclipse.net4j.db.DBUtil.readSchema(IDBAdapter, Connection, IDBSchema)
org.eclipse.net4j.db.DBUtil.readSchema(IDBAdapter, Connection, String, boolean)
org.eclipse.net4j.internal.db.DBDatabase.DBDatabase(...).new RunnableWithConnection() {...}.run(Connection)
org.eclipse.net4j.internal.db.DBDatabase.DBDatabase(...).new RunnableWithConnection() {...}
org.eclipse.net4j.internal.db.DBDatabase.DBDatabase(DBAdapter, IDBConnectionProvider, String, boolean)
org.eclipse.net4j.db.DBUtil.openDatabase(IDBAdapter, IDBConnectionProvider, String, boolean)
org.eclipse.emf.cdo.server.internal.db.DBStore.openDatabase(IDBAdapter, IDBConnectionProvider, String, boolean)
org.eclipse.emf.cdo.server.internal.db.DBStore.doActivate()


But that would mean that the schema name comes from DBStore.doActivate(), where it's computed like so:
String schemaName = repository.getName();
database = openDatabase(dbAdapter, dbConnectionProvider, schemaName, fixNullableIndexColumns);


Perhaps you can find out why it's upper case?

In any case you could subclass PostgreSQLAdapter and override readSchema(). If there's anything I can fix, I can do it only in master for the 4.25 release in December, not in 4.10.
Re: Relation doesn't exists when executing CDOServerUtil.addRepository() [message #1860881 is a reply to message #1860878] Thu, 07 September 2023 02:46 Go to previous messageGo to next message
Eclipse UserFriend
Quote:
Perhaps you can find out why it's upper case?

It comes from org.eclipse.net4j.db:
public static IDBSchema readSchema(IDBAdapter adapter, Connection connection, String name, boolean fixNullableIndexColumns) {
        IDBSchema schema = new DBSchema(name);


new DBSchema(name) returns upper case schema name, so IDBSchema schema contains schema in upper case; however String name is in lower case. To be more precise, it happens in org.eclipse.net4j.internal.db.ddl:
    public static String name(String name) {
        return name.toUpperCase().intern();
    }


The whole stacktrace is below:
org.eclipse.net4j.db.DBException: org.postgresql.util.PSQLException: ERROR: relation "battery_level_mapping" does not exist
  Position: 15

	at org.eclipse.net4j.spi.db.DBAdapter.readSchema(DBAdapter.java:213)
	at org.eclipse.net4j.db.DBUtil.readSchema(DBUtil.java:229)
	at org.eclipse.net4j.db.DBUtil.readSchema(DBUtil.java:254)
	at org.eclipse.net4j.internal.db.DBDatabase$1.run(DBDatabase.java:74)
	at org.eclipse.net4j.internal.db.DBDatabase$1.run(DBDatabase.java:1)
	at org.eclipse.net4j.db.DBUtil.execute(DBUtil.java:826)
	at org.eclipse.net4j.internal.db.DBDatabase.<init>(DBDatabase.java:69)
	at org.eclipse.net4j.db.DBUtil.openDatabase(DBUtil.java:216)
	at org.eclipse.emf.cdo.server.internal.db.DBStore.doActivate(DBStore.java:687)
	at org.eclipse.net4j.util.lifecycle.Lifecycle.internalActivate(Lifecycle.java:75)
	at org.eclipse.net4j.util.lifecycle.Lifecycle.activate(Lifecycle.java:164)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:127)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:117)
	at org.eclipse.emf.cdo.internal.server.Repository.doActivate(Repository.java:2584)
	at org.eclipse.net4j.util.lifecycle.Lifecycle.internalActivate(Lifecycle.java:75)
	at org.eclipse.net4j.util.lifecycle.ShareableLifecycle.internalActivate(ShareableLifecycle.java:43)
	at org.eclipse.net4j.util.lifecycle.Lifecycle.activate(Lifecycle.java:164)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:127)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:117)
	at org.eclipse.emf.cdo.server.CDOServerUtil.addRepository(CDOServerUtil.java:284)
	at com.mst.importer.xmlimport.cdoClassTest.testStore(cdoClassTest.java:64)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "battery_level_mapping" does not exist
  Position: 15
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307)
	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270)
	at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:224)
	at org.eclipse.net4j.spi.db.DBAdapter.readFields(DBAdapter.java:241)
	at org.eclipse.net4j.spi.db.DBAdapter.readSchema(DBAdapter.java:207)
	... 44 more
Re: Relation doesn't exists when executing CDOServerUtil.addRepository() [message #1860889 is a reply to message #1860881] Thu, 07 September 2023 06:05 Go to previous messageGo to next message
Eclipse UserFriend
I see!

I could make that more configurable, but not for 4.10. If you want me to address that for 4.25 please submit a GitHub issue.

In the meantime you'd have to either fork/patch DBNamedElement.name() or subclass PostgreSQLAdapter...
Re: Relation doesn't exists when executing CDOServerUtil.addRepository() [message #1860906 is a reply to message #1860889] Thu, 07 September 2023 20:12 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Eike!

I reported the problem as you advised https://github.com/eclipse-cdo/cdo/issues/19
Re: Relation doesn't exists when executing CDOServerUtil.addRepository() [message #1870608 is a reply to message #1860906] Wed, 04 September 2024 04:37 Go to previous message
Eclipse UserFriend
It took me a year to return back to my CDO upgrade, sorry for the delay :)
I tested Eike's changes in 2024.06, the issue had been fixed.
Thanks Eike!
Previous Topic:Download org.eclipse.net4j.db.postgresql
Next Topic:ERROR: relation "cdo_lobs" does not exist
Goto Forum:
  


Current Time: Sat Jul 12 15:03:19 EDT 2025

Powered by FUDForum. Page generated in 0.04915 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top