179 words

Can't get arraylist/vector type attributes

#1
2017-03-09 19:54

I have a class that contains some attributes of type Vector (also tried with ArrayList and same happens). When I try to get an object from that class doing using the find method it works fine, I get the object. But when I call the close method to close the EntityManager the information from the Vector dissapears and I get an empty vector.

Something weird happens, if BEFORE closing the entitymanager I write something like vector.size() or I print it's size or I do anything with the vector, after calling the close method the information from the Vector doesn't disappear.

What am I doing wrong?

Unknown
Unknown's picture
Joined on 2017-03-09
User Post #1
#2
2017-03-09 20:28

By default, collections are retreived from the database lazily, and only when the containing entity objects are managed. i.e. when the EntityManager is open.

When you close the EntityManager managed entity objects become detached, and content that has not been retrieved from the datbase already is not available.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,712
#3
2017-03-09 20:59

And what should I do to keep the information?

Unknown
Unknown's picture
Joined on 2017-03-09
User Post #2
#4
2017-03-09 21:04

Access it before closing the EntityManager or load it eagerly (FetchType.EAGER).

See also "objectdb.temp.no-detach" as a possible quick workaround.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,713
#5
2017-03-09 21:47

Loading it eagerly worked

Unknown
Unknown's picture
Joined on 2017-03-09
User Post #3

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel