Note that there are some explanatory texts on larger screens.

plurals
  1. POMorphia - issue with @Reference when using custom object for ID
    primarykey
    data
    text
    <p>I am trying to use a custom object for entities' IDs instead of the usual ObjectId - the idea is to have a composite _id which would include a "version" along with the identifier.</p> <p>Here is what I would like to use for the ID:</p> <pre><code>public class VersionedId implements DBObject { ObjectId _id; Long _version; public Map toMap() { Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;(2); map.put("_id", _id); map.put("_version", _version ); return map; } } </code></pre> <p>The entities then look like this - parent referencing a sub-entity:</p> <pre><code>@Entity (value = "entities") public class VersionedEntity { @Id VersionedId _id; @Reference VersionedSubEntity subEntity; } </code></pre> <p>...and the sub-entity referenced:</p> <pre><code>@Entity (value = "subentities") public class VersionedSubEntity { @Id VersionedId _id; } </code></pre> <p>Both saving and loading of the VersionedSubEntity works fine, so does <em>saving</em> the VersionedEntity - the DBRef is correctly created with both the <code>_id</code> and <code>_version</code>. However, trying to <em>load</em> VersionedEntity throws the following:</p> <pre><code>java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.DBRef at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:483) at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:267) at com.google.code.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:53) at com.google.code.morphia.query.MorphiaIterator.next(MorphiaIterator.java:48) at com.google.code.morphia.query.QueryImpl.get(QueryImpl.java:344) </code></pre> <p>Any hints on what I am doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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