[
https://issues.apache.org/jira/browse/OPENJPA-2429?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14131362#comment-14131362
]
Sander Hindimith commented on OPENJPA-2429:
-------------------------------------------
The problem comes from the ClearInverseRelationCache method that assumes that
all inverse relations of the changed field are assumed to have an OrderBy
declaration.
if (inverse.getOrderDeclaration().indexOf(fmd.getName()) != -1) {
}
This could be the case if you have a Entity that has a inverse relation with an
OrderBy , but that same Entity is also referenced in another Entity with an
inverse relation without an OrderBy. For example:
@Entity
public class ManagementSystem {
@OneToMany(mappedBy="managementSystem")
@OrderBy("group, key")
private List<ManagementSystemProperty> properties;
@OneToMany(mappedBy = "dependsOn")
private List<ManagementSystemProperty> dependencies;
}
@Entity
public class ManagementSystemProperty implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String group;
private String key;
@ManyToOne(optional=true)
private ManagementSystem managementSystem;
@ManyToOne(optional=true)
private ManagementSystem dependsOn;
}
I this case updating the group/key field will throw an NPE on the
ClearInverseRelationCache, because the 'dependencies' inverse field in
ManagementSystem is lacking an OrderBy. This also happens if you introduce a
third Entity that also has a relationship to the first Entity.
The workaround is to align all reverse relations of a certain Entity if the
field is used in a certain @OrderBy column, but it would be simpler if the
inverse.getOrderDeclaration() had an additional NULL check.
In the other example provided Mark Liback there must be a third Entity that
also references Project in a reverse relation, but does not have the @OrderBy.
> NPE was thrown out when a @OrderBy modified column is being persisted.
> ----------------------------------------------------------------------
>
> Key: OPENJPA-2429
> URL: https://issues.apache.org/jira/browse/OPENJPA-2429
> Project: OpenJPA
> Issue Type: Bug
> Components: datacache
> Affects Versions: 2.2.1
> Environment: Windows 7
> WebSphere 8.5
> Reporter: Kymair Wu
>
> Following NPE was thrown out when a @OrderBy modified column is being
> persisted.
> {quote}
> Caused by: java.lang.NullPointerException
> at
> org.apache.openjpa.datacache.DataCachePCDataImpl.clearInverseRelationCache(DataCachePCDataImpl.java:179)
> at
> org.apache.openjpa.datacache.DataCachePCDataImpl.storeField(DataCachePCDataImpl.java:159)
> {quote}
> I notice that getOrderDeclaration() of FieldMetaData will return null when
> both _orders and _orderDec are null, which cause the NPE.
> The only place _orders will be set after class initialization seems to be
> getOrders()? But getOrders() is not involved for all the FieldMetaData of
> "fields[i].getInverseMetaDatas()"
> I'm not sure whether this is a OpenJPA issue but whether this NPE should be
> handled internally?
> Google returns a potential case but no more information found. See
> https://issues.apache.org/jira/browse/OPENJPA-2096?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
> and
> http://mail-archives.apache.org/mod_mbox/openjpa-users/201006.mbox/%[email protected]%3E
> Thanks!
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)