loading entity association after redirect
vata2999 Jun 22, 2015 12:59 AMHi,
I have an entity with a manytoone relation as follow
public class Document extends PO {
private Project project;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "proj_id", nullable = false)
@NotNull
public Project getProject()
{
return this.project;
}
public void setProject(Project project)
{
this.project = project;
}
}
I use Seam EntityHome to insert it, after redirecting to the list page the entity will be loaded in list without inserted relation, I need to refresh the page to see the relation.
public class DocumentHome extends HibernateEntityHome<Document>
{
public String persist()
{
Project p = new Project();
p.setId(5000); // I don't want to hit the database to load the entity
getInstance().setPtoject(p);
super.persist();
return "persisted";
}
}
<rich:dataTable value="#{documentQuery.documentList}" var="_doc">
<rich:column>
#{_doc.project.projectName} // this line returns null after insert and redirect
</rich:column>
</rich:dataTable>
DocumentQuery.java
public class DocumentQuery extends HibernateEntityQuery<Document>
{
private List<Document> documentList;
public List<Document> getdocumentList){
if(documentList != null)
return documentList;
Criteria criteria = getSession().createCriteria(Document.class);
criteria.createCriteria("project", Criteria.LEFT_JOIN);
documentList = criteria.list();
//I can see in the list there is a project with previouse reference id for the new item which it has only id even though I ended the conversation
return documentList();
}
}
I also end conversation .
<navigation from-action="#{documentHome.persist}">
<end-conversation/> // I can't use before-redirect true because I want to show the created message
<redirect view-id="/documentList.xhtml" >
</redirect>
</navigation>
manarh can you help me ?