当我尝试合并我的DashboardVO对象时遇到问题。如果我尝试插入新对象或更新,一切都会好的(但更新我需要更新仪表板"和#34;以及#34;我自己)
我的DashboardVO:
public class DashboardVO implements Serializable {
private static final long serialVersionUID = 1L;
private int idDashboard;
private String descricao;
private String publico;
private Set<DashboardPerfilVO> perfis = new HashSet<DashboardPerfilVO>();
private Set<DashboardItemVO> itens = new HashSet<DashboardItemVO>();
public int getIdDashboard() {
return idDashboard;
}
public void setIdDashboard(int idDashboard) {
this.idDashboard = idDashboard;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public String getPublico() {
return publico;
}
public void setPublico(String publico) {
this.publico = publico;
}
public Set<DashboardPerfilVO> getPerfis() {
return perfis;
}
public void setPerfis(Set<DashboardPerfilVO> perfis) {
this.perfis = perfis;
}
public Set<DashboardItemVO> getItens() {
return itens;
}
public void setItens(Set<DashboardItemVO> itens) {
this.itens = itens;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + idDashboard;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DashboardVO other = (DashboardVO) obj;
if (idDashboard != other.idDashboard)
return false;
return true;
}
}
我的DashboardVO.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="gerencial.persistencia.dashboard">
<class name="DashboardVO" table="SGT_CM_DASHBOARD">
<id name="idDashboard" column="SEQ_DASHBOARD">
<generator class="sequence">
<param name="sequence">SGT_CM_DASHBOARD_SEQ_DASHBOARD_SEQ</param>
</generator>
</id>
<property name="descricao" column="DES_DASHBOARD" type="string"/>
<property name="publico" column="IND_PUBLICO" type="string"/>
<set name="perfis" inverse="true" lazy="true" cascade="all-delete-orphan" order-by="COD_PERFIL">
<key column="COD_DASHBOARD"/>
<one-to-many class="DashboardPerfilVO"/>
</set>
<set name="itens" inverse="true" lazy="true" cascade="all-delete-orphan" order-by="NUM_ORDEM">
<key column="COD_DASHBOARD"/>
<one-to-many class="DashboardItemVO"/>
</set>
</class>
我的方法保存:
@SuppressWarnings("unchecked")
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws HibernateException, Exception {
ActionErrors errors = new ActionErrors();
SessionFactory sf = HibernateUtil.getSessionFactory();
DashboardForm dashboardForm = (DashboardForm) form;
Dashboard dashboard = new Dashboard();
DashboardVO dashboardVO;
if (dashboardForm.getIdDashboard() == null
|| dashboardForm.getIdDashboard().equals("")) {
dashboardVO = new DashboardVO();
} else {
dashboardVO = dashboard.retornaDashboard(Integer
.parseInt(dashboardForm.getIdDashboard()));
}
dashboardVO.setDescricao(dashboardForm.getDescricao());
dashboardVO.setPublico(dashboardForm.getPublico());
Set<DashboardPerfilVO> perfis = new HashSet<DashboardPerfilVO>();
ArrayList<DashboardPerfilVO> perfisDashboard = (ArrayList<DashboardPerfilVO>) request
.getSession().getAttribute("perfisDashboard");
boolean existePerfilAlterar = false;
if (perfisDashboard != null) {
for (DashboardPerfilVO dashboardPerfilVO : perfisDashboard) {
if (dashboardPerfilVO.getAlterar() == 1) {
existePerfilAlterar = true;
}
dashboardPerfilVO.setDashboardVO(dashboardVO);
perfis.add(dashboardPerfilVO);
}
}
if (!existePerfilAlterar) {
// Não existe um perfil que possa alterar
errors.add("erro", new ActionMessage(
"erro.sem.perfil.alterar.dashboard"));
}
dashboardVO.setPerfis(null);
dashboardVO.setPerfis(perfis);
Set<DashboardItemVO> itens = new HashSet<DashboardItemVO>();
ArrayList<DashboardItemVO> itensDashboard = (ArrayList<DashboardItemVO>) request
.getSession().getAttribute("itensDashboard");
if (itensDashboard == null || itensDashboard.size() < 1) {
// Deve existir ao menos um item
errors.add("erro", new ActionMessage("erro.sem.item.dashboard"));
} else {
int ordem = 0;
for (DashboardItemVO dashboardItemVO : itensDashboard) {
dashboardItemVO.setOrdem(++ordem);
dashboardItemVO.setDashboardVO(dashboardVO);
for (DashboardItemSerieVO disVO : dashboardItemVO.getSeries()) {
disVO.setDashboardItemVO(dashboardItemVO);
}
itens.add(dashboardItemVO);
}
}
dashboardVO.setItens(null);
dashboardVO.setItens(itens);
if (!errors.isEmpty()) {
request.setAttribute(Globals.ERROR_KEY, errors);
return mapping.getInputForward();
} else {
if (dashboardForm.getIdDashboard() == null
|| dashboardForm.getIdDashboard().equals("")) {
// Inclui o dashboard na base de dados
dashboard.incluiDashboard(dashboardVO, sf.getCurrentSession());
dashboardForm.setIdDashboard(String.valueOf(dashboardVO
.getIdDashboard()));
} else {
// Altera o dashboard na base de dados
dashboard.mergeDashboard(dashboardVO, sf.getCurrentSession());
}
return mapping.findForward("sucesso");
}
}
在stackTrace之前我得到这个循环(我只发布几行):
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
Hibernate: select dashboardv0_.SEQ_DASHBOARD as SEQ1_41_1_, dashboardv0_.DES_DASHBOARD as DES2_41_1_, dashboardv0_.IND_PUBLICO as IND3_41_1_, perfis1_.COD_DASHBOARD as COD1_41_3_, perfis1_.COD_DASHBOARD as COD1_3_, perfis1_.COD_PERFIL as COD2_3_, perfis1_.COD_DASHBOARD as COD1_44_0_, perfis1_.COD_PERFIL as COD2_44_0_, perfis1_.IND_CONSULTAR as IND3_44_0_, perfis1_.IND_ALTERAR as IND4_44_0_, perfis1_.IND_EXCLUIR as IND5_44_0_ from SGT_CM_DASHBOARD dashboardv0_ left outer join SGT_CM_DASHBOARD_PERFIL perfis1_ on dashboardv0_.SEQ_DASHBOARD=perfis1_.COD_DASHBOARD where dashboardv0_.SEQ_DASHBOARD=? order by perfis1_.COD_PERFIL
然后我明白了:
SEVERE: Servlet.service() for servlet [action] in context with path [/itauditor] threw exception [java.lang.reflect.UndeclaredThrowableException] with root cause java.lang.StackOverflowError
问题1:我想更新DashboardVO对象及其&#34; perfis&#34;并且&#34; itens&#34;。我应该使用合并还是更新?我应该更新&#34; perfis&#34;和&#34; itens&#34;首先然后是DashboardVO?
问题2:为什么会发生这种异常?这是一个映射问题?我做错了什么?