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
Ok, that's usefull, I'll try it. Thanks.
After some digging, will the following do?
objectToCheckIfIsInitialized match {
case ic: IndirectContainer => ic.isInstantiated
case vhi: ValueHolderInterface => vhi.isInstantiated
case _ => true
}
The object may be of any type, String, Enum, Integer,
Collection, "Entity". After what I figure those 2 interfaces
cover *ToOne and *ToMany associations, right?
One more thing;
I think I have control over non-JPA objects and *ToMany
associations as *ToMany associations always have a value (the
IndirectContainer IIUC) which I may test if is instantiated.
But, when there's a @ManyToOne mapping then the field-value
is null whether it's actually null (not set in DB) or just not
initialized yet (because it's not accessed). I need to tell the
difference between the two but it seems impossible to check if a
@ManyToOne-attribute exists for an instance of an Entity without
actually loading it, is there a way? I want to prevent is
loading *ToOne associations by the validation-framework if they
are not initialized (to skip validation of the actual value of
the "other end" itself, if it's annotated by @AssertValid), but
want to be able to tell if the value is null (set or not), for
giving correct validation-error if @NotNull is set, without
loading it, is this possible? Hibernate inserts a proxy for the
value if the value exists but is lazy, with a reference to the
foreign key so it can tell if there's an object "on the other
side" without loading it, hence making it possible to tell if
it's null or not without loading the object.
I hope I made claer what I'm trying to do...
Thanks.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users