ActiveObject OneToMany relationship returning an empty array

I have a series on ActiveObject entities in my JIRA plugin.

public interface AT extends Template {

  @OneToMany(reverse = "getAT")
  public ComponentOrder[] getOrders();

}

@Polymorphic
public interface CT extends Template {

  @OneToMany(reverse = "getCT")
  public ComponentOrder[] getOrders();
}

public interface IT extends CT {

   public String getAttribute();
   public void setAttribute(String attribute);
}

public interface ComponentOrder extends Entity {

  public AT getAT();

  public void setAT(AT at);

  public CT getCT();

  public void setCT(CT ct);

  public int getOrder();

  public void setOrder(int order);

  public static class ComponentOrderComparator implements Comparator<ComponentOrder> {

    @Override
    public int compare(ComponentOrder o1, ComponentOrder o2) {
      return Integer.compare(o1.getOrder(), o2.getOrder());
    }
  }
}

Template extends Entity.

The values I have in ComponentOrder are valid. Each entry points to one AT and one CT (plus containing the order).

If I get the list of AT, when I call getOrders(), it returns the correct objects from ComponentOrder.

 

//I specifically get one AT to get the number of components attached
int number = ao.find(AT.class)[2].getOrders().length;

However, if I get the list of IT, the number of components is zero.

int number = ao.find(IT.class)[0].getOrders().length;

If I search directly in ComponentOrder, I can can both the AT and CT without issue.

String nameAT = ao.find(ComponentOrder.class)[0].getAT().getName();
String nameCT = ao.find(ComponentOrder.class)[0].getCT().getName();

Has it something to do with the fact that my ComponentOrder entity points to a polymorphic object?

2 answers

0 vote
Sam Hall Community Champion Apr 21, 2017
0 vote

I would think so.

What you have defined is a one to many relation between ComponentOrder and AT/CT. IT extends CT but doesn't have a relationship directly in the definition. Why not get CT and cast it into IT? Or define IT in the relationship? 

The goal was to have CT being generic and containing a list of common attributes (kind of a common template). IT is one of many types that will inherit from it (we plan to have at least six types, that will all have to be linked to ComponentOrder, but without ComponentOrder having to know the exact type of the component. Wouldn't defining IT directly in the relationship, or casting, prevent us from havig multiple types?

In that case, you might want to use CT to retrieve and then cast them appropriately at runtime. Not sure if there is another easier solution out threre or not. 

Sorry about the delay. I thought I understood what you meant and tried a few things, but it does not seem to work. I tried moving the relation

@OneToMany(reverse = "getCT")
public ComponentOrder[] getOrders();

in the IT class, but it complains that "getOrders()" is not found in CT.

What should I modify to make it work and keep the flexibility?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

278 views 4 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you