0

I'm wondering if there is a way with Apache Cayenne to use their .setTo method for setting relationships without it pulling the object one at a time each time the method is called. I'm working with several thousands of rows of data and it having to query the object each time a relationship is set eats a few milliseconds which adds up to several minutes with this large of a data set.

I've tried digging through their documentation, but a number of it is abstracted away which makes it hard to find in their exactly what I'm looking for. Would appreciate any tips!

Tim Hunter
  • 242
  • 1
  • 7
  • I just did a work around of sorts by checking if there is new data being added or changed before calling the setTo methods. It works for my purposes. – Tim Hunter Oct 24 '18 at 18:20

1 Answers1

0

An idiomatic solution is to explicitly prefetch all relationships when you run a query that gives you the original object list if you anticipate accessing those relationships for a significant percentage of list objects:

List<Artist> objects = ObjectSelect.query(Artist.class)
    .prefetch(Artist.PAINTINGS.joint())
    .select(context);
andrus_a
  • 2,528
  • 1
  • 16
  • 10
  • Thanks for the comment! Hmmm... not sure this is quite what I'm looking for. I already have objects I'm setting relationships for stored in hashmaps, so I should have all the objects locally. I'm just not sure how to disable the .setTo method's automatic behavior to query the database when the method is called until I can send the relationship settings for all objects as a group of actions. Provided such functionality is even possible anyways. – Tim Hunter Oct 27 '18 at 00:35
  • Cayenne should not query the database when you are calling 'setTo*' if that relationship is already resolved. – andrus_a Oct 27 '18 at 10:06