Play 2.1.3 application with Maven enhanced models not loading lazy objects
I have a Play application that is been refactored. The play models have
been refactored out to its own Maven project so they can be shared with
other projects, and the ant-run plugin is being used to enhance the model
classes.
The models work ok up to the point that it involves loading the lazy
references (I'm using field enhancement with public fields). The
references are simply not loaded and an empty object is beeing returned.
The example code is:
@Entity
class A extends Model {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int id;
@ManyToOne
public B b;
public static Finder<Integer,A> finder = new
Finder<Integer,A>(Integer.class, A.class);
}
@Entity
class B extends Model {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int id;
public String someField;
}
....
....
A a = A.finder.by(someId); // returns the correct object
B b = a.b; // Returns a not null but empty object
System.out.println(b.someField); // someField is alway null
When I try to use the referenced object the object is not null, but it
seems it hasn't been initialized with data from the DB.
Even the id field on the B is populated correctly, but the rest of the
fields are not.
Maven seems to be enhancing the objects correctly (ant-run) since I can
get the objects with queries, etc.
If I specify .fetch("b") on the Java side the object is returned
correctly, but it wasn't necessary before, and sometimes is not possible
to do so (in the Scala templates).
I've checked the DB and the related objects are there. Also the code was
working while it was inside the Play project, but a lot of code (not all)
has stopped doing so since I moved the models outside Play.
Are there any specific configs for application.conf to specify lazy
loading or am I missing something?
No comments:
Post a Comment