Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Is there a method for checking if an object (Entity or attribute) is loaded?

Hi Andreas,

  The best suggestion I can think of is to write a similar method.  You can leverage the behavior already provided by persistenceUnitUtil.isLoaded(value).  In addition to that, you can do your own check for null.  The additional code you will have to add is EclispeLink specific.  Essentially what you need to do is check whether EclispeLink thinks the class of the object is one that is an Entity. You can do that using our org.eclipse.persistence.jpa.JpaHelper utility.  It provides a set of method that allow you to get at the EclipseLink internals from a JPA class.  One thing you could do is this:

  Session session = JpaHelper.getDatabaseSession(entityManagerFactory);
  if (session.getClassDescriptor(object.getClass()) != null){
      // this indicates this is an Entity/MappedSuperclass//Embeddable

-Tom



On 04/07/2013 6:52 PM, Andreas Joseph Krogh wrote:
I'm looking for an equivalent of Hibernate.isInitialized(object) which checks if the passed object is "initialized".
 
- If object is null, it returns true.
- If the object is an Entity and the entity is loaded it returns true.
- If the object is something other than null or an Entity (String, Collection, @ManyToOne or whatever) it returns true unless the object is a lazy-mapped attribute with isn't loaded yet.
 
I'ved tried to use persistenceUnitUtil.isLoaded(value) but it fails if the value is null or not an Entity....
 
Thanks.
 
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top