You must read an object from the EntityManager to get the version from the database. If you just instantiate an object, you only have exactly what you instantiated (there is no magic).
i.e.
you must use,
MyObject object = em.find(MyObject.class, id);
object.getLeverancier();
Clogs wrote:
Hello all,
I am faced with a problem which I am unable to get a grip on. This is the scenario:
I instantiate a POJO which is anotated as an Entity. In the POJO there are annotations which are used to reference other tables in the database, like:
@ManyToOne(fetch=FetchType.LAZY,optional=false)
@JoinColumn(name="LEVNR", referencedColumnName = "LEVNR", insertable = false, updatable = false)
private Leverancier leverancier;
public Leverancier getLeverancier() {
return leverancier;
}
public void setLeverancier(Leverancier leverancier) {
this.leverancier = leverancier;
}
When I now invoke getLeverancier() on the instantiated object, I would expect a trip to the database to get the information. However, this never happens, 'leverancier' remains null and the application falls over. The information to retrieve the required leverancier is set-up correctly (LEVNR).
Does the newly created entity need be managed in order for mappings to work?
Am I overlooking anything?
Thanks..