Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I could not get this to work for multiple reasons:</p> <ol> <li>I could not get the data once persisted to the mongoDB to load back into the object, the object would always just be null.</li> <li>After issue #1, I added a private list that would populate my MorphiaList on lookup to get around it. But after getting the ids into the MorphiaList, I could not figure out how to do a lookup on the specific collections. Especially when you consider I use inheritance so I have some heterogeneous collections.</li> </ol> <p>My Solution: For every List of references I rewrote this: </p> <pre><code>@Reference public List&lt;Season&gt; seasons; </code></pre> <p>To this:</p> <pre><code>@Transient public List&lt;Season&gt; seasons; private List&lt;ObjectId&gt; _seasons = new ArrayList(); @Transient private List&lt;Season&gt; pSeasons; public List&lt;Season&gt; getSeasons() { if(pSeasons==null) { if(_seasons.size()!=0) pSeasons = Season.find().&lt;Season&gt;field("_id").in(_seasons).asList(); else pSeasons = new ArrayList(); } return pSeasons; } </code></pre> <p>I also had to add a <strong>@PrePersist</strong> method to check for list access:</p> <pre><code>@PrePersist void beforeSave() { if(pSeasons!=null) { _seasons.clear(); for(Season s: pSeasons) { _seasons.add((ObjectId)s.getId()); } } } </code></pre> <p>This <strong>beforeSave()</strong> will have to expand for every extra List of refs you have in your code. Moral of the story: </p> <p><em>If you're using Play's morphia module, don't use the @Reference notation.</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload