These are my objects :
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public abstract class AdtagEntity extends GenericEntity implements Serializable {
private static final long serialVersionUID = -6624915864457400750L;
@Id
@XmlElement
protected ObjectId id;
@XmlElement
protected Date createdDate;
@XmlElement
@Indexed
protected Date modifiedDate;
@XmlElement
protected boolean deleted;
public ObjectId getId() {
return id;
}
....
}
and :
@Entity
@XmlRootElement(name = "offerAdvantage")
public class OfferAdvantage extends AdtagEntity implements Serializable {
private static final long serialVersionUID = 1L;
@XmlElement
@NotNull
private Date beginDateValidity;
...
}
And this is the content of the collection OfferAdvantage :
myset:PRIMARY> db.OfferAdvantage.findOne()
{
"_id" : ObjectId("502533ddc131e6beb0b07cae"),
"company" : "pio",
"version" : 666,
"createdDate" : ISODate("2012-08-10T16:16:29.106Z"),
"modifiedDate" : ISODate("2012-08-10T16:16:29.106Z"),
"deleted" : false,
"beginDateValidity" : ISODate("2012-08-03T13:20:00Z"),
"endDateValidity" : ISODate("2015-10-04T23:06:40Z"),
"name" : "deuxieme demarque",
"description" : "",
"pois" : [
ObjectId("4fe1ebb9e4b0ef9431abd904")
]
}
My pom.xml :
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.6.5</version>
</dependency>
<dependency>
<groupId>org.jongo</groupId>
<artifactId>jongo</artifactId>
<version>0.2</version>
</dependency>
The problem is that when I want to use an OfferAdvantage object, the id of advantage is null for each object of the collection (advantage collection is a MongoCollection of jongo api):
Iterable<OfferAdvantage> iterable = advantageCollection.find().as(OfferAdvantage.class);
Iterator<OfferAdvantage> iterator = iterable.iterator();
ObjectId advantageId = null;
while(iterator.hasNext()) {
OfferAdvantage advantage = iterator.next();
}
Thanks in advance for the help.
According to Jongo documentation you can use annotation
@JsonProperty("_id")
on top of your Morphia annotation for Jongo use :Tell if it's work, I'm highly interested. ;)