Reputation: 591
So I'm creating a Play Java app and I'm using the default Ebean as my ORM framework. I have my objects set up in a ManyToOne
and OneToMany
bidirectional mapping.
The problem that I'm having is that when I do SimCard.find.all()
and look at the pool
property in any of the returned objects, the PlanPool
has all its properties as null, except for the ID.
Here is the setup of my objects:
SimCard:
@Entity
public class SimCard extends Model {
private static final long serialVersionUID = 8664141460726922270L;
@Id
public String simId;
public String displayName;
@ManyToOne
public PlanPool pool;
@OneToMany(mappedBy = "simCard")
public List<SimUsage> usages;
public static Model.Finder<String, SimCard> find = new Model.Finder<String, SimCard>(String.class, SimCard.class);
}
PlanPool:
@Entity
public class PlanPool extends Model {
private static final long serialVersionUID = 4083095490040410160L;
@Id
public Long poolId;
public String displayName;
@ManyToOne
public Plan plan;
@OneToMany(mappedBy = "pool")
public List<SimCard> simCards;
@Required
public Boolean isUnlimited;
@Required
public Boolean isDefaultPool;
@Required
public Long maxBytes;
@Required
public Long maxCards;
public static Model.Finder<Long, PlanPool> find = new Model.Finder<Long, PlanPool>(Long.class, PlanPool.class);
}
I have some more objects that are set up in the same one-to-many, many-to-one fashion. But the problem is the same for all of them.
Upvotes: 1
Views: 1498
Reputation: 591
It appears that my set up was correct. I was manually inserting things into the database, and for some reason that screwed up Ebean; it couldn't pick up the mappings correctly. When you use the Ebean methods (save, find, etc.), it writes to the database correctly and it works now.
On another note, it's kind of weird that the values that it writes to the database look exactly like what I put in, yet it didn't work with me. I guess it does something different that I can't see because the results of the find method are consistent across different sessions.
Upvotes: 1