New instances and resolving mappings

View: New views
2 Messages — Rating Filter:   Alert me  

New instances and resolving mappings

by Clogs :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 annotated 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...all help is appreciated

Re: New instances and resolving mappings

by christopher delahunt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

Yes, only entities obtained from an EntityManager will be populated by
the persistence provider.  If you instantiate a new entity instance, it
has no connection to the EntityManager to get data.

Best Regards,
Chris

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 annotated 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...all help is appreciated
>
>  
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users