Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » CDO ResourceManager lifecycle
CDO ResourceManager lifecycle [message #42213] Fri, 28 July 2006 15:37 Go to next message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

Hi all,

The following piece of code causes a Unique constraint violation on the
CDO server:

// Init resource manager
ResourceManager resourceManager = ...

// Create and commit the first resource
CDOResource resource = (CDOResource) resourceManager.getResourceSet()
.createResource(URI.createURI("cdo:///uri1"));
resource.getContents().add(factory.createMyObject1());
resourceManager.commit();

// Create and commit the second resource
CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
.createResource(URI.createURI("cdo:///uri2"));
resource2.getContents().add(factory.createMyObject2());
resourceManager.commit();

The error is : "Unique constraint violation: in statement [INSERT IGNORE INTO
CDO_RESOURCE VALUES (?, ?)]"


It seems the problem comes from the 2 commits made on the same
ResourceManager. Indeed, when I remove the first one (just like in the
CDO example application), it works fine.

I would like to better understand the behaviour (lifecycle) and the role
of the ResourceManager, as well as the best way to use it.

For example: can I re-use a ResourceManager instance after a commit? Is
an instance linked to only one transaction?
Should I have to create a new instance each time I want to load a
resource (as it seems to be in the exampes)?
Am I wrong if I consider it at the same level as the Hibernate Session?


Thanks and congratulation for this two really promising projects.
Yannick
Re: CDO ResourceManager lifecycle [message #42316 is a reply to message #42213] Fri, 28 July 2006 16:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: stepper.sympedia.de

Yannick,

A ResourceManager is intended to have the same lifecycle as the
ResourceSet it's attached to.
You can imagine as a regular ResourceSet adapter (although it's
currently not implemented as such, next version it will be).

You can apply multiple, yet subsequent transactions to a whole
ResourceSet by calling commit() on the associated ResourceManager.
The same can be achieved by calling save() on an arbitrary (CDO)Resource
within that ResourceSet:

public void save(Map options)
{
try
{
resourceManager.commit();
}
catch (Throwable t)
{
logger.error("Error while committing", t);
}
}

Regarding the duplicate key issue you mention, I assume that your
database is simply not empty.
The example action to create two remote Resources is very simple. It
always uses the same URIs.
So you can only use the action once to initially create some example
Resources.
If you want to recreate the Resources you will have to drop the database
prior to that.

And thanks for your kind words about CDO ;-)
I hope it can be useful for you.

Cheers
/Eike


Yannick Lizzi schrieb:
> Hi all,
>
> The following piece of code causes a Unique constraint violation on
> the CDO server:
>
> // Init resource manager
> ResourceManager resourceManager = ...
>
> // Create and commit the first resource
> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
> .createResource(URI.createURI("cdo:///uri1"));
> resource.getContents().add(factory.createMyObject1());
> resourceManager.commit();
>
> // Create and commit the second resource
> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
> .createResource(URI.createURI("cdo:///uri2"));
> resource2.getContents().add(factory.createMyObject2());
> resourceManager.commit();
>
> The error is : "Unique constraint violation: in statement [INSERT
> INTO CDO_RESOURCE VALUES (?, ?)]"
>
>
> It seems the problem comes from the 2 commits made on the same
> ResourceManager. Indeed, when I remove the first one (just like in the
> CDO example application), it works fine.
>
> I would like to better understand the behaviour (lifecycle) and the
> role of the ResourceManager, as well as the best way to use it.
>
> For example: can I re-use a ResourceManager instance after a commit?
> Is an instance linked to only one transaction?
> Should I have to create a new instance each time I want to load a
> resource (as it seems to be in the exampes)?
> Am I wrong if I consider it at the same level as the Hibernate Session?
>
>
> Thanks and congratulation for this two really promising projects.
> Yannick
>
Re: CDO ResourceManager lifecycle [message #42514 is a reply to message #42316] Mon, 31 July 2006 09:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

Eike,

Thanks for your quick answer, it's now clear to me how to use the
ResourceManager.

Regarding the duplicate key problem, I made some tests and it seems it's
indeed a database issue. However, I don't think it's because the
database is not empty.
Actually, I made my test with HSQLDB. I used the server.properties file
provided in the CDO example and I just comment DERBY and uncomment
HSQLDB config. Here are these parameters:
jdbc.dialect=HSQLDB
jdbc.driver=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:.
jdbc.username=sa
jdbc.password=

With this configuration, the exception is raised on each execution. But
this also means that hsqldb is launched in-memory, so the database
should be empty on start.
Don't ask me why, but if I set this configuration instead:
jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.


Regards,
Yannick




Eike Stepper a écrit :
> Yannick,
>
> A ResourceManager is intended to have the same lifecycle as the
> ResourceSet it's attached to.
> You can imagine as a regular ResourceSet adapter (although it's
> currently not implemented as such, next version it will be).
>
> You can apply multiple, yet subsequent transactions to a whole
> ResourceSet by calling commit() on the associated ResourceManager.
> The same can be achieved by calling save() on an arbitrary (CDO)Resource
> within that ResourceSet:
>
> public void save(Map options)
> {
> try
> {
> resourceManager.commit();
> }
> catch (Throwable t)
> {
> logger.error("Error while committing", t);
> }
> }
>
> Regarding the duplicate key issue you mention, I assume that your
> database is simply not empty.
> The example action to create two remote Resources is very simple. It
> always uses the same URIs.
> So you can only use the action once to initially create some example
> Resources.
> If you want to recreate the Resources you will have to drop the database
> prior to that.
>
> And thanks for your kind words about CDO ;-)
> I hope it can be useful for you.
>
> Cheers
> /Eike
>
>
> Yannick Lizzi schrieb:
>> Hi all,
>>
>> The following piece of code causes a Unique constraint violation on
>> the CDO server:
>>
>> // Init resource manager
>> ResourceManager resourceManager = ...
>>
>> // Create and commit the first resource
>> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
>> .createResource(URI.createURI("cdo:///uri1"));
>> resource.getContents().add(factory.createMyObject1());
>> resourceManager.commit();
>>
>> // Create and commit the second resource
>> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
>> .createResource(URI.createURI("cdo:///uri2"));
>> resource2.getContents().add(factory.createMyObject2());
>> resourceManager.commit();
>>
>> The error is : "Unique constraint violation: in statement [INSERT
>> INTO CDO_RESOURCE VALUES (?, ?)]"
>>
>>
>> It seems the problem comes from the 2 commits made on the same
>> ResourceManager. Indeed, when I remove the first one (just like in the
>> CDO example application), it works fine.
>>
>> I would like to better understand the behaviour (lifecycle) and the
>> role of the ResourceManager, as well as the best way to use it.
>>
>> For example: can I re-use a ResourceManager instance after a commit?
>> Is an instance linked to only one transaction?
>> Should I have to create a new instance each time I want to load a
>> resource (as it seems to be in the exampes)?
>> Am I wrong if I consider it at the same level as the Hibernate Session?
>>
>>
>> Thanks and congratulation for this two really promising projects.
>> Yannick
>>
Re: CDO ResourceManager lifecycle [message #42612 is a reply to message #42514] Mon, 31 July 2006 12:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

Another important information for the error I mentioned:
I try to start the server and the client in the same jvm.
If I run my previous test with client and server in 2 separates jvm, it
works well.
Maybe I should use the embedded connector instead of the socket connector?

Yannick


Yannick Lizzi a écrit :
> Eike,
>
> Thanks for your quick answer, it's now clear to me how to use the
> ResourceManager.
>
> Regarding the duplicate key problem, I made some tests and it seems it's
> indeed a database issue. However, I don't think it's because the
> database is not empty.
> Actually, I made my test with HSQLDB. I used the server.properties file
> provided in the CDO example and I just comment DERBY and uncomment
> HSQLDB config. Here are these parameters:
> jdbc.dialect=HSQLDB
> jdbc.driver=org.hsqldb.jdbcDriver
> jdbc.url=jdbc:hsqldb:.
> jdbc.username=sa
> jdbc.password=
>
> With this configuration, the exception is raised on each execution. But
> this also means that hsqldb is launched in-memory, so the database
> should be empty on start.
> Don't ask me why, but if I set this configuration instead:
> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>
>
> Regards,
> Yannick
>
>
>
>
> Eike Stepper a écrit :
>> Yannick,
>>
>> A ResourceManager is intended to have the same lifecycle as the
>> ResourceSet it's attached to.
>> You can imagine as a regular ResourceSet adapter (although it's
>> currently not implemented as such, next version it will be).
>>
>> You can apply multiple, yet subsequent transactions to a whole
>> ResourceSet by calling commit() on the associated ResourceManager.
>> The same can be achieved by calling save() on an arbitrary
>> (CDO)Resource within that ResourceSet:
>>
>> public void save(Map options)
>> {
>> try
>> {
>> resourceManager.commit();
>> }
>> catch (Throwable t)
>> {
>> logger.error("Error while committing", t);
>> }
>> }
>>
>> Regarding the duplicate key issue you mention, I assume that your
>> database is simply not empty.
>> The example action to create two remote Resources is very simple. It
>> always uses the same URIs.
>> So you can only use the action once to initially create some example
>> Resources.
>> If you want to recreate the Resources you will have to drop the
>> database prior to that.
>>
>> And thanks for your kind words about CDO ;-)
>> I hope it can be useful for you.
>>
>> Cheers
>> /Eike
>>
>>
>> Yannick Lizzi schrieb:
>>> Hi all,
>>>
>>> The following piece of code causes a Unique constraint violation on
>>> the CDO server:
>>>
>>> // Init resource manager
>>> ResourceManager resourceManager = ...
>>>
>>> // Create and commit the first resource
>>> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
>>> .createResource(URI.createURI("cdo:///uri1"));
>>> resource.getContents().add(factory.createMyObject1());
>>> resourceManager.commit();
>>>
>>> // Create and commit the second resource
>>> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
>>> .createResource(URI.createURI("cdo:///uri2"));
>>> resource2.getContents().add(factory.createMyObject2());
>>> resourceManager.commit();
>>>
>>> The error is : "Unique constraint violation: in statement [INSERT
>>> INTO CDO_RESOURCE VALUES (?, ?)]"
>>>
>>>
>>> It seems the problem comes from the 2 commits made on the same
>>> ResourceManager. Indeed, when I remove the first one (just like in
>>> the CDO example application), it works fine.
>>>
>>> I would like to better understand the behaviour (lifecycle) and the
>>> role of the ResourceManager, as well as the best way to use it.
>>>
>>> For example: can I re-use a ResourceManager instance after a commit?
>>> Is an instance linked to only one transaction?
>>> Should I have to create a new instance each time I want to load a
>>> resource (as it seems to be in the exampes)?
>>> Am I wrong if I consider it at the same level as the Hibernate Session?
>>>
>>>
>>> Thanks and congratulation for this two really promising projects.
>>> Yannick
>>>
Re: CDO ResourceManager lifecycle [message #42705 is a reply to message #42612] Tue, 01 August 2006 04:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: stepper.sympedia.de

Yannick,

I have no idea, why in-memory hsqldb doesn't work for you. It does for me:

[INFO] common.client.connector: Connected socketChannel:
java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
remote=localhost/127.0.0.1:2036]
--> TEST: Create an EMF ResourceSet and associate it with a CDO
ResourceManager
--> TEST: Create a new CDO Resource
--> TEST: Populate the resource with an example model
--> TEST: Create a second CDO Resource
--> TEST: Populate the second resource with an example model
--> TEST: Commit the changes to the database

Even if I use the create action several times, there is no exception.
The originally created resources are reused and populated with multiple
top-level objects (libraries).
Since I can't reproduce the exception I fear I can't help with this
issue. If you can trace it to somethiing I can fix, please tell me.

The embedded connector is currently not stable and there's no example
how to configure it (actually it'd be simpler than NIO).

Cheers
/Eike


Yannick Lizzi schrieb:
> Another important information for the error I mentioned:
> I try to start the server and the client in the same jvm.
> If I run my previous test with client and server in 2 separates jvm,
> it works well.
> Maybe I should use the embedded connector instead of the socket
> connector?
>
> Yannick
>
>
> Yannick Lizzi a écrit :
>> Eike,
>>
>> Thanks for your quick answer, it's now clear to me how to use the
>> ResourceManager.
>>
>> Regarding the duplicate key problem, I made some tests and it seems
>> it's indeed a database issue. However, I don't think it's because the
>> database is not empty.
>> Actually, I made my test with HSQLDB. I used the server.properties
>> file provided in the CDO example and I just comment DERBY and
>> uncomment HSQLDB config. Here are these parameters:
>> jdbc.dialect=HSQLDB
>> jdbc.driver=org.hsqldb.jdbcDriver
>> jdbc.url=jdbc:hsqldb:.
>> jdbc.username=sa
>> jdbc.password=
>>
>> With this configuration, the exception is raised on each execution.
>> But this also means that hsqldb is launched in-memory, so the
>> database should be empty on start.
>> Don't ask me why, but if I set this configuration instead:
>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>
>>
>> Regards,
>> Yannick
>>
>>
>>
>>
>> Eike Stepper a écrit :
>>> Yannick,
>>>
>>> A ResourceManager is intended to have the same lifecycle as the
>>> ResourceSet it's attached to.
>>> You can imagine as a regular ResourceSet adapter (although it's
>>> currently not implemented as such, next version it will be).
>>>
>>> You can apply multiple, yet subsequent transactions to a whole
>>> ResourceSet by calling commit() on the associated ResourceManager.
>>> The same can be achieved by calling save() on an arbitrary
>>> (CDO)Resource within that ResourceSet:
>>>
>>> public void save(Map options)
>>> {
>>> try
>>> {
>>> resourceManager.commit();
>>> }
>>> catch (Throwable t)
>>> {
>>> logger.error("Error while committing", t);
>>> }
>>> }
>>>
>>> Regarding the duplicate key issue you mention, I assume that your
>>> database is simply not empty.
>>> The example action to create two remote Resources is very simple. It
>>> always uses the same URIs.
>>> So you can only use the action once to initially create some example
>>> Resources.
>>> If you want to recreate the Resources you will have to drop the
>>> database prior to that.
>>>
>>> And thanks for your kind words about CDO ;-)
>>> I hope it can be useful for you.
>>>
>>> Cheers
>>> /Eike
>>>
>>>
>>> Yannick Lizzi schrieb:
>>>> Hi all,
>>>>
>>>> The following piece of code causes a Unique constraint violation on
>>>> the CDO server:
>>>>
>>>> // Init resource manager
>>>> ResourceManager resourceManager = ...
>>>>
>>>> // Create and commit the first resource
>>>> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>> resource.getContents().add(factory.createMyObject1());
>>>> resourceManager.commit();
>>>>
>>>> // Create and commit the second resource
>>>> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>> resource2.getContents().add(factory.createMyObject2());
>>>> resourceManager.commit();
>>>>
>>>> The error is : "Unique constraint violation: in statement [INSERT
>>>> INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>
>>>>
>>>> It seems the problem comes from the 2 commits made on the same
>>>> ResourceManager. Indeed, when I remove the first one (just like in
>>>> the CDO example application), it works fine.
>>>>
>>>> I would like to better understand the behaviour (lifecycle) and the
>>>> role of the ResourceManager, as well as the best way to use it.
>>>>
>>>> For example: can I re-use a ResourceManager instance after a
>>>> commit? Is an instance linked to only one transaction?
>>>> Should I have to create a new instance each time I want to load a
>>>> resource (as it seems to be in the exampes)?
>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>> Session?
>>>>
>>>>
>>>> Thanks and congratulation for this two really promising projects.
>>>> Yannick
>>>>
Re: CDO ResourceManager lifecycle [message #42734 is a reply to message #42705] Tue, 01 August 2006 12:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

Eike,

OK, so let's start from the cdo/net4j example, and not from my own code.
Here are the slight modifications I make to reproduce the same error I
exeperienced

In the project org.eclipse.emf.cdo.examples.library.ui/src, in
CreateResourceAction, I add the following code at line 125:

124 resource.getContents().add(library);
125 resourceManager.commit(); // my code
126
127
128 // Create a second CDO Resource.
129 System.out.println("--> TEST: Create a second CDO Resource");


In org.eclipse.emf.cdo.examples.server/META-INF, in server.properties:
I simply comment DERBY settings, and uncomment HSQLDB settings.

I start CDO Server, then start the CDO Client1. I click on Create
Library CDO Resource.
Here is the error I get on the server console:

[INFO] net4j.slave-1: Connected socketChannel:
java.nio.channels.SocketChannel[connected local=/127.0.0.1:2036
remote=/127.0.0.1:1673]
Exception in thread "pool-1-thread-2"
org.springframework.dao.DataIntegrityViolationException:
PreparedStatementCallback; SQL [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)];
Unique constraint violation: in statement [INSERT IGNORE INTO CDO_RESOURCE
VALUES (?, ?)]; nested exception is java.sql.SQLException: Unique
constraint violation: in statement [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
java.sql.SQLException: Unique constraint violation: in statement
[INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
at
org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedSta tement(JdbcTemplate.java:697)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTempl ate.java:476)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:691)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:753)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:761)
at org.eclipse.emf.cdo.server.impl.MapperImpl.sql(MapperImpl.ja va:653)
at
org.eclipse.emf.cdo.server.impl.MapperImpl.insertResource(Ma pperImpl.java:530)
at
org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.receiveNewResources(CommitTransactionIndication.java:133 )
at
org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.access$3(CommitTransactionIndication.java:127)
at
org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion$1.doInTransactionWithoutResult(CommitTransactionIndicati on.java:82)
at
org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
at
org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:114)
at
org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.indicate(CommitTransactionIndication.java:74)
at
org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.processSi gnal(ChannelImpl.java:853)
at
org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.run(Chann elImpl.java:789)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


I'm sorry but I was wrong, the problem is probably not related to the
in-memory database, as if I change the settings to a file database, the
error is still there.

This is probably related to this second resourceManager.commit()
statement, though I don't really understand why.

Regards,
Yannick




Eike Stepper a écrit :
> Yannick,
>
> I have no idea, why in-memory hsqldb doesn't work for you. It does for me:
>
> [INFO] common.client.connector: Connected socketChannel:
> java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
> remote=localhost/127.0.0.1:2036]
> --> TEST: Create an EMF ResourceSet and associate it with a CDO
> ResourceManager
> --> TEST: Create a new CDO Resource
> --> TEST: Populate the resource with an example model
> --> TEST: Create a second CDO Resource
> --> TEST: Populate the second resource with an example model
> --> TEST: Commit the changes to the database
>
> Even if I use the create action several times, there is no exception.
> The originally created resources are reused and populated with multiple
> top-level objects (libraries).
> Since I can't reproduce the exception I fear I can't help with this
> issue. If you can trace it to somethiing I can fix, please tell me.
>
> The embedded connector is currently not stable and there's no example
> how to configure it (actually it'd be simpler than NIO).
>
> Cheers
> /Eike
>
>
> Yannick Lizzi schrieb:
>> Another important information for the error I mentioned:
>> I try to start the server and the client in the same jvm.
>> If I run my previous test with client and server in 2 separates jvm,
>> it works well.
>> Maybe I should use the embedded connector instead of the socket
>> connector?
>>
>> Yannick
>>
>>
>> Yannick Lizzi a écrit :
>>> Eike,
>>>
>>> Thanks for your quick answer, it's now clear to me how to use the
>>> ResourceManager.
>>>
>>> Regarding the duplicate key problem, I made some tests and it seems
>>> it's indeed a database issue. However, I don't think it's because the
>>> database is not empty.
>>> Actually, I made my test with HSQLDB. I used the server.properties
>>> file provided in the CDO example and I just comment DERBY and
>>> uncomment HSQLDB config. Here are these parameters:
>>> jdbc.dialect=HSQLDB
>>> jdbc.driver=org.hsqldb.jdbcDriver
>>> jdbc.url=jdbc:hsqldb:.
>>> jdbc.username=sa
>>> jdbc.password=
>>>
>>> With this configuration, the exception is raised on each execution.
>>> But this also means that hsqldb is launched in-memory, so the
>>> database should be empty on start.
>>> Don't ask me why, but if I set this configuration instead:
>>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>>
>>>
>>> Regards,
>>> Yannick
>>>
>>>
>>>
>>>
>>> Eike Stepper a écrit :
>>>> Yannick,
>>>>
>>>> A ResourceManager is intended to have the same lifecycle as the
>>>> ResourceSet it's attached to.
>>>> You can imagine as a regular ResourceSet adapter (although it's
>>>> currently not implemented as such, next version it will be).
>>>>
>>>> You can apply multiple, yet subsequent transactions to a whole
>>>> ResourceSet by calling commit() on the associated ResourceManager.
>>>> The same can be achieved by calling save() on an arbitrary
>>>> (CDO)Resource within that ResourceSet:
>>>>
>>>> public void save(Map options)
>>>> {
>>>> try
>>>> {
>>>> resourceManager.commit();
>>>> }
>>>> catch (Throwable t)
>>>> {
>>>> logger.error("Error while committing", t);
>>>> }
>>>> }
>>>>
>>>> Regarding the duplicate key issue you mention, I assume that your
>>>> database is simply not empty.
>>>> The example action to create two remote Resources is very simple. It
>>>> always uses the same URIs.
>>>> So you can only use the action once to initially create some example
>>>> Resources.
>>>> If you want to recreate the Resources you will have to drop the
>>>> database prior to that.
>>>>
>>>> And thanks for your kind words about CDO ;-)
>>>> I hope it can be useful for you.
>>>>
>>>> Cheers
>>>> /Eike
>>>>
>>>>
>>>> Yannick Lizzi schrieb:
>>>>> Hi all,
>>>>>
>>>>> The following piece of code causes a Unique constraint violation on
>>>>> the CDO server:
>>>>>
>>>>> // Init resource manager
>>>>> ResourceManager resourceManager = ...
>>>>>
>>>>> // Create and commit the first resource
>>>>> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
>>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>>> resource.getContents().add(factory.createMyObject1());
>>>>> resourceManager.commit();
>>>>>
>>>>> // Create and commit the second resource
>>>>> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
>>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>>> resource2.getContents().add(factory.createMyObject2());
>>>>> resourceManager.commit();
>>>>>
>>>>> The error is : "Unique constraint violation: in statement [INSERT
>>>>> INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>>
>>>>>
>>>>> It seems the problem comes from the 2 commits made on the same
>>>>> ResourceManager. Indeed, when I remove the first one (just like in
>>>>> the CDO example application), it works fine.
>>>>>
>>>>> I would like to better understand the behaviour (lifecycle) and the
>>>>> role of the ResourceManager, as well as the best way to use it.
>>>>>
>>>>> For example: can I re-use a ResourceManager instance after a
>>>>> commit? Is an instance linked to only one transaction?
>>>>> Should I have to create a new instance each time I want to load a
>>>>> resource (as it seems to be in the exampes)?
>>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>>> Session?
>>>>>
>>>>>
>>>>> Thanks and congratulation for this two really promising projects.
>>>>> Yannick
>>>>>
Re: CDO ResourceManager lifecycle [message #43065 is a reply to message #42734] Tue, 01 August 2006 21:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: stepper.sympedia.de

Yannick,

Indeed, that is a bug with new resources not being marked existent after
commit.
I fixed it and committed to HEAD. You should only need to update
org.eclipse.emf.cdo.client.

If you run again into issues, please set the logging priority to debug
in the /org.eclipse.net4j.util/config/log4j.xml

<root>
<priority value="debug"/>
<appender-ref ref="CONSOLE"/>
</root>

Cheers
/Eike


Yannick Lizzi schrieb:
> Eike,
>
> OK, so let's start from the cdo/net4j example, and not from my own code.
> Here are the slight modifications I make to reproduce the same error I
> exeperienced
>
> In the project org.eclipse.emf.cdo.examples.library.ui/src, in
> CreateResourceAction, I add the following code at line 125:
>
> 124 resource.getContents().add(library);
> 125 resourceManager.commit(); // my code
> 126
> 127
> 128 // Create a second CDO Resource.
> 129 System.out.println("--> TEST: Create a second CDO Resource");
>
>
> In org.eclipse.emf.cdo.examples.server/META-INF, in server.properties:
> I simply comment DERBY settings, and uncomment HSQLDB settings.
>
> I start CDO Server, then start the CDO Client1. I click on Create
> Library CDO Resource.
> Here is the error I get on the server console:
>
> [INFO] net4j.slave-1: Connected socketChannel:
> java.nio.channels.SocketChannel[connected local=/127.0.0.1:2036
> remote=/127.0.0.1:1673]
> Exception in thread "pool-1-thread-2"
> org.springframework.dao.DataIntegrityViolationException:
> PreparedStatementCallback; SQL [INSERT IGNORE INTO CDO_RESOURCE VALUES (?,
> ?)]; Unique constraint violation: in statement [INSERT IGNORE INTO
> CDO_RESOURCE VALUES (?, ?)]; nested exception is
> java.sql.SQLException: Unique constraint violation: in statement
> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
> java.sql.SQLException: Unique constraint violation: in statement
> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
> at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
> at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown
> Source)
> at
> org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedSta tement(JdbcTemplate.java:697)
>
> at
> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTempl ate.java:476)
> at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:691)
> at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:753)
> at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:761)
> at
> org.eclipse.emf.cdo.server.impl.MapperImpl.sql(MapperImpl.ja va:653)
> at
> org.eclipse.emf.cdo.server.impl.MapperImpl.insertResource(Ma pperImpl.java:530)
>
> at
> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.receiveNewResources(CommitTransactionIndication.java:133 )
>
> at
> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.access$3(CommitTransactionIndication.java:127)
>
> at
> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion$1.doInTransactionWithoutResult(CommitTransactionIndicati on.java:82)
>
> at
> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>
> at
> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:114)
>
> at
> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.indicate(CommitTransactionIndication.java:74)
>
> at
> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.processSi gnal(ChannelImpl.java:853)
>
> at
> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.run(Chann elImpl.java:789)
>
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn
> Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
>
>
> I'm sorry but I was wrong, the problem is probably not related to the
> in-memory database, as if I change the settings to a file database,
> the error is still there.
>
> This is probably related to this second resourceManager.commit()
> statement, though I don't really understand why.
>
> Regards,
> Yannick
>
>
>
>
> Eike Stepper a écrit :
>> Yannick,
>>
>> I have no idea, why in-memory hsqldb doesn't work for you. It does
>> for me:
>>
>> [INFO] common.client.connector: Connected socketChannel:
>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
>> remote=localhost/127.0.0.1:2036]
>> --> TEST: Create an EMF ResourceSet and associate it with a CDO
>> ResourceManager
>> --> TEST: Create a new CDO Resource
>> --> TEST: Populate the resource with an example model
>> --> TEST: Create a second CDO Resource
>> --> TEST: Populate the second resource with an example model
>> --> TEST: Commit the changes to the database
>>
>> Even if I use the create action several times, there is no exception.
>> The originally created resources are reused and populated with
>> multiple top-level objects (libraries).
>> Since I can't reproduce the exception I fear I can't help with this
>> issue. If you can trace it to somethiing I can fix, please tell me.
>>
>> The embedded connector is currently not stable and there's no example
>> how to configure it (actually it'd be simpler than NIO).
>>
>> Cheers
>> /Eike
>>
>>
>> Yannick Lizzi schrieb:
>>> Another important information for the error I mentioned:
>>> I try to start the server and the client in the same jvm.
>>> If I run my previous test with client and server in 2 separates jvm,
>>> it works well.
>>> Maybe I should use the embedded connector instead of the socket
>>> connector?
>>>
>>> Yannick
>>>
>>>
>>> Yannick Lizzi a écrit :
>>>> Eike,
>>>>
>>>> Thanks for your quick answer, it's now clear to me how to use the
>>>> ResourceManager.
>>>>
>>>> Regarding the duplicate key problem, I made some tests and it seems
>>>> it's indeed a database issue. However, I don't think it's because
>>>> the database is not empty.
>>>> Actually, I made my test with HSQLDB. I used the server.properties
>>>> file provided in the CDO example and I just comment DERBY and
>>>> uncomment HSQLDB config. Here are these parameters:
>>>> jdbc.dialect=HSQLDB
>>>> jdbc.driver=org.hsqldb.jdbcDriver
>>>> jdbc.url=jdbc:hsqldb:.
>>>> jdbc.username=sa
>>>> jdbc.password=
>>>>
>>>> With this configuration, the exception is raised on each execution.
>>>> But this also means that hsqldb is launched in-memory, so the
>>>> database should be empty on start.
>>>> Don't ask me why, but if I set this configuration instead:
>>>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>>>
>>>>
>>>> Regards,
>>>> Yannick
>>>>
>>>>
>>>>
>>>>
>>>> Eike Stepper a écrit :
>>>>> Yannick,
>>>>>
>>>>> A ResourceManager is intended to have the same lifecycle as the
>>>>> ResourceSet it's attached to.
>>>>> You can imagine as a regular ResourceSet adapter (although it's
>>>>> currently not implemented as such, next version it will be).
>>>>>
>>>>> You can apply multiple, yet subsequent transactions to a whole
>>>>> ResourceSet by calling commit() on the associated ResourceManager.
>>>>> The same can be achieved by calling save() on an arbitrary
>>>>> (CDO)Resource within that ResourceSet:
>>>>>
>>>>> public void save(Map options)
>>>>> {
>>>>> try
>>>>> {
>>>>> resourceManager.commit();
>>>>> }
>>>>> catch (Throwable t)
>>>>> {
>>>>> logger.error("Error while committing", t);
>>>>> }
>>>>> }
>>>>>
>>>>> Regarding the duplicate key issue you mention, I assume that your
>>>>> database is simply not empty.
>>>>> The example action to create two remote Resources is very simple.
>>>>> It always uses the same URIs.
>>>>> So you can only use the action once to initially create some
>>>>> example Resources.
>>>>> If you want to recreate the Resources you will have to drop the
>>>>> database prior to that.
>>>>>
>>>>> And thanks for your kind words about CDO ;-)
>>>>> I hope it can be useful for you.
>>>>>
>>>>> Cheers
>>>>> /Eike
>>>>>
>>>>>
>>>>> Yannick Lizzi schrieb:
>>>>>> Hi all,
>>>>>>
>>>>>> The following piece of code causes a Unique constraint violation
>>>>>> on the CDO server:
>>>>>>
>>>>>> // Init resource manager
>>>>>> ResourceManager resourceManager = ...
>>>>>>
>>>>>> // Create and commit the first resource
>>>>>> CDOResource resource = (CDOResource)
>>>>>> resourceManager.getResourceSet()
>>>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>>>> resource.getContents().add(factory.createMyObject1());
>>>>>> resourceManager.commit();
>>>>>>
>>>>>> // Create and commit the second resource
>>>>>> CDOResource resource2 = (CDOResource)
>>>>>> resourceManager.getResourceSet()
>>>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>>>> resource2.getContents().add(factory.createMyObject2());
>>>>>> resourceManager.commit();
>>>>>>
>>>>>> The error is : "Unique constraint violation: in statement
>>>>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>>>
>>>>>>
>>>>>> It seems the problem comes from the 2 commits made on the same
>>>>>> ResourceManager. Indeed, when I remove the first one (just like
>>>>>> in the CDO example application), it works fine.
>>>>>>
>>>>>> I would like to better understand the behaviour (lifecycle) and
>>>>>> the role of the ResourceManager, as well as the best way to use it.
>>>>>>
>>>>>> For example: can I re-use a ResourceManager instance after a
>>>>>> commit? Is an instance linked to only one transaction?
>>>>>> Should I have to create a new instance each time I want to load
>>>>>> a resource (as it seems to be in the exampes)?
>>>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>>>> Session?
>>>>>>
>>>>>>
>>>>>> Thanks and congratulation for this two really promising projects.
>>>>>> Yannick
>>>>>>
Re: CDO ResourceManager lifecycle [message #43163 is a reply to message #43065] Wed, 02 August 2006 08:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

OK, now it works fine !
Thanks
Yannick


Eike Stepper a écrit :
> Yannick,
>
> Indeed, that is a bug with new resources not being marked existent after
> commit.
> I fixed it and committed to HEAD. You should only need to update
> org.eclipse.emf.cdo.client.
>
> If you run again into issues, please set the logging priority to debug
> in the /org.eclipse.net4j.util/config/log4j.xml
>
> <root>
> <priority value="debug"/>
> <appender-ref ref="CONSOLE"/>
> </root>
>
> Cheers
> /Eike
>
>
> Yannick Lizzi schrieb:
>> Eike,
>>
>> OK, so let's start from the cdo/net4j example, and not from my own code.
>> Here are the slight modifications I make to reproduce the same error I
>> exeperienced
>>
>> In the project org.eclipse.emf.cdo.examples.library.ui/src, in
>> CreateResourceAction, I add the following code at line 125:
>>
>> 124 resource.getContents().add(library);
>> 125 resourceManager.commit(); // my code
>> 126
>> 127
>> 128 // Create a second CDO Resource.
>> 129 System.out.println("--> TEST: Create a second CDO Resource");
>>
>>
>> In org.eclipse.emf.cdo.examples.server/META-INF, in server.properties:
>> I simply comment DERBY settings, and uncomment HSQLDB settings.
>>
>> I start CDO Server, then start the CDO Client1. I click on Create
>> Library CDO Resource.
>> Here is the error I get on the server console:
>>
>> [INFO] net4j.slave-1: Connected socketChannel:
>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:2036
>> remote=/127.0.0.1:1673]
>> Exception in thread "pool-1-thread-2"
>> org.springframework.dao.DataIntegrityViolationException:
>> PreparedStatementCallback; SQL [INSERT IGNORE INTO CDO_RESOURCE VALUES (?,
>> ?)]; Unique constraint violation: in statement [INSERT IGNORE INTO
>> CDO_RESOURCE VALUES (?, ?)]; nested exception is
>> java.sql.SQLException: Unique constraint violation: in statement
>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
>> java.sql.SQLException: Unique constraint violation: in statement
>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
>> at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
>> at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown
>> Source)
>> at
>> org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedSta tement(JdbcTemplate.java:697)
>>
>> at
>> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTempl ate.java:476)
>> at
>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:691)
>> at
>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:753)
>> at
>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:761)
>> at
>> org.eclipse.emf.cdo.server.impl.MapperImpl.sql(MapperImpl.ja va:653)
>> at
>> org.eclipse.emf.cdo.server.impl.MapperImpl.insertResource(Ma pperImpl.java:530)
>>
>> at
>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.receiveNewResources(CommitTransactionIndication.java:133 )
>>
>> at
>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.access$3(CommitTransactionIndication.java:127)
>>
>> at
>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion$1.doInTransactionWithoutResult(CommitTransactionIndicati on.java:82)
>>
>> at
>> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>>
>> at
>> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:114)
>>
>> at
>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.indicate(CommitTransactionIndication.java:74)
>>
>> at
>> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.processSi gnal(ChannelImpl.java:853)
>>
>> at
>> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.run(Chann elImpl.java:789)
>>
>> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn
>> Source)
>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
>> at java.lang.Thread.run(Unknown Source)
>>
>>
>> I'm sorry but I was wrong, the problem is probably not related to the
>> in-memory database, as if I change the settings to a file database,
>> the error is still there.
>>
>> This is probably related to this second resourceManager.commit()
>> statement, though I don't really understand why.
>>
>> Regards,
>> Yannick
>>
>>
>>
>>
>> Eike Stepper a écrit :
>>> Yannick,
>>>
>>> I have no idea, why in-memory hsqldb doesn't work for you. It does
>>> for me:
>>>
>>> [INFO] common.client.connector: Connected socketChannel:
>>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
>>> remote=localhost/127.0.0.1:2036]
>>> --> TEST: Create an EMF ResourceSet and associate it with a CDO
>>> ResourceManager
>>> --> TEST: Create a new CDO Resource
>>> --> TEST: Populate the resource with an example model
>>> --> TEST: Create a second CDO Resource
>>> --> TEST: Populate the second resource with an example model
>>> --> TEST: Commit the changes to the database
>>>
>>> Even if I use the create action several times, there is no exception.
>>> The originally created resources are reused and populated with
>>> multiple top-level objects (libraries).
>>> Since I can't reproduce the exception I fear I can't help with this
>>> issue. If you can trace it to somethiing I can fix, please tell me.
>>>
>>> The embedded connector is currently not stable and there's no example
>>> how to configure it (actually it'd be simpler than NIO).
>>>
>>> Cheers
>>> /Eike
>>>
>>>
>>> Yannick Lizzi schrieb:
>>>> Another important information for the error I mentioned:
>>>> I try to start the server and the client in the same jvm.
>>>> If I run my previous test with client and server in 2 separates jvm,
>>>> it works well.
>>>> Maybe I should use the embedded connector instead of the socket
>>>> connector?
>>>>
>>>> Yannick
>>>>
>>>>
>>>> Yannick Lizzi a écrit :
>>>>> Eike,
>>>>>
>>>>> Thanks for your quick answer, it's now clear to me how to use the
>>>>> ResourceManager.
>>>>>
>>>>> Regarding the duplicate key problem, I made some tests and it seems
>>>>> it's indeed a database issue. However, I don't think it's because
>>>>> the database is not empty.
>>>>> Actually, I made my test with HSQLDB. I used the server.properties
>>>>> file provided in the CDO example and I just comment DERBY and
>>>>> uncomment HSQLDB config. Here are these parameters:
>>>>> jdbc.dialect=HSQLDB
>>>>> jdbc.driver=org.hsqldb.jdbcDriver
>>>>> jdbc.url=jdbc:hsqldb:.
>>>>> jdbc.username=sa
>>>>> jdbc.password=
>>>>>
>>>>> With this configuration, the exception is raised on each execution.
>>>>> But this also means that hsqldb is launched in-memory, so the
>>>>> database should be empty on start.
>>>>> Don't ask me why, but if I set this configuration instead:
>>>>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>>>>
>>>>>
>>>>> Regards,
>>>>> Yannick
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Eike Stepper a écrit :
>>>>>> Yannick,
>>>>>>
>>>>>> A ResourceManager is intended to have the same lifecycle as the
>>>>>> ResourceSet it's attached to.
>>>>>> You can imagine as a regular ResourceSet adapter (although it's
>>>>>> currently not implemented as such, next version it will be).
>>>>>>
>>>>>> You can apply multiple, yet subsequent transactions to a whole
>>>>>> ResourceSet by calling commit() on the associated ResourceManager.
>>>>>> The same can be achieved by calling save() on an arbitrary
>>>>>> (CDO)Resource within that ResourceSet:
>>>>>>
>>>>>> public void save(Map options)
>>>>>> {
>>>>>> try
>>>>>> {
>>>>>> resourceManager.commit();
>>>>>> }
>>>>>> catch (Throwable t)
>>>>>> {
>>>>>> logger.error("Error while committing", t);
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> Regarding the duplicate key issue you mention, I assume that your
>>>>>> database is simply not empty.
>>>>>> The example action to create two remote Resources is very simple.
>>>>>> It always uses the same URIs.
>>>>>> So you can only use the action once to initially create some
>>>>>> example Resources.
>>>>>> If you want to recreate the Resources you will have to drop the
>>>>>> database prior to that.
>>>>>>
>>>>>> And thanks for your kind words about CDO ;-)
>>>>>> I hope it can be useful for you.
>>>>>>
>>>>>> Cheers
>>>>>> /Eike
>>>>>>
>>>>>>
>>>>>> Yannick Lizzi schrieb:
>>>>>>> Hi all,
>>>>>>>
>>>>>>> The following piece of code causes a Unique constraint violation
>>>>>>> on the CDO server:
>>>>>>>
>>>>>>> // Init resource manager
>>>>>>> ResourceManager resourceManager = ...
>>>>>>>
>>>>>>> // Create and commit the first resource
>>>>>>> CDOResource resource = (CDOResource)
>>>>>>> resourceManager.getResourceSet()
>>>>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>>>>> resource.getContents().add(factory.createMyObject1());
>>>>>>> resourceManager.commit();
>>>>>>>
>>>>>>> // Create and commit the second resource
>>>>>>> CDOResource resource2 = (CDOResource)
>>>>>>> resourceManager.getResourceSet()
>>>>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>>>>> resource2.getContents().add(factory.createMyObject2());
>>>>>>> resourceManager.commit();
>>>>>>>
>>>>>>> The error is : "Unique constraint violation: in statement
>>>>>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>>>>
>>>>>>>
>>>>>>> It seems the problem comes from the 2 commits made on the same
>>>>>>> ResourceManager. Indeed, when I remove the first one (just like
>>>>>>> in the CDO example application), it works fine.
>>>>>>>
>>>>>>> I would like to better understand the behaviour (lifecycle) and
>>>>>>> the role of the ResourceManager, as well as the best way to use it.
>>>>>>>
>>>>>>> For example: can I re-use a ResourceManager instance after a
>>>>>>> commit? Is an instance linked to only one transaction?
>>>>>>> Should I have to create a new instance each time I want to load
>>>>>>> a resource (as it seems to be in the exampes)?
>>>>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>>>>> Session?
>>>>>>>
>>>>>>>
>>>>>>> Thanks and congratulation for this two really promising projects.
>>>>>>> Yannick
>>>>>>>
Re: CDO ResourceManager lifecycle [message #43242 is a reply to message #43163] Wed, 02 August 2006 11:51 Go to previous message
Eclipse UserFriend
Originally posted by: stepper.sympedia.de

Yannick,

I assume you are just playing around a bit with own client code.
That's ok, but I'd like to mention that you don't need two transactions
(commits) in order to add two resources.

Cheers
/Eike



Yannick Lizzi schrieb:
> OK, now it works fine !
> Thanks
> Yannick
>
>
> Eike Stepper a écrit :
>> Yannick,
>>
>> Indeed, that is a bug with new resources not being marked existent
>> after commit.
>> I fixed it and committed to HEAD. You should only need to update
>> org.eclipse.emf.cdo.client.
>>
>> If you run again into issues, please set the logging priority to
>> debug in the /org.eclipse.net4j.util/config/log4j.xml
>>
>> <root>
>> <priority value="debug"/>
>> <appender-ref ref="CONSOLE"/>
>> </root>
>>
>> Cheers
>> /Eike
>>
>>
>> Yannick Lizzi schrieb:
>>> Eike,
>>>
>>> OK, so let's start from the cdo/net4j example, and not from my own
>>> code.
>>> Here are the slight modifications I make to reproduce the same error
>>> I exeperienced
>>>
>>> In the project org.eclipse.emf.cdo.examples.library.ui/src, in
>>> CreateResourceAction, I add the following code at line 125:
>>>
>>> 124 resource.getContents().add(library);
>>> 125 resourceManager.commit(); // my code
>>> 126
>>> 127
>>> 128 // Create a second CDO Resource.
>>> 129 System.out.println("--> TEST: Create a second CDO Resource");
>>>
>>>
>>> In org.eclipse.emf.cdo.examples.server/META-INF, in server.properties:
>>> I simply comment DERBY settings, and uncomment HSQLDB settings.
>>>
>>> I start CDO Server, then start the CDO Client1. I click on Create
>>> Library CDO Resource.
>>> Here is the error I get on the server console:
>>>
>>> [INFO] net4j.slave-1: Connected socketChannel:
>>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:2036
>>> remote=/127.0.0.1:1673]
>>> Exception in thread "pool-1-thread-2"
>>> org.springframework.dao.DataIntegrityViolationException:
>>> PreparedStatementCallback; SQL [INSERT IGNORE INTO CDO_RESOURCE VALUES (?,
>>> ?)]; Unique constraint violation: in statement [INSERT IGNORE INTO
>>> CDO_RESOURCE VALUES (?, ?)]; nested exception is
>>> java.sql.SQLException: Unique constraint violation: in statement
>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
>>> java.sql.SQLException: Unique constraint violation: in statement
>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
>>> at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
>>> at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown
>>> Source)
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedSta tement(JdbcTemplate.java:697)
>>>
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTempl ate.java:476)
>>>
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:691)
>>>
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:753)
>>>
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:761)
>>>
>>> at
>>> org.eclipse.emf.cdo.server.impl.MapperImpl.sql(MapperImpl.ja va:653)
>>> at
>>> org.eclipse.emf.cdo.server.impl.MapperImpl.insertResource(Ma pperImpl.java:530)
>>>
>>> at
>>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.receiveNewResources(CommitTransactionIndication.java:133 )
>>>
>>> at
>>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.access$3(CommitTransactionIndication.java:127)
>>>
>>> at
>>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion$1.doInTransactionWithoutResult(CommitTransactionIndicati on.java:82)
>>>
>>> at
>>> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>>>
>>> at
>>> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:114)
>>>
>>> at
>>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.indicate(CommitTransactionIndication.java:74)
>>>
>>> at
>>> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.processSi gnal(ChannelImpl.java:853)
>>>
>>> at
>>> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.run(Chann elImpl.java:789)
>>>
>>> at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn Source)
>>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
>>> Source)
>>> at java.lang.Thread.run(Unknown Source)
>>>
>>>
>>> I'm sorry but I was wrong, the problem is probably not related to
>>> the in-memory database, as if I change the settings to a file
>>> database, the error is still there.
>>>
>>> This is probably related to this second resourceManager.commit()
>>> statement, though I don't really understand why.
>>>
>>> Regards,
>>> Yannick
>>>
>>>
>>>
>>>
>>> Eike Stepper a écrit :
>>>> Yannick,
>>>>
>>>> I have no idea, why in-memory hsqldb doesn't work for you. It does
>>>> for me:
>>>>
>>>> [INFO] common.client.connector: Connected socketChannel:
>>>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
>>>> remote=localhost/127.0.0.1:2036]
>>>> --> TEST: Create an EMF ResourceSet and associate it with a CDO
>>>> ResourceManager
>>>> --> TEST: Create a new CDO Resource
>>>> --> TEST: Populate the resource with an example model
>>>> --> TEST: Create a second CDO Resource
>>>> --> TEST: Populate the second resource with an example model
>>>> --> TEST: Commit the changes to the database
>>>>
>>>> Even if I use the create action several times, there is no
>>>> exception. The originally created resources are reused and
>>>> populated with multiple top-level objects (libraries).
>>>> Since I can't reproduce the exception I fear I can't help with this
>>>> issue. If you can trace it to somethiing I can fix, please tell me.
>>>>
>>>> The embedded connector is currently not stable and there's no
>>>> example how to configure it (actually it'd be simpler than NIO).
>>>>
>>>> Cheers
>>>> /Eike
>>>>
>>>>
>>>> Yannick Lizzi schrieb:
>>>>> Another important information for the error I mentioned:
>>>>> I try to start the server and the client in the same jvm.
>>>>> If I run my previous test with client and server in 2 separates
>>>>> jvm, it works well.
>>>>> Maybe I should use the embedded connector instead of the socket
>>>>> connector?
>>>>>
>>>>> Yannick
>>>>>
>>>>>
>>>>> Yannick Lizzi a écrit :
>>>>>> Eike,
>>>>>>
>>>>>> Thanks for your quick answer, it's now clear to me how to use the
>>>>>> ResourceManager.
>>>>>>
>>>>>> Regarding the duplicate key problem, I made some tests and it
>>>>>> seems it's indeed a database issue. However, I don't think it's
>>>>>> because the database is not empty.
>>>>>> Actually, I made my test with HSQLDB. I used the
>>>>>> server.properties file provided in the CDO example and I just
>>>>>> comment DERBY and uncomment HSQLDB config. Here are these
>>>>>> parameters:
>>>>>> jdbc.dialect=HSQLDB
>>>>>> jdbc.driver=org.hsqldb.jdbcDriver
>>>>>> jdbc.url=jdbc:hsqldb:.
>>>>>> jdbc.username=sa
>>>>>> jdbc.password=
>>>>>>
>>>>>> With this configuration, the exception is raised on each
>>>>>> execution. But this also means that hsqldb is launched in-memory,
>>>>>> so the database should be empty on start.
>>>>>> Don't ask me why, but if I set this configuration instead:
>>>>>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Yannick
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Eike Stepper a écrit :
>>>>>>> Yannick,
>>>>>>>
>>>>>>> A ResourceManager is intended to have the same lifecycle as the
>>>>>>> ResourceSet it's attached to.
>>>>>>> You can imagine as a regular ResourceSet adapter (although it's
>>>>>>> currently not implemented as such, next version it will be).
>>>>>>>
>>>>>>> You can apply multiple, yet subsequent transactions to a whole
>>>>>>> ResourceSet by calling commit() on the associated ResourceManager.
>>>>>>> The same can be achieved by calling save() on an arbitrary
>>>>>>> (CDO)Resource within that ResourceSet:
>>>>>>>
>>>>>>> public void save(Map options)
>>>>>>> {
>>>>>>> try
>>>>>>> {
>>>>>>> resourceManager.commit();
>>>>>>> }
>>>>>>> catch (Throwable t)
>>>>>>> {
>>>>>>> logger.error("Error while committing", t);
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> Regarding the duplicate key issue you mention, I assume that
>>>>>>> your database is simply not empty.
>>>>>>> The example action to create two remote Resources is very
>>>>>>> simple. It always uses the same URIs.
>>>>>>> So you can only use the action once to initially create some
>>>>>>> example Resources.
>>>>>>> If you want to recreate the Resources you will have to drop the
>>>>>>> database prior to that.
>>>>>>>
>>>>>>> And thanks for your kind words about CDO ;-)
>>>>>>> I hope it can be useful for you.
>>>>>>>
>>>>>>> Cheers
>>>>>>> /Eike
>>>>>>>
>>>>>>>
>>>>>>> Yannick Lizzi schrieb:
>>>>>>>> Hi all,
>>>>>>>>
>>>>>>>> The following piece of code causes a Unique constraint
>>>>>>>> violation on the CDO server:
>>>>>>>>
>>>>>>>> // Init resource manager
>>>>>>>> ResourceManager resourceManager = ...
>>>>>>>>
>>>>>>>> // Create and commit the first resource
>>>>>>>> CDOResource resource = (CDOResource)
>>>>>>>> resourceManager.getResourceSet()
>>>>>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>>>>>> resource.getContents().add(factory.createMyObject1());
>>>>>>>> resourceManager.commit();
>>>>>>>>
>>>>>>>> // Create and commit the second resource
>>>>>>>> CDOResource resource2 = (CDOResource)
>>>>>>>> resourceManager.getResourceSet()
>>>>>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>>>>>> resource2.getContents().add(factory.createMyObject2());
>>>>>>>> resourceManager.commit();
>>>>>>>>
>>>>>>>> The error is : "Unique constraint violation: in statement
>>>>>>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>>>>>
>>>>>>>>
>>>>>>>> It seems the problem comes from the 2 commits made on the same
>>>>>>>> ResourceManager. Indeed, when I remove the first one (just like
>>>>>>>> in the CDO example application), it works fine.
>>>>>>>>
>>>>>>>> I would like to better understand the behaviour (lifecycle) and
>>>>>>>> the role of the ResourceManager, as well as the best way to use
>>>>>>>> it.
>>>>>>>>
>>>>>>>> For example: can I re-use a ResourceManager instance after a
>>>>>>>> commit? Is an instance linked to only one transaction?
>>>>>>>> Should I have to create a new instance each time I want to
>>>>>>>> load a resource (as it seems to be in the exampes)?
>>>>>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>>>>>> Session?
>>>>>>>>
>>>>>>>>
>>>>>>>> Thanks and congratulation for this two really promising projects.
>>>>>>>> Yannick
>>>>>>>>
Re: CDO ResourceManager lifecycle [message #583841 is a reply to message #42213] Fri, 28 July 2006 16:18 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Yannick,

A ResourceManager is intended to have the same lifecycle as the
ResourceSet it's attached to.
You can imagine as a regular ResourceSet adapter (although it's
currently not implemented as such, next version it will be).

You can apply multiple, yet subsequent transactions to a whole
ResourceSet by calling commit() on the associated ResourceManager.
The same can be achieved by calling save() on an arbitrary (CDO)Resource
within that ResourceSet:

public void save(Map options)
{
try
{
resourceManager.commit();
}
catch (Throwable t)
{
logger.error("Error while committing", t);
}
}

Regarding the duplicate key issue you mention, I assume that your
database is simply not empty.
The example action to create two remote Resources is very simple. It
always uses the same URIs.
So you can only use the action once to initially create some example
Resources.
If you want to recreate the Resources you will have to drop the database
prior to that.

And thanks for your kind words about CDO ;-)
I hope it can be useful for you.

Cheers
/Eike


Yannick Lizzi schrieb:
> Hi all,
>
> The following piece of code causes a Unique constraint violation on
> the CDO server:
>
> // Init resource manager
> ResourceManager resourceManager = ...
>
> // Create and commit the first resource
> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
> .createResource(URI.createURI("cdo:///uri1"));
> resource.getContents().add(factory.createMyObject1());
> resourceManager.commit();
>
> // Create and commit the second resource
> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
> .createResource(URI.createURI("cdo:///uri2"));
> resource2.getContents().add(factory.createMyObject2());
> resourceManager.commit();
>
> The error is : "Unique constraint violation: in statement [INSERT
> INTO CDO_RESOURCE VALUES (?, ?)]"
>
>
> It seems the problem comes from the 2 commits made on the same
> ResourceManager. Indeed, when I remove the first one (just like in the
> CDO example application), it works fine.
>
> I would like to better understand the behaviour (lifecycle) and the
> role of the ResourceManager, as well as the best way to use it.
>
> For example: can I re-use a ResourceManager instance after a commit?
> Is an instance linked to only one transaction?
> Should I have to create a new instance each time I want to load a
> resource (as it seems to be in the exampes)?
> Am I wrong if I consider it at the same level as the Hibernate Session?
>
>
> Thanks and congratulation for this two really promising projects.
> Yannick
>


Re: CDO ResourceManager lifecycle [message #583965 is a reply to message #42316] Mon, 31 July 2006 09:46 Go to previous message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

Eike,

Thanks for your quick answer, it's now clear to me how to use the
ResourceManager.

Regarding the duplicate key problem, I made some tests and it seems it's
indeed a database issue. However, I don't think it's because the
database is not empty.
Actually, I made my test with HSQLDB. I used the server.properties file
provided in the CDO example and I just comment DERBY and uncomment
HSQLDB config. Here are these parameters:
jdbc.dialect=HSQLDB
jdbc.driver=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:.
jdbc.username=sa
jdbc.password=

With this configuration, the exception is raised on each execution. But
this also means that hsqldb is launched in-memory, so the database
should be empty on start.
Don't ask me why, but if I set this configuration instead:
jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.


Regards,
Yannick




Eike Stepper a écrit :
> Yannick,
>
> A ResourceManager is intended to have the same lifecycle as the
> ResourceSet it's attached to.
> You can imagine as a regular ResourceSet adapter (although it's
> currently not implemented as such, next version it will be).
>
> You can apply multiple, yet subsequent transactions to a whole
> ResourceSet by calling commit() on the associated ResourceManager.
> The same can be achieved by calling save() on an arbitrary (CDO)Resource
> within that ResourceSet:
>
> public void save(Map options)
> {
> try
> {
> resourceManager.commit();
> }
> catch (Throwable t)
> {
> logger.error("Error while committing", t);
> }
> }
>
> Regarding the duplicate key issue you mention, I assume that your
> database is simply not empty.
> The example action to create two remote Resources is very simple. It
> always uses the same URIs.
> So you can only use the action once to initially create some example
> Resources.
> If you want to recreate the Resources you will have to drop the database
> prior to that.
>
> And thanks for your kind words about CDO ;-)
> I hope it can be useful for you.
>
> Cheers
> /Eike
>
>
> Yannick Lizzi schrieb:
>> Hi all,
>>
>> The following piece of code causes a Unique constraint violation on
>> the CDO server:
>>
>> // Init resource manager
>> ResourceManager resourceManager = ...
>>
>> // Create and commit the first resource
>> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
>> .createResource(URI.createURI("cdo:///uri1"));
>> resource.getContents().add(factory.createMyObject1());
>> resourceManager.commit();
>>
>> // Create and commit the second resource
>> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
>> .createResource(URI.createURI("cdo:///uri2"));
>> resource2.getContents().add(factory.createMyObject2());
>> resourceManager.commit();
>>
>> The error is : "Unique constraint violation: in statement [INSERT
>> INTO CDO_RESOURCE VALUES (?, ?)]"
>>
>>
>> It seems the problem comes from the 2 commits made on the same
>> ResourceManager. Indeed, when I remove the first one (just like in the
>> CDO example application), it works fine.
>>
>> I would like to better understand the behaviour (lifecycle) and the
>> role of the ResourceManager, as well as the best way to use it.
>>
>> For example: can I re-use a ResourceManager instance after a commit?
>> Is an instance linked to only one transaction?
>> Should I have to create a new instance each time I want to load a
>> resource (as it seems to be in the exampes)?
>> Am I wrong if I consider it at the same level as the Hibernate Session?
>>
>>
>> Thanks and congratulation for this two really promising projects.
>> Yannick
>>
Re: CDO ResourceManager lifecycle [message #584016 is a reply to message #42514] Mon, 31 July 2006 12:16 Go to previous message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

Another important information for the error I mentioned:
I try to start the server and the client in the same jvm.
If I run my previous test with client and server in 2 separates jvm, it
works well.
Maybe I should use the embedded connector instead of the socket connector?

Yannick


Yannick Lizzi a écrit :
> Eike,
>
> Thanks for your quick answer, it's now clear to me how to use the
> ResourceManager.
>
> Regarding the duplicate key problem, I made some tests and it seems it's
> indeed a database issue. However, I don't think it's because the
> database is not empty.
> Actually, I made my test with HSQLDB. I used the server.properties file
> provided in the CDO example and I just comment DERBY and uncomment
> HSQLDB config. Here are these parameters:
> jdbc.dialect=HSQLDB
> jdbc.driver=org.hsqldb.jdbcDriver
> jdbc.url=jdbc:hsqldb:.
> jdbc.username=sa
> jdbc.password=
>
> With this configuration, the exception is raised on each execution. But
> this also means that hsqldb is launched in-memory, so the database
> should be empty on start.
> Don't ask me why, but if I set this configuration instead:
> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>
>
> Regards,
> Yannick
>
>
>
>
> Eike Stepper a écrit :
>> Yannick,
>>
>> A ResourceManager is intended to have the same lifecycle as the
>> ResourceSet it's attached to.
>> You can imagine as a regular ResourceSet adapter (although it's
>> currently not implemented as such, next version it will be).
>>
>> You can apply multiple, yet subsequent transactions to a whole
>> ResourceSet by calling commit() on the associated ResourceManager.
>> The same can be achieved by calling save() on an arbitrary
>> (CDO)Resource within that ResourceSet:
>>
>> public void save(Map options)
>> {
>> try
>> {
>> resourceManager.commit();
>> }
>> catch (Throwable t)
>> {
>> logger.error("Error while committing", t);
>> }
>> }
>>
>> Regarding the duplicate key issue you mention, I assume that your
>> database is simply not empty.
>> The example action to create two remote Resources is very simple. It
>> always uses the same URIs.
>> So you can only use the action once to initially create some example
>> Resources.
>> If you want to recreate the Resources you will have to drop the
>> database prior to that.
>>
>> And thanks for your kind words about CDO ;-)
>> I hope it can be useful for you.
>>
>> Cheers
>> /Eike
>>
>>
>> Yannick Lizzi schrieb:
>>> Hi all,
>>>
>>> The following piece of code causes a Unique constraint violation on
>>> the CDO server:
>>>
>>> // Init resource manager
>>> ResourceManager resourceManager = ...
>>>
>>> // Create and commit the first resource
>>> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
>>> .createResource(URI.createURI("cdo:///uri1"));
>>> resource.getContents().add(factory.createMyObject1());
>>> resourceManager.commit();
>>>
>>> // Create and commit the second resource
>>> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
>>> .createResource(URI.createURI("cdo:///uri2"));
>>> resource2.getContents().add(factory.createMyObject2());
>>> resourceManager.commit();
>>>
>>> The error is : "Unique constraint violation: in statement [INSERT
>>> INTO CDO_RESOURCE VALUES (?, ?)]"
>>>
>>>
>>> It seems the problem comes from the 2 commits made on the same
>>> ResourceManager. Indeed, when I remove the first one (just like in
>>> the CDO example application), it works fine.
>>>
>>> I would like to better understand the behaviour (lifecycle) and the
>>> role of the ResourceManager, as well as the best way to use it.
>>>
>>> For example: can I re-use a ResourceManager instance after a commit?
>>> Is an instance linked to only one transaction?
>>> Should I have to create a new instance each time I want to load a
>>> resource (as it seems to be in the exampes)?
>>> Am I wrong if I consider it at the same level as the Hibernate Session?
>>>
>>>
>>> Thanks and congratulation for this two really promising projects.
>>> Yannick
>>>
Re: CDO ResourceManager lifecycle [message #584059 is a reply to message #42612] Tue, 01 August 2006 04:20 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Yannick,

I have no idea, why in-memory hsqldb doesn't work for you. It does for me:

[INFO] common.client.connector: Connected socketChannel:
java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
remote=localhost/127.0.0.1:2036]
--> TEST: Create an EMF ResourceSet and associate it with a CDO
ResourceManager
--> TEST: Create a new CDO Resource
--> TEST: Populate the resource with an example model
--> TEST: Create a second CDO Resource
--> TEST: Populate the second resource with an example model
--> TEST: Commit the changes to the database

Even if I use the create action several times, there is no exception.
The originally created resources are reused and populated with multiple
top-level objects (libraries).
Since I can't reproduce the exception I fear I can't help with this
issue. If you can trace it to somethiing I can fix, please tell me.

The embedded connector is currently not stable and there's no example
how to configure it (actually it'd be simpler than NIO).

Cheers
/Eike


Yannick Lizzi schrieb:
> Another important information for the error I mentioned:
> I try to start the server and the client in the same jvm.
> If I run my previous test with client and server in 2 separates jvm,
> it works well.
> Maybe I should use the embedded connector instead of the socket
> connector?
>
> Yannick
>
>
> Yannick Lizzi a écrit :
>> Eike,
>>
>> Thanks for your quick answer, it's now clear to me how to use the
>> ResourceManager.
>>
>> Regarding the duplicate key problem, I made some tests and it seems
>> it's indeed a database issue. However, I don't think it's because the
>> database is not empty.
>> Actually, I made my test with HSQLDB. I used the server.properties
>> file provided in the CDO example and I just comment DERBY and
>> uncomment HSQLDB config. Here are these parameters:
>> jdbc.dialect=HSQLDB
>> jdbc.driver=org.hsqldb.jdbcDriver
>> jdbc.url=jdbc:hsqldb:.
>> jdbc.username=sa
>> jdbc.password=
>>
>> With this configuration, the exception is raised on each execution.
>> But this also means that hsqldb is launched in-memory, so the
>> database should be empty on start.
>> Don't ask me why, but if I set this configuration instead:
>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>
>>
>> Regards,
>> Yannick
>>
>>
>>
>>
>> Eike Stepper a écrit :
>>> Yannick,
>>>
>>> A ResourceManager is intended to have the same lifecycle as the
>>> ResourceSet it's attached to.
>>> You can imagine as a regular ResourceSet adapter (although it's
>>> currently not implemented as such, next version it will be).
>>>
>>> You can apply multiple, yet subsequent transactions to a whole
>>> ResourceSet by calling commit() on the associated ResourceManager.
>>> The same can be achieved by calling save() on an arbitrary
>>> (CDO)Resource within that ResourceSet:
>>>
>>> public void save(Map options)
>>> {
>>> try
>>> {
>>> resourceManager.commit();
>>> }
>>> catch (Throwable t)
>>> {
>>> logger.error("Error while committing", t);
>>> }
>>> }
>>>
>>> Regarding the duplicate key issue you mention, I assume that your
>>> database is simply not empty.
>>> The example action to create two remote Resources is very simple. It
>>> always uses the same URIs.
>>> So you can only use the action once to initially create some example
>>> Resources.
>>> If you want to recreate the Resources you will have to drop the
>>> database prior to that.
>>>
>>> And thanks for your kind words about CDO ;-)
>>> I hope it can be useful for you.
>>>
>>> Cheers
>>> /Eike
>>>
>>>
>>> Yannick Lizzi schrieb:
>>>> Hi all,
>>>>
>>>> The following piece of code causes a Unique constraint violation on
>>>> the CDO server:
>>>>
>>>> // Init resource manager
>>>> ResourceManager resourceManager = ...
>>>>
>>>> // Create and commit the first resource
>>>> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>> resource.getContents().add(factory.createMyObject1());
>>>> resourceManager.commit();
>>>>
>>>> // Create and commit the second resource
>>>> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>> resource2.getContents().add(factory.createMyObject2());
>>>> resourceManager.commit();
>>>>
>>>> The error is : "Unique constraint violation: in statement [INSERT
>>>> INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>
>>>>
>>>> It seems the problem comes from the 2 commits made on the same
>>>> ResourceManager. Indeed, when I remove the first one (just like in
>>>> the CDO example application), it works fine.
>>>>
>>>> I would like to better understand the behaviour (lifecycle) and the
>>>> role of the ResourceManager, as well as the best way to use it.
>>>>
>>>> For example: can I re-use a ResourceManager instance after a
>>>> commit? Is an instance linked to only one transaction?
>>>> Should I have to create a new instance each time I want to load a
>>>> resource (as it seems to be in the exampes)?
>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>> Session?
>>>>
>>>>
>>>> Thanks and congratulation for this two really promising projects.
>>>> Yannick
>>>>


Re: CDO ResourceManager lifecycle [message #584084 is a reply to message #42705] Tue, 01 August 2006 12:42 Go to previous message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

Eike,

OK, so let's start from the cdo/net4j example, and not from my own code.
Here are the slight modifications I make to reproduce the same error I
exeperienced

In the project org.eclipse.emf.cdo.examples.library.ui/src, in
CreateResourceAction, I add the following code at line 125:

124 resource.getContents().add(library);
125 resourceManager.commit(); // my code
126
127
128 // Create a second CDO Resource.
129 System.out.println("--> TEST: Create a second CDO Resource");


In org.eclipse.emf.cdo.examples.server/META-INF, in server.properties:
I simply comment DERBY settings, and uncomment HSQLDB settings.

I start CDO Server, then start the CDO Client1. I click on Create
Library CDO Resource.
Here is the error I get on the server console:

[INFO] net4j.slave-1: Connected socketChannel:
java.nio.channels.SocketChannel[connected local=/127.0.0.1:2036
remote=/127.0.0.1:1673]
Exception in thread "pool-1-thread-2"
org.springframework.dao.DataIntegrityViolationException:
PreparedStatementCallback; SQL [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)];
Unique constraint violation: in statement [INSERT IGNORE INTO CDO_RESOURCE
VALUES (?, ?)]; nested exception is java.sql.SQLException: Unique
constraint violation: in statement [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
java.sql.SQLException: Unique constraint violation: in statement
[INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
at
org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedSta tement(JdbcTemplate.java:697)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTempl ate.java:476)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:691)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:753)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:761)
at org.eclipse.emf.cdo.server.impl.MapperImpl.sql(MapperImpl.ja va:653)
at
org.eclipse.emf.cdo.server.impl.MapperImpl.insertResource(Ma pperImpl.java:530)
at
org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.receiveNewResources(CommitTransactionIndication.java:133 )
at
org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.access$3(CommitTransactionIndication.java:127)
at
org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion$1.doInTransactionWithoutResult(CommitTransactionIndicati on.java:82)
at
org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
at
org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:114)
at
org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.indicate(CommitTransactionIndication.java:74)
at
org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.processSi gnal(ChannelImpl.java:853)
at
org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.run(Chann elImpl.java:789)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


I'm sorry but I was wrong, the problem is probably not related to the
in-memory database, as if I change the settings to a file database, the
error is still there.

This is probably related to this second resourceManager.commit()
statement, though I don't really understand why.

Regards,
Yannick




Eike Stepper a écrit :
> Yannick,
>
> I have no idea, why in-memory hsqldb doesn't work for you. It does for me:
>
> [INFO] common.client.connector: Connected socketChannel:
> java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
> remote=localhost/127.0.0.1:2036]
> --> TEST: Create an EMF ResourceSet and associate it with a CDO
> ResourceManager
> --> TEST: Create a new CDO Resource
> --> TEST: Populate the resource with an example model
> --> TEST: Create a second CDO Resource
> --> TEST: Populate the second resource with an example model
> --> TEST: Commit the changes to the database
>
> Even if I use the create action several times, there is no exception.
> The originally created resources are reused and populated with multiple
> top-level objects (libraries).
> Since I can't reproduce the exception I fear I can't help with this
> issue. If you can trace it to somethiing I can fix, please tell me.
>
> The embedded connector is currently not stable and there's no example
> how to configure it (actually it'd be simpler than NIO).
>
> Cheers
> /Eike
>
>
> Yannick Lizzi schrieb:
>> Another important information for the error I mentioned:
>> I try to start the server and the client in the same jvm.
>> If I run my previous test with client and server in 2 separates jvm,
>> it works well.
>> Maybe I should use the embedded connector instead of the socket
>> connector?
>>
>> Yannick
>>
>>
>> Yannick Lizzi a écrit :
>>> Eike,
>>>
>>> Thanks for your quick answer, it's now clear to me how to use the
>>> ResourceManager.
>>>
>>> Regarding the duplicate key problem, I made some tests and it seems
>>> it's indeed a database issue. However, I don't think it's because the
>>> database is not empty.
>>> Actually, I made my test with HSQLDB. I used the server.properties
>>> file provided in the CDO example and I just comment DERBY and
>>> uncomment HSQLDB config. Here are these parameters:
>>> jdbc.dialect=HSQLDB
>>> jdbc.driver=org.hsqldb.jdbcDriver
>>> jdbc.url=jdbc:hsqldb:.
>>> jdbc.username=sa
>>> jdbc.password=
>>>
>>> With this configuration, the exception is raised on each execution.
>>> But this also means that hsqldb is launched in-memory, so the
>>> database should be empty on start.
>>> Don't ask me why, but if I set this configuration instead:
>>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>>
>>>
>>> Regards,
>>> Yannick
>>>
>>>
>>>
>>>
>>> Eike Stepper a écrit :
>>>> Yannick,
>>>>
>>>> A ResourceManager is intended to have the same lifecycle as the
>>>> ResourceSet it's attached to.
>>>> You can imagine as a regular ResourceSet adapter (although it's
>>>> currently not implemented as such, next version it will be).
>>>>
>>>> You can apply multiple, yet subsequent transactions to a whole
>>>> ResourceSet by calling commit() on the associated ResourceManager.
>>>> The same can be achieved by calling save() on an arbitrary
>>>> (CDO)Resource within that ResourceSet:
>>>>
>>>> public void save(Map options)
>>>> {
>>>> try
>>>> {
>>>> resourceManager.commit();
>>>> }
>>>> catch (Throwable t)
>>>> {
>>>> logger.error("Error while committing", t);
>>>> }
>>>> }
>>>>
>>>> Regarding the duplicate key issue you mention, I assume that your
>>>> database is simply not empty.
>>>> The example action to create two remote Resources is very simple. It
>>>> always uses the same URIs.
>>>> So you can only use the action once to initially create some example
>>>> Resources.
>>>> If you want to recreate the Resources you will have to drop the
>>>> database prior to that.
>>>>
>>>> And thanks for your kind words about CDO ;-)
>>>> I hope it can be useful for you.
>>>>
>>>> Cheers
>>>> /Eike
>>>>
>>>>
>>>> Yannick Lizzi schrieb:
>>>>> Hi all,
>>>>>
>>>>> The following piece of code causes a Unique constraint violation on
>>>>> the CDO server:
>>>>>
>>>>> // Init resource manager
>>>>> ResourceManager resourceManager = ...
>>>>>
>>>>> // Create and commit the first resource
>>>>> CDOResource resource = (CDOResource) resourceManager.getResourceSet()
>>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>>> resource.getContents().add(factory.createMyObject1());
>>>>> resourceManager.commit();
>>>>>
>>>>> // Create and commit the second resource
>>>>> CDOResource resource2 = (CDOResource) resourceManager.getResourceSet()
>>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>>> resource2.getContents().add(factory.createMyObject2());
>>>>> resourceManager.commit();
>>>>>
>>>>> The error is : "Unique constraint violation: in statement [INSERT
>>>>> INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>>
>>>>>
>>>>> It seems the problem comes from the 2 commits made on the same
>>>>> ResourceManager. Indeed, when I remove the first one (just like in
>>>>> the CDO example application), it works fine.
>>>>>
>>>>> I would like to better understand the behaviour (lifecycle) and the
>>>>> role of the ResourceManager, as well as the best way to use it.
>>>>>
>>>>> For example: can I re-use a ResourceManager instance after a
>>>>> commit? Is an instance linked to only one transaction?
>>>>> Should I have to create a new instance each time I want to load a
>>>>> resource (as it seems to be in the exampes)?
>>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>>> Session?
>>>>>
>>>>>
>>>>> Thanks and congratulation for this two really promising projects.
>>>>> Yannick
>>>>>
Re: CDO ResourceManager lifecycle [message #584229 is a reply to message #42734] Tue, 01 August 2006 21:54 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Yannick,

Indeed, that is a bug with new resources not being marked existent after
commit.
I fixed it and committed to HEAD. You should only need to update
org.eclipse.emf.cdo.client.

If you run again into issues, please set the logging priority to debug
in the /org.eclipse.net4j.util/config/log4j.xml

<root>
<priority value="debug"/>
<appender-ref ref="CONSOLE"/>
</root>

Cheers
/Eike


Yannick Lizzi schrieb:
> Eike,
>
> OK, so let's start from the cdo/net4j example, and not from my own code.
> Here are the slight modifications I make to reproduce the same error I
> exeperienced
>
> In the project org.eclipse.emf.cdo.examples.library.ui/src, in
> CreateResourceAction, I add the following code at line 125:
>
> 124 resource.getContents().add(library);
> 125 resourceManager.commit(); // my code
> 126
> 127
> 128 // Create a second CDO Resource.
> 129 System.out.println("--> TEST: Create a second CDO Resource");
>
>
> In org.eclipse.emf.cdo.examples.server/META-INF, in server.properties:
> I simply comment DERBY settings, and uncomment HSQLDB settings.
>
> I start CDO Server, then start the CDO Client1. I click on Create
> Library CDO Resource.
> Here is the error I get on the server console:
>
> [INFO] net4j.slave-1: Connected socketChannel:
> java.nio.channels.SocketChannel[connected local=/127.0.0.1:2036
> remote=/127.0.0.1:1673]
> Exception in thread "pool-1-thread-2"
> org.springframework.dao.DataIntegrityViolationException:
> PreparedStatementCallback; SQL [INSERT IGNORE INTO CDO_RESOURCE VALUES (?,
> ?)]; Unique constraint violation: in statement [INSERT IGNORE INTO
> CDO_RESOURCE VALUES (?, ?)]; nested exception is
> java.sql.SQLException: Unique constraint violation: in statement
> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
> java.sql.SQLException: Unique constraint violation: in statement
> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
> at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
> at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown
> Source)
> at
> org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedSta tement(JdbcTemplate.java:697)
>
> at
> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTempl ate.java:476)
> at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:691)
> at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:753)
> at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:761)
> at
> org.eclipse.emf.cdo.server.impl.MapperImpl.sql(MapperImpl.ja va:653)
> at
> org.eclipse.emf.cdo.server.impl.MapperImpl.insertResource(Ma pperImpl.java:530)
>
> at
> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.receiveNewResources(CommitTransactionIndication.java:133 )
>
> at
> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.access$3(CommitTransactionIndication.java:127)
>
> at
> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion$1.doInTransactionWithoutResult(CommitTransactionIndicati on.java:82)
>
> at
> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>
> at
> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:114)
>
> at
> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.indicate(CommitTransactionIndication.java:74)
>
> at
> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.processSi gnal(ChannelImpl.java:853)
>
> at
> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.run(Chann elImpl.java:789)
>
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn
> Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
>
>
> I'm sorry but I was wrong, the problem is probably not related to the
> in-memory database, as if I change the settings to a file database,
> the error is still there.
>
> This is probably related to this second resourceManager.commit()
> statement, though I don't really understand why.
>
> Regards,
> Yannick
>
>
>
>
> Eike Stepper a écrit :
>> Yannick,
>>
>> I have no idea, why in-memory hsqldb doesn't work for you. It does
>> for me:
>>
>> [INFO] common.client.connector: Connected socketChannel:
>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
>> remote=localhost/127.0.0.1:2036]
>> --> TEST: Create an EMF ResourceSet and associate it with a CDO
>> ResourceManager
>> --> TEST: Create a new CDO Resource
>> --> TEST: Populate the resource with an example model
>> --> TEST: Create a second CDO Resource
>> --> TEST: Populate the second resource with an example model
>> --> TEST: Commit the changes to the database
>>
>> Even if I use the create action several times, there is no exception.
>> The originally created resources are reused and populated with
>> multiple top-level objects (libraries).
>> Since I can't reproduce the exception I fear I can't help with this
>> issue. If you can trace it to somethiing I can fix, please tell me.
>>
>> The embedded connector is currently not stable and there's no example
>> how to configure it (actually it'd be simpler than NIO).
>>
>> Cheers
>> /Eike
>>
>>
>> Yannick Lizzi schrieb:
>>> Another important information for the error I mentioned:
>>> I try to start the server and the client in the same jvm.
>>> If I run my previous test with client and server in 2 separates jvm,
>>> it works well.
>>> Maybe I should use the embedded connector instead of the socket
>>> connector?
>>>
>>> Yannick
>>>
>>>
>>> Yannick Lizzi a écrit :
>>>> Eike,
>>>>
>>>> Thanks for your quick answer, it's now clear to me how to use the
>>>> ResourceManager.
>>>>
>>>> Regarding the duplicate key problem, I made some tests and it seems
>>>> it's indeed a database issue. However, I don't think it's because
>>>> the database is not empty.
>>>> Actually, I made my test with HSQLDB. I used the server.properties
>>>> file provided in the CDO example and I just comment DERBY and
>>>> uncomment HSQLDB config. Here are these parameters:
>>>> jdbc.dialect=HSQLDB
>>>> jdbc.driver=org.hsqldb.jdbcDriver
>>>> jdbc.url=jdbc:hsqldb:.
>>>> jdbc.username=sa
>>>> jdbc.password=
>>>>
>>>> With this configuration, the exception is raised on each execution.
>>>> But this also means that hsqldb is launched in-memory, so the
>>>> database should be empty on start.
>>>> Don't ask me why, but if I set this configuration instead:
>>>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>>>
>>>>
>>>> Regards,
>>>> Yannick
>>>>
>>>>
>>>>
>>>>
>>>> Eike Stepper a écrit :
>>>>> Yannick,
>>>>>
>>>>> A ResourceManager is intended to have the same lifecycle as the
>>>>> ResourceSet it's attached to.
>>>>> You can imagine as a regular ResourceSet adapter (although it's
>>>>> currently not implemented as such, next version it will be).
>>>>>
>>>>> You can apply multiple, yet subsequent transactions to a whole
>>>>> ResourceSet by calling commit() on the associated ResourceManager.
>>>>> The same can be achieved by calling save() on an arbitrary
>>>>> (CDO)Resource within that ResourceSet:
>>>>>
>>>>> public void save(Map options)
>>>>> {
>>>>> try
>>>>> {
>>>>> resourceManager.commit();
>>>>> }
>>>>> catch (Throwable t)
>>>>> {
>>>>> logger.error("Error while committing", t);
>>>>> }
>>>>> }
>>>>>
>>>>> Regarding the duplicate key issue you mention, I assume that your
>>>>> database is simply not empty.
>>>>> The example action to create two remote Resources is very simple.
>>>>> It always uses the same URIs.
>>>>> So you can only use the action once to initially create some
>>>>> example Resources.
>>>>> If you want to recreate the Resources you will have to drop the
>>>>> database prior to that.
>>>>>
>>>>> And thanks for your kind words about CDO ;-)
>>>>> I hope it can be useful for you.
>>>>>
>>>>> Cheers
>>>>> /Eike
>>>>>
>>>>>
>>>>> Yannick Lizzi schrieb:
>>>>>> Hi all,
>>>>>>
>>>>>> The following piece of code causes a Unique constraint violation
>>>>>> on the CDO server:
>>>>>>
>>>>>> // Init resource manager
>>>>>> ResourceManager resourceManager = ...
>>>>>>
>>>>>> // Create and commit the first resource
>>>>>> CDOResource resource = (CDOResource)
>>>>>> resourceManager.getResourceSet()
>>>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>>>> resource.getContents().add(factory.createMyObject1());
>>>>>> resourceManager.commit();
>>>>>>
>>>>>> // Create and commit the second resource
>>>>>> CDOResource resource2 = (CDOResource)
>>>>>> resourceManager.getResourceSet()
>>>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>>>> resource2.getContents().add(factory.createMyObject2());
>>>>>> resourceManager.commit();
>>>>>>
>>>>>> The error is : "Unique constraint violation: in statement
>>>>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>>>
>>>>>>
>>>>>> It seems the problem comes from the 2 commits made on the same
>>>>>> ResourceManager. Indeed, when I remove the first one (just like
>>>>>> in the CDO example application), it works fine.
>>>>>>
>>>>>> I would like to better understand the behaviour (lifecycle) and
>>>>>> the role of the ResourceManager, as well as the best way to use it.
>>>>>>
>>>>>> For example: can I re-use a ResourceManager instance after a
>>>>>> commit? Is an instance linked to only one transaction?
>>>>>> Should I have to create a new instance each time I want to load
>>>>>> a resource (as it seems to be in the exampes)?
>>>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>>>> Session?
>>>>>>
>>>>>>
>>>>>> Thanks and congratulation for this two really promising projects.
>>>>>> Yannick
>>>>>>


Re: CDO ResourceManager lifecycle [message #584285 is a reply to message #43065] Wed, 02 August 2006 08:44 Go to previous message
Eclipse UserFriend
Originally posted by: yannick.lizzi.silogic.fr

OK, now it works fine !
Thanks
Yannick


Eike Stepper a écrit :
> Yannick,
>
> Indeed, that is a bug with new resources not being marked existent after
> commit.
> I fixed it and committed to HEAD. You should only need to update
> org.eclipse.emf.cdo.client.
>
> If you run again into issues, please set the logging priority to debug
> in the /org.eclipse.net4j.util/config/log4j.xml
>
> <root>
> <priority value="debug"/>
> <appender-ref ref="CONSOLE"/>
> </root>
>
> Cheers
> /Eike
>
>
> Yannick Lizzi schrieb:
>> Eike,
>>
>> OK, so let's start from the cdo/net4j example, and not from my own code.
>> Here are the slight modifications I make to reproduce the same error I
>> exeperienced
>>
>> In the project org.eclipse.emf.cdo.examples.library.ui/src, in
>> CreateResourceAction, I add the following code at line 125:
>>
>> 124 resource.getContents().add(library);
>> 125 resourceManager.commit(); // my code
>> 126
>> 127
>> 128 // Create a second CDO Resource.
>> 129 System.out.println("--> TEST: Create a second CDO Resource");
>>
>>
>> In org.eclipse.emf.cdo.examples.server/META-INF, in server.properties:
>> I simply comment DERBY settings, and uncomment HSQLDB settings.
>>
>> I start CDO Server, then start the CDO Client1. I click on Create
>> Library CDO Resource.
>> Here is the error I get on the server console:
>>
>> [INFO] net4j.slave-1: Connected socketChannel:
>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:2036
>> remote=/127.0.0.1:1673]
>> Exception in thread "pool-1-thread-2"
>> org.springframework.dao.DataIntegrityViolationException:
>> PreparedStatementCallback; SQL [INSERT IGNORE INTO CDO_RESOURCE VALUES (?,
>> ?)]; Unique constraint violation: in statement [INSERT IGNORE INTO
>> CDO_RESOURCE VALUES (?, ?)]; nested exception is
>> java.sql.SQLException: Unique constraint violation: in statement
>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
>> java.sql.SQLException: Unique constraint violation: in statement
>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
>> at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
>> at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown
>> Source)
>> at
>> org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedSta tement(JdbcTemplate.java:697)
>>
>> at
>> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTempl ate.java:476)
>> at
>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:691)
>> at
>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:753)
>> at
>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:761)
>> at
>> org.eclipse.emf.cdo.server.impl.MapperImpl.sql(MapperImpl.ja va:653)
>> at
>> org.eclipse.emf.cdo.server.impl.MapperImpl.insertResource(Ma pperImpl.java:530)
>>
>> at
>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.receiveNewResources(CommitTransactionIndication.java:133 )
>>
>> at
>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.access$3(CommitTransactionIndication.java:127)
>>
>> at
>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion$1.doInTransactionWithoutResult(CommitTransactionIndicati on.java:82)
>>
>> at
>> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>>
>> at
>> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:114)
>>
>> at
>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.indicate(CommitTransactionIndication.java:74)
>>
>> at
>> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.processSi gnal(ChannelImpl.java:853)
>>
>> at
>> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.run(Chann elImpl.java:789)
>>
>> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn
>> Source)
>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
>> at java.lang.Thread.run(Unknown Source)
>>
>>
>> I'm sorry but I was wrong, the problem is probably not related to the
>> in-memory database, as if I change the settings to a file database,
>> the error is still there.
>>
>> This is probably related to this second resourceManager.commit()
>> statement, though I don't really understand why.
>>
>> Regards,
>> Yannick
>>
>>
>>
>>
>> Eike Stepper a écrit :
>>> Yannick,
>>>
>>> I have no idea, why in-memory hsqldb doesn't work for you. It does
>>> for me:
>>>
>>> [INFO] common.client.connector: Connected socketChannel:
>>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
>>> remote=localhost/127.0.0.1:2036]
>>> --> TEST: Create an EMF ResourceSet and associate it with a CDO
>>> ResourceManager
>>> --> TEST: Create a new CDO Resource
>>> --> TEST: Populate the resource with an example model
>>> --> TEST: Create a second CDO Resource
>>> --> TEST: Populate the second resource with an example model
>>> --> TEST: Commit the changes to the database
>>>
>>> Even if I use the create action several times, there is no exception.
>>> The originally created resources are reused and populated with
>>> multiple top-level objects (libraries).
>>> Since I can't reproduce the exception I fear I can't help with this
>>> issue. If you can trace it to somethiing I can fix, please tell me.
>>>
>>> The embedded connector is currently not stable and there's no example
>>> how to configure it (actually it'd be simpler than NIO).
>>>
>>> Cheers
>>> /Eike
>>>
>>>
>>> Yannick Lizzi schrieb:
>>>> Another important information for the error I mentioned:
>>>> I try to start the server and the client in the same jvm.
>>>> If I run my previous test with client and server in 2 separates jvm,
>>>> it works well.
>>>> Maybe I should use the embedded connector instead of the socket
>>>> connector?
>>>>
>>>> Yannick
>>>>
>>>>
>>>> Yannick Lizzi a écrit :
>>>>> Eike,
>>>>>
>>>>> Thanks for your quick answer, it's now clear to me how to use the
>>>>> ResourceManager.
>>>>>
>>>>> Regarding the duplicate key problem, I made some tests and it seems
>>>>> it's indeed a database issue. However, I don't think it's because
>>>>> the database is not empty.
>>>>> Actually, I made my test with HSQLDB. I used the server.properties
>>>>> file provided in the CDO example and I just comment DERBY and
>>>>> uncomment HSQLDB config. Here are these parameters:
>>>>> jdbc.dialect=HSQLDB
>>>>> jdbc.driver=org.hsqldb.jdbcDriver
>>>>> jdbc.url=jdbc:hsqldb:.
>>>>> jdbc.username=sa
>>>>> jdbc.password=
>>>>>
>>>>> With this configuration, the exception is raised on each execution.
>>>>> But this also means that hsqldb is launched in-memory, so the
>>>>> database should be empty on start.
>>>>> Don't ask me why, but if I set this configuration instead:
>>>>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>>>>
>>>>>
>>>>> Regards,
>>>>> Yannick
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Eike Stepper a écrit :
>>>>>> Yannick,
>>>>>>
>>>>>> A ResourceManager is intended to have the same lifecycle as the
>>>>>> ResourceSet it's attached to.
>>>>>> You can imagine as a regular ResourceSet adapter (although it's
>>>>>> currently not implemented as such, next version it will be).
>>>>>>
>>>>>> You can apply multiple, yet subsequent transactions to a whole
>>>>>> ResourceSet by calling commit() on the associated ResourceManager.
>>>>>> The same can be achieved by calling save() on an arbitrary
>>>>>> (CDO)Resource within that ResourceSet:
>>>>>>
>>>>>> public void save(Map options)
>>>>>> {
>>>>>> try
>>>>>> {
>>>>>> resourceManager.commit();
>>>>>> }
>>>>>> catch (Throwable t)
>>>>>> {
>>>>>> logger.error("Error while committing", t);
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> Regarding the duplicate key issue you mention, I assume that your
>>>>>> database is simply not empty.
>>>>>> The example action to create two remote Resources is very simple.
>>>>>> It always uses the same URIs.
>>>>>> So you can only use the action once to initially create some
>>>>>> example Resources.
>>>>>> If you want to recreate the Resources you will have to drop the
>>>>>> database prior to that.
>>>>>>
>>>>>> And thanks for your kind words about CDO ;-)
>>>>>> I hope it can be useful for you.
>>>>>>
>>>>>> Cheers
>>>>>> /Eike
>>>>>>
>>>>>>
>>>>>> Yannick Lizzi schrieb:
>>>>>>> Hi all,
>>>>>>>
>>>>>>> The following piece of code causes a Unique constraint violation
>>>>>>> on the CDO server:
>>>>>>>
>>>>>>> // Init resource manager
>>>>>>> ResourceManager resourceManager = ...
>>>>>>>
>>>>>>> // Create and commit the first resource
>>>>>>> CDOResource resource = (CDOResource)
>>>>>>> resourceManager.getResourceSet()
>>>>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>>>>> resource.getContents().add(factory.createMyObject1());
>>>>>>> resourceManager.commit();
>>>>>>>
>>>>>>> // Create and commit the second resource
>>>>>>> CDOResource resource2 = (CDOResource)
>>>>>>> resourceManager.getResourceSet()
>>>>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>>>>> resource2.getContents().add(factory.createMyObject2());
>>>>>>> resourceManager.commit();
>>>>>>>
>>>>>>> The error is : "Unique constraint violation: in statement
>>>>>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>>>>
>>>>>>>
>>>>>>> It seems the problem comes from the 2 commits made on the same
>>>>>>> ResourceManager. Indeed, when I remove the first one (just like
>>>>>>> in the CDO example application), it works fine.
>>>>>>>
>>>>>>> I would like to better understand the behaviour (lifecycle) and
>>>>>>> the role of the ResourceManager, as well as the best way to use it.
>>>>>>>
>>>>>>> For example: can I re-use a ResourceManager instance after a
>>>>>>> commit? Is an instance linked to only one transaction?
>>>>>>> Should I have to create a new instance each time I want to load
>>>>>>> a resource (as it seems to be in the exampes)?
>>>>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>>>>> Session?
>>>>>>>
>>>>>>>
>>>>>>> Thanks and congratulation for this two really promising projects.
>>>>>>> Yannick
>>>>>>>
Re: CDO ResourceManager lifecycle [message #584340 is a reply to message #43163] Wed, 02 August 2006 11:51 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Yannick,

I assume you are just playing around a bit with own client code.
That's ok, but I'd like to mention that you don't need two transactions
(commits) in order to add two resources.

Cheers
/Eike



Yannick Lizzi schrieb:
> OK, now it works fine !
> Thanks
> Yannick
>
>
> Eike Stepper a écrit :
>> Yannick,
>>
>> Indeed, that is a bug with new resources not being marked existent
>> after commit.
>> I fixed it and committed to HEAD. You should only need to update
>> org.eclipse.emf.cdo.client.
>>
>> If you run again into issues, please set the logging priority to
>> debug in the /org.eclipse.net4j.util/config/log4j.xml
>>
>> <root>
>> <priority value="debug"/>
>> <appender-ref ref="CONSOLE"/>
>> </root>
>>
>> Cheers
>> /Eike
>>
>>
>> Yannick Lizzi schrieb:
>>> Eike,
>>>
>>> OK, so let's start from the cdo/net4j example, and not from my own
>>> code.
>>> Here are the slight modifications I make to reproduce the same error
>>> I exeperienced
>>>
>>> In the project org.eclipse.emf.cdo.examples.library.ui/src, in
>>> CreateResourceAction, I add the following code at line 125:
>>>
>>> 124 resource.getContents().add(library);
>>> 125 resourceManager.commit(); // my code
>>> 126
>>> 127
>>> 128 // Create a second CDO Resource.
>>> 129 System.out.println("--> TEST: Create a second CDO Resource");
>>>
>>>
>>> In org.eclipse.emf.cdo.examples.server/META-INF, in server.properties:
>>> I simply comment DERBY settings, and uncomment HSQLDB settings.
>>>
>>> I start CDO Server, then start the CDO Client1. I click on Create
>>> Library CDO Resource.
>>> Here is the error I get on the server console:
>>>
>>> [INFO] net4j.slave-1: Connected socketChannel:
>>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:2036
>>> remote=/127.0.0.1:1673]
>>> Exception in thread "pool-1-thread-2"
>>> org.springframework.dao.DataIntegrityViolationException:
>>> PreparedStatementCallback; SQL [INSERT IGNORE INTO CDO_RESOURCE VALUES (?,
>>> ?)]; Unique constraint violation: in statement [INSERT IGNORE INTO
>>> CDO_RESOURCE VALUES (?, ?)]; nested exception is
>>> java.sql.SQLException: Unique constraint violation: in statement
>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
>>> java.sql.SQLException: Unique constraint violation: in statement
>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]
>>> at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
>>> at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown
>>> Source)
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedSta tement(JdbcTemplate.java:697)
>>>
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTempl ate.java:476)
>>>
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:691)
>>>
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:753)
>>>
>>> at
>>> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTempla te.java:761)
>>>
>>> at
>>> org.eclipse.emf.cdo.server.impl.MapperImpl.sql(MapperImpl.ja va:653)
>>> at
>>> org.eclipse.emf.cdo.server.impl.MapperImpl.insertResource(Ma pperImpl.java:530)
>>>
>>> at
>>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.receiveNewResources(CommitTransactionIndication.java:133 )
>>>
>>> at
>>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.access$3(CommitTransactionIndication.java:127)
>>>
>>> at
>>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion$1.doInTransactionWithoutResult(CommitTransactionIndicati on.java:82)
>>>
>>> at
>>> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>>>
>>> at
>>> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:114)
>>>
>>> at
>>> org.eclipse.emf.cdo.server.protocol.CommitTransactionIndicat ion.indicate(CommitTransactionIndication.java:74)
>>>
>>> at
>>> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.processSi gnal(ChannelImpl.java:853)
>>>
>>> at
>>> org.eclipse.net4j.core.impl.ChannelImpl$SignalTask.run(Chann elImpl.java:789)
>>>
>>> at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn Source)
>>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
>>> Source)
>>> at java.lang.Thread.run(Unknown Source)
>>>
>>>
>>> I'm sorry but I was wrong, the problem is probably not related to
>>> the in-memory database, as if I change the settings to a file
>>> database, the error is still there.
>>>
>>> This is probably related to this second resourceManager.commit()
>>> statement, though I don't really understand why.
>>>
>>> Regards,
>>> Yannick
>>>
>>>
>>>
>>>
>>> Eike Stepper a écrit :
>>>> Yannick,
>>>>
>>>> I have no idea, why in-memory hsqldb doesn't work for you. It does
>>>> for me:
>>>>
>>>> [INFO] common.client.connector: Connected socketChannel:
>>>> java.nio.channels.SocketChannel[connected local=/127.0.0.1:1139
>>>> remote=localhost/127.0.0.1:2036]
>>>> --> TEST: Create an EMF ResourceSet and associate it with a CDO
>>>> ResourceManager
>>>> --> TEST: Create a new CDO Resource
>>>> --> TEST: Populate the resource with an example model
>>>> --> TEST: Create a second CDO Resource
>>>> --> TEST: Populate the second resource with an example model
>>>> --> TEST: Commit the changes to the database
>>>>
>>>> Even if I use the create action several times, there is no
>>>> exception. The originally created resources are reused and
>>>> populated with multiple top-level objects (libraries).
>>>> Since I can't reproduce the exception I fear I can't help with this
>>>> issue. If you can trace it to somethiing I can fix, please tell me.
>>>>
>>>> The embedded connector is currently not stable and there's no
>>>> example how to configure it (actually it'd be simpler than NIO).
>>>>
>>>> Cheers
>>>> /Eike
>>>>
>>>>
>>>> Yannick Lizzi schrieb:
>>>>> Another important information for the error I mentioned:
>>>>> I try to start the server and the client in the same jvm.
>>>>> If I run my previous test with client and server in 2 separates
>>>>> jvm, it works well.
>>>>> Maybe I should use the embedded connector instead of the socket
>>>>> connector?
>>>>>
>>>>> Yannick
>>>>>
>>>>>
>>>>> Yannick Lizzi a écrit :
>>>>>> Eike,
>>>>>>
>>>>>> Thanks for your quick answer, it's now clear to me how to use the
>>>>>> ResourceManager.
>>>>>>
>>>>>> Regarding the duplicate key problem, I made some tests and it
>>>>>> seems it's indeed a database issue. However, I don't think it's
>>>>>> because the database is not empty.
>>>>>> Actually, I made my test with HSQLDB. I used the
>>>>>> server.properties file provided in the CDO example and I just
>>>>>> comment DERBY and uncomment HSQLDB config. Here are these
>>>>>> parameters:
>>>>>> jdbc.dialect=HSQLDB
>>>>>> jdbc.driver=org.hsqldb.jdbcDriver
>>>>>> jdbc.url=jdbc:hsqldb:.
>>>>>> jdbc.username=sa
>>>>>> jdbc.password=
>>>>>>
>>>>>> With this configuration, the exception is raised on each
>>>>>> execution. But this also means that hsqldb is launched in-memory,
>>>>>> so the database should be empty on start.
>>>>>> Don't ask me why, but if I set this configuration instead:
>>>>>> jdbc.url=jdbc:hsqldb:testdb, my test runs without exception.
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Yannick
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Eike Stepper a écrit :
>>>>>>> Yannick,
>>>>>>>
>>>>>>> A ResourceManager is intended to have the same lifecycle as the
>>>>>>> ResourceSet it's attached to.
>>>>>>> You can imagine as a regular ResourceSet adapter (although it's
>>>>>>> currently not implemented as such, next version it will be).
>>>>>>>
>>>>>>> You can apply multiple, yet subsequent transactions to a whole
>>>>>>> ResourceSet by calling commit() on the associated ResourceManager.
>>>>>>> The same can be achieved by calling save() on an arbitrary
>>>>>>> (CDO)Resource within that ResourceSet:
>>>>>>>
>>>>>>> public void save(Map options)
>>>>>>> {
>>>>>>> try
>>>>>>> {
>>>>>>> resourceManager.commit();
>>>>>>> }
>>>>>>> catch (Throwable t)
>>>>>>> {
>>>>>>> logger.error("Error while committing", t);
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> Regarding the duplicate key issue you mention, I assume that
>>>>>>> your database is simply not empty.
>>>>>>> The example action to create two remote Resources is very
>>>>>>> simple. It always uses the same URIs.
>>>>>>> So you can only use the action once to initially create some
>>>>>>> example Resources.
>>>>>>> If you want to recreate the Resources you will have to drop the
>>>>>>> database prior to that.
>>>>>>>
>>>>>>> And thanks for your kind words about CDO ;-)
>>>>>>> I hope it can be useful for you.
>>>>>>>
>>>>>>> Cheers
>>>>>>> /Eike
>>>>>>>
>>>>>>>
>>>>>>> Yannick Lizzi schrieb:
>>>>>>>> Hi all,
>>>>>>>>
>>>>>>>> The following piece of code causes a Unique constraint
>>>>>>>> violation on the CDO server:
>>>>>>>>
>>>>>>>> // Init resource manager
>>>>>>>> ResourceManager resourceManager = ...
>>>>>>>>
>>>>>>>> // Create and commit the first resource
>>>>>>>> CDOResource resource = (CDOResource)
>>>>>>>> resourceManager.getResourceSet()
>>>>>>>> .createResource(URI.createURI("cdo:///uri1"));
>>>>>>>> resource.getContents().add(factory.createMyObject1());
>>>>>>>> resourceManager.commit();
>>>>>>>>
>>>>>>>> // Create and commit the second resource
>>>>>>>> CDOResource resource2 = (CDOResource)
>>>>>>>> resourceManager.getResourceSet()
>>>>>>>> .createResource(URI.createURI("cdo:///uri2"));
>>>>>>>> resource2.getContents().add(factory.createMyObject2());
>>>>>>>> resourceManager.commit();
>>>>>>>>
>>>>>>>> The error is : "Unique constraint violation: in statement
>>>>>>>> [INSERT IGNORE INTO CDO_RESOURCE VALUES (?, ?)]"
>>>>>>>>
>>>>>>>>
>>>>>>>> It seems the problem comes from the 2 commits made on the same
>>>>>>>> ResourceManager. Indeed, when I remove the first one (just like
>>>>>>>> in the CDO example application), it works fine.
>>>>>>>>
>>>>>>>> I would like to better understand the behaviour (lifecycle) and
>>>>>>>> the role of the ResourceManager, as well as the best way to use
>>>>>>>> it.
>>>>>>>>
>>>>>>>> For example: can I re-use a ResourceManager instance after a
>>>>>>>> commit? Is an instance linked to only one transaction?
>>>>>>>> Should I have to create a new instance each time I want to
>>>>>>>> load a resource (as it seems to be in the exampes)?
>>>>>>>> Am I wrong if I consider it at the same level as the Hibernate
>>>>>>>> Session?
>>>>>>>>
>>>>>>>>
>>>>>>>> Thanks and congratulation for this two really promising projects.
>>>>>>>> Yannick
>>>>>>>>


Previous Topic:Can't set an attribute with an enumeration type
Next Topic:CDO and GMF
Goto Forum:
  


Current Time: Thu Apr 25 19:02:53 GMT 2024

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

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

Back to the top