Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrientDB generates temporaty @rid during transaction #6120

Closed
schernolyas opened this issue May 11, 2016 · 33 comments
Closed

OrientDB generates temporaty @rid during transaction #6120

schernolyas opened this issue May 11, 2016 · 33 comments
Assignees
Labels

Comments

@schernolyas
Copy link

OrientDB generates temporaty @Rid during transaction. In this way, Hibernate OGM links entities by the @Rid. And .... the link is incorrect after transaction commited.

Test examle is OrientDbLinkTest.java. At the example, Entity 'Card' has incorrect links (see row 108)

Full hibernate ogm debug output attached.
org.hibernate.datastore.ogm.orientdb.OrientDbLinkTest-output.txt

@schernolyas
Copy link
Author

Version of orientdb: 2.2.0-rc1

@tglman tglman self-assigned this May 11, 2016
@tglman tglman added the bug label May 11, 2016
@tglman
Copy link
Member

tglman commented May 11, 2016

Thanks @schernolyas we will check ASAP

@schernolyas
Copy link
Author

Hi @tglman !
Have You any progress? Which milestone will contains fix?

@lvca
Copy link
Member

lvca commented May 16, 2016

Do you have logs? My theory is that the first time it creates a new class in background and to do this operation, the TX is committed and restarted.

@schernolyas Could you please check it? Could you create the OrientDB class before the TX?

@lvca lvca assigned lvca and unassigned tglman May 16, 2016
@schernolyas
Copy link
Author

HI @lvca !
I attached full hibernate ogm log already. You can see file OrientDbLinkTest-output.txt. The file contains a tons of text. But You can fond usefull information by search word "insert".

JPA EntityManager can not work without transaction and throw Exception.

@lvca
Copy link
Member

lvca commented May 16, 2016

I cannot find must be executed outside active transaction. When do you create the respective "Card" OrientDB class?

@schernolyas
Copy link
Author

@lvca Can You return to hangout?

@schernolyas
Copy link
Author

@lvca

Copy from hangout (chat):


Luca please find row by " 14:01:42,248 DEBUG"
it is start of orientdb transaction N 1 in connection
during transaction N1 I execute "insert" query insert into Card content {"pan":"4444"} return @Rid (at 14:01:42,244)
and at 14:01:42,233 I get result: Key: @Rid (#45:-2)
and transaction N1 was commited at 14:01:42,261
and 3 rows was persisted


About "I cannot find must be executed outside active transaction" ....What do You mean?

@schernolyas
Copy link
Author

@lvca
Copy from hangout


Yes YOu are right absolutly
And ... How we can fix the situation?
I guess that OrientDB have to create persistent RecordId at once
I offer next algorithm

  1. create persistent RecordId for new record during transaction and the recordid as "used"
  2. if transaction commited .... then all right
  3. if transaction rollbacked ... then mark the recordid as "free" and link the recordid with other row
    is the algorithm implementable?

@schernolyas
Copy link
Author

@lvca


And it was without transaction. I know that OrientDB not allow change schema during transaction
About terms
Class is same a table
Entity (is JPA term) is same data in table/class
Schema (tables/classes, indexes, sequences ans stored procedues) created during EntityManager instantiation
It occurs at this https://github.com/schernolyas/hibernate-ogm/blob/use_links/orientdb/src/test/java/org/hibernate/datastore/ogm/orientdb/OrientDbLinkTest.java#L50
Transaction for create new entities and links them is https://github.com/schernolyas/hibernate-ogm/blob/use_links/orientdb/src/test/java/org/hibernate/datastore/ogm/orientdb/OrientDbLinkTest.java#L80:L105


@schernolyas
Copy link
Author

Hi @lvca !

Have You any questions about the problem?

@schernolyas
Copy link
Author

Hi @lvca !

Have You any progress? Which milestone will conteins fix for the issue?

A lot of thanks!

@lvca
Copy link
Member

lvca commented May 24, 2016

To recap, what's the sql you execute? just 1 statement insert? Can you copy and paste only the relevant snippet here?

@schernolyas
Copy link
Author

schernolyas commented May 24, 2016

Hi @lvca !
During transaction, I execute queries:

  1. select executeQuery('insert into Card content {"pan":"4444"} return @Rid');
    result RID Not-unique Indexes [moved] #45:-2
  2. select executeQuery('insert into Payment content {"created":"2016-05-11 14:01:42","sum":"1"} return @Rid') ; result RID: Install as Windows Service [moved] #61:-3
  3. select executeQuery('insert into Payment content {"created":"2016-05-11 14:01:42","sum":"2"} return @Rid') ; result RID: Support for ENUM on class schema [moved] #62:-4

Body of stored procedure executeQuery:
CREATE FUNCTION executeQuery "return orient.getDatabase().command(insertQuery);" PARAMETERS [insertQuery] LANGUAGE GROOVY

Problem that there RID is actual during the transaction only.

@lvca
Copy link
Member

lvca commented May 24, 2016

Why are you creating 3 new functions in Groovy just to execute 3 SQL?

@schernolyas
Copy link
Author

@lvca , because OrientDB implenentation of JDBC driver not allow to execute queries like mine

@lvca
Copy link
Member

lvca commented May 24, 2016

Why not? Have you tried:

ResultSet rs = conn.createStatement().executeQuery("insert into Card content {"pan":"4444"} return @rid");

@schernolyas
Copy link
Author

@lvca Yes of course! It is first that I did. I got exception.

@lvca
Copy link
Member

lvca commented May 24, 2016

Ok, just created: #6205

@lvca
Copy link
Member

lvca commented May 24, 2016

Done: #6205

@lvca
Copy link
Member

lvca commented May 24, 2016

Could you try it (it's in last develop branch)

@schernolyas
Copy link
Author

@lvca Okey. I will try. I will attach results .

@schernolyas
Copy link
Author

@lvca I got exception. See part of stack trace

Caused by: com.orientechnologies.orient.core.exception.OCommandExecutionException: Cannot execute non idempotent command
Storage URL="memory:test"
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.executeCommand(OAbstractPaginatedStorage.java:2489)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:2474)
at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:78)
at com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery.run(OSQLAsynchQuery.java:74)
at com.orientechnologies.orient.core.sql.query.OSQLSynchQuery.run(OSQLSynchQuery.java:85)
at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:33)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.query(ODatabaseDocumentTx.java:672)
at com.orientechnologies.orient.jdbc.OrientJdbcPreparedStatement.executeQuery(OrientJdbcPreparedStatement.java:75)

@lvca
Copy link
Member

lvca commented May 24, 2016

I created this test case and passed:

@Test
  public void testInsertRIDReturning() throws Exception {
    conn.createStatement().executeQuery("CREATE CLASS Insertable ");
    ResultSet result = conn.createStatement().executeQuery("INSERT INTO Insertable(id) VALUES(1) return @rid");

    assertThat(result.next()).isTrue();
    assertThat(result.getObject("id")).isNotNull();
  }

@schernolyas
Copy link
Author

@lvca
I guess that You do it in non-transactional environment.
I using pooled connection and transaction.

The exception show all

@schernolyas
Copy link
Author

Hi @lvca

I sended to You some presentation that describe a problem with issue 6120
I hope ... You will not a have a questions.
But .... main question is ... Can I use @Rid as primary key ?

@schernolyas
Copy link
Author

Hi @lvca !

Have You any decision about the issue?
Can I help?

@schernolyas
Copy link
Author

Hi @lvca !

What is status of the bug?

@lvca
Copy link
Member

lvca commented Feb 18, 2017

I'd like to follow up on this. Is this issue still relevant? Can I close it?

@schernolyas
Copy link
Author

schernolyas commented Feb 18, 2017 via email

@lvca lvca assigned luigidellaquila and unassigned lvca Feb 22, 2017
@lvca
Copy link
Member

lvca commented Feb 22, 2017

Forwarding to @luigidellaquila.

@luigidellaquila
Copy link
Member

Hi @lvca

This issue is specific to tx behavior, that is a basic behavior in OrientDB so it cannot be changed.
I think the problem here is that when the transaction is committed, there is no callback mechanism to notify that the RID was updated.
For sure the issue is still there, for sure it's hard to fix in v 2.x, maybe we can do something in 3.0 but I have to check with @tglman (for the tx lifecycle) and @robfrank (for JDBC implications).

Thanks

Luigi

@schernolyas
Copy link
Author

HI @luigidellaquila

I demonstate the problem.

For example Entity A and Entity B have 'one-to-many' link.

  1. hibernate open transaction
  2. hibernate persist entity a and save it to own cache with @Rid 21:-1
  3. hibernate persist entity b ans save it to own cache with @Rid 22:-1
  4. hibernate update entity b and store link to entity a ( link to @Rid 21:-1)
  5. hibernate commit the transaction
  6. ORIENTDB CHANGE @Rid OF THESE ENTITIES AND NOW ENTITY WITH @Rid 22:-1 NOT EXISTS!!!
    The feature make impossible to use system field @Rid as primary key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

6 participants