A @ManyToOne field on the same entity class is null when 2nd level cache is enabled
-----------------------------------------------------------------------------------
Key: HHH-5087
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5087
Project: Hibernate Core
Issue Type: Bug
Components: caching (L2)
Affects Versions: 3.5.0-Final, 3.3.0.CR1
Reporter: Joseph Pachod
Attachments: demos.tar.gz
The issue is based on this discussion
https://forum.hibernate.org/viewtopic.php?p=2350265
which shows how to have a List with the index managed by Hibernate.
The example given involves two distinct entities classes, for example ParentEntity.class
et ChildEntity.class.
I tried to use it as well for a List containing the same entity, like that (see attachment
for more details):
public class RecursiveListItem
{
(..)
public void setParent(final RecursiveListItem parent)
{
this.parent = parent;
}
public RecursiveListItem getParent()
{
return parent;
}
public static final String RECURSIVELISTITEM_ONETOMANY_INDEX_COLUMN_NAME =
"recursivelistitem_position";
public static final String RECURSIVELISTITEM_ONETOMANY_JOIN_COLUMN_NAME =
"recursivelistitem_id";
@ManyToOne
@JoinColumn(name = RECURSIVELISTITEM_ONETOMANY_JOIN_COLUMN_NAME, insertable = false,
updatable = false)
private RecursiveListItem parent;
@SuppressWarnings("unused")
@Column(name = RECURSIVELISTITEM_ONETOMANY_INDEX_COLUMN_NAME, insertable = false,
updatable = false)
private Integer position;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = RecursiveListItem.RECURSIVELISTITEM_ONETOMANY_JOIN_COLUMN_NAME)
@org.hibernate.annotations.IndexColumn(name =
RecursiveListItem.RECURSIVELISTITEM_ONETOMANY_INDEX_COLUMN_NAME)
private List<RecursiveListItem> children = new
ArrayList<RecursiveListItem>();
(...)
}
In my test case, I do :
EntityManager entityManager = entityManagerFactory.createEntityManager();
RecursiveListItem parent = new RecursiveListItem();
RecursiveListItem child = new RecursiveListItem();
persist(entityManager, parent);
persist(entityManager, child);
parent.getChildren().add(child);
child.setParent(parent);
persist(entityManager, parent);
persist(entityManager, child);
entityManager.close();
entityManager = entityManagerFactory.createEntityManager();
RecursiveListItem childFound = entityManager.find(RecursiveListItem.class,
child.getId());
assertNotNull(childFound);
assertNotNull(childFound.getParent());
The last line works when the 2nd level cache and fails otherwise.
The issue applies both for 3.5 and 3.3.0.CR1. In the attached file I put two maven enabled
eclipse projects, on for 3.5 and one for 3.3.0.CR1.
Thanks in advance
best regards
joseph
ps : I'll be on vacation until next Monday (April 12)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira