217 words

Help understanding Entity behavior with JPA

#1
2012-12-06 11:01

Hi Support,

 

We have a entity with an @Id entity which we then put into a list and store in an different entity inside a field defined as:

 

@OneToOne(orphanRemoval=true, cascade=CascadeType.ALL, fetch=FetchType.EAGER)
private Object payload;

the list that we put in the 'payload' is an java.util.ArrayList and it contains multitple entities with an the same id.  the behavior we are seeing is that when we reload the entity that contains the 'payload' field is that every entity in the list is the same. I would understand if we ended up with a list with one item in item but we are ending up with a list with 45 items the same this is a little confusing.

can you help?

Dan

dansmith
dansmith's picture
Joined on 2012-11-08
User Post #7
#2
2012-12-06 12:59

The combination of (type, ID) should identify entity objects uniquely. Therefore, only one entity object per (type, ID) is managed per EntityManager. Consequently, it is unclear what exactly you put in the payload list. How can you have multiple entities with the same ID?

Notice that if you just create objects with the IDs they are not managed. You can get the single managed entity of that ID by using find or merge. Non managed objects with the same ID may be replaced by the single managed entity object.

If you just want to eliminate duplicates consider using a Set instead of a List.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,352

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