Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] does a similar function like "void Session.load(Object object, Serializable id) " in Hibernate

Hi Tom.

Thanks for your reply.

The different between void load() function in hibernate and  getReference in JPA is,
Load() 
    will directly read the loaded entity into the input param without any return value,
but 
getReference() or  find() 
     just return the entity as the return value.....


We use a lot in our base entity ,
    PersistenceEntity.class

    public void load() {
              org.hiberntae.session.load(this,this.id);//support in hibernate,change the entity itself 
    }

so we could use :
    User user = new User();
    user.setId(1L);
    user.load();  //user will be the entity loaded by ORM

and now if use getReference() 
  PersistenceEntity.class
    public void load() {
            Object object = javax.persistence.EntityManager.getReference(this.getClass,this.id);
            setObjectToThis(); //this = object
    }
    
How to set Object value to this.
solution : copy bean by BeanUtil ,cglib copier or java reflect 
risk: but does this safety , for lazy load entity with proxy.

or any better solution......

But the disaster is from we use the void load() api.....
 

--
BR,
Ajax


Date: Wed, 10 Jul 2013 07:55:51 -0400
From: Tom Ware <tom.ware@xxxxxxxxxx>
To: eclipselink-users@xxxxxxxxxxx
Subject: Re: [eclipselink-users] does a similar function like "void
        Session.load(Object object, Serializable id) " in Hibernate
Message-ID: <51DD4BC7.6010208@xxxxxxxxxx>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

Hi Ajax,

   How does the load function compare to the JPA function, getReference()?

/**
* Get an instance, whose state may be lazily fetched.
* If the requested instance does not exist in the database,
* the EntityNotFoundException is thrown when the instance
* state is first accessed. (The persistence provider runtime is
* permitted to throw the EntityNotFoundException when
* getReference is called.)
* The application should not expect that the instance state will
* be available upon detachment, unless it was accessed by the
* application while the entity manager was open.
* @param entityClass
* @param primaryKey
* @return the found entity instance
* @throws IllegalArgumentException if the first argument does
* not denote an entity type or the second argument is
* not a valid type for that entity's primary key or
* is null
* @throws EntityNotFoundException if the entity state
* cannot be accessed
*/
public <T> T getReference(Class<T> entityClass,
Object primaryKey);

   That function is supported by EclipseLink.

-Tom

On 10/07/2013 6:39 AM, Ajax Zhang wrote:
> Hi all,
>
> We migrate the project from hibernate to eclipselink.
> But we use the hibernate load api a lot. It can directly change the
> toLoaded Entity ,not need to set the return value to the reference.
>
>     void org.hibernate.Session.load(Object object, Serializable id)
> throws HibernateException
> Read the persistent state associated with the given identifier into
> the given transient instance.
>         Parameters:
>         object an "empty" instance of the persistent class
>         id a valid identifier of an existing persistent instance of
> the class
>         Throws:
>         HibernateException
>
>
> Does the eclipselink have the similar soluction,
>
>  1.  should I need to change all the place
>  2. use beanutil or java reflect to copy the properties
>  3. or any other soluction?
>
>
>
>
>
>
> --
> Thanks & Best Regards,
> Ajax


Back to the top