Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Instantiating a new instance and resolving references

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..
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Instantiating-a-new-instance-and-resolving-references-tp24756494p25044989.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top