detach

63 views
Skip to first unread message

Ravi Kapoor

unread,
Oct 1, 2015, 5:02:34 AM10/1/15
to OrientDB

Newbie question,

I am having trouble making detach work properly.
1. I load an object. I call detachAll(element, true), the fields are NOT copied and everything is still null
2. I call  detachAll(element, false), now all fields are copied, however it is a proxied instance and I cannot use it as POJO in application.

Screenshots
1.png: before I call detach, you can see in debug window that all fields are null
2.png: after I call detachAll(element, true), the fields are still null
3.png After I call detachAll(element, false), the fields are populated, but now it is proxied (so if I hadd a 

What is right way to do this?

1.png
2.png
3.png

alessand...@gmail.com

unread,
Oct 1, 2015, 6:57:00 AM10/1/15
to OrientDB
Hi,
can you post the complete query at the line 19 and the complete stacktrace from console ?

Alessandro

Ravi Kapoor

unread,
Oct 1, 2015, 10:24:57 AM10/1/15
to OrientDB

Sure, I made some changes, now it is 2 file source only. These two screenshots show all source code. I am also attaching two source code files for reference.
5.png
4.png
App.java
Element.java

alessand...@gmail.com

unread,
Oct 1, 2015, 10:49:35 AM10/1/15
to OrientDB
Sorry, 
if you can, you send me also the db and the class component.

Alessandro

Ravi Kapoor

unread,
Oct 1, 2015, 11:13:06 AM10/1/15
to OrientDB
I am not sure how to send DB. I simplified code so it will create the table for you. Source code is attached.
App.java
Element.java

alessand...@gmail.com

unread,
Oct 1, 2015, 11:23:19 AM10/1/15
to OrientDB
Thanks, 
I'll let you know as soon as possible

Kind regards,
Alessandro

alessand...@gmail.com

unread,
Oct 1, 2015, 11:42:08 AM10/1/15
to OrientDB
Hi,
try the code in the attachments.

Alessandro
App.java
Element.java

alessand...@gmail.com

unread,
Oct 1, 2015, 11:53:51 AM10/1/15
to OrientDB
Hi,
try the code in the class App and let me know.

Alessandro
App.java

Ravi Kapoor

unread,
Oct 1, 2015, 2:45:24 PM10/1/15
to OrientDB

Hi Alessandro,

You used
    	dbTx.detachAll(root, false);

This has always worked. When I switch it to 
    	dbTx.detachAll(root, true);

it again stops worknig. This is the problem I am reporting.
I need "non proxy" version, so I can use it as business object in my application.

xvik

unread,
Oct 2, 2015, 3:26:34 AM10/2/15
to OrientDB
When you need to use pure pojo instead of proxy you have to introduce new reference:

Element rootPojo = dbTx.detachAll(root, true);


пятница, 2 октября 2015 г., 0:45:24 UTC+6 пользователь Ravi Kapoor написал:

Ravi Kapoor

unread,
Oct 2, 2015, 12:57:14 PM10/2/15
to OrientDB

Thanks xvik that worked perfectly. Such a simple solution.
Thanks Alessandro for helping.

Can I present one more problem? 

I created 'Person' class so it can have more Person as children.

I create  structure of "Parent" -> "Child" -> "Grand child" and save it. (This works very well)
I read the "Parent" back from DB, it retrieves child and grand child with it. (This also works)
I add one more grand child to this structure. 

Now when I save it, the 2nd grandchild is not saved.
I experimented and found that any changes in existing Persons are saved. Also, any new child objects are also saved, however any new grandchild objects are not saved.

Also note that if I add a child as well (code is commented out), then both new objects (1 child and 1 grandchild) are saved.
This feels very strange. Is this expected behavior? 

Source files are attached.
App1.java
Person.java
Reply all
Reply to author
Forward
0 new messages