Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.2.0-CR1/ Hibernate annotations version: 3.1.0-beta10
Name and version of the database you are using : mysql Ver 12.22 Distrib 4.0.24
Hi,
I have a question : I have to make the mapping of a class "CV"
which has the following properties :
@SuppressWarnings("serial")
@Entity
public class CV implements ICV
{
private Long id;
private IMissionGroup defaultGroup = new MissionGroup("Groupe par defaut");
private List<IMissionGroup> missionGroups = new ArrayList<IMissionGroup>();
/**
* @return Returns the defaultGroup.
*/
@OneToOne(mappedBy="cv", targetEntity=MissionGroup.class, cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
public IMissionGroup getDefaultGroup()
{
return defaultGroup;
}
/**
* @param defaultGroup The defaultGroup to set.
*/
public void setDefaultGroup(IMissionGroup defaultGroup)
{
this.defaultGroup = defaultGroup;
}
/**
* @return Returns the missionGroups.
*/
@OneToMany(targetEntity=MissionGroup.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@JoinColumn(name="cv_id")
public List<IMissionGroup> getMissionGroups()
{
return missionGroups;
}
/**
* @param missionGroups The missionGroups to set.
*/
public void setMissionGroups(List<IMissionGroup> missionGroups)
{
this.missionGroups = missionGroups;
}
// other getters and setters
}
A mission belongs to a missionGroup
On the webapp, when I create a mission; I have to choose the missionGroup it will belongs to (list of selection :
"none" ->> defaultGroup
"mymissionGroup1"
"mymissionGroup2" ..etc
If I didn't create any missionGroups, the mission belongs to the defaultGroup by default.
The problem is that I have both a oneToOne and a oneToMany relationship between CV and MissionGroup, that's why, when I try to get the defaultGroup, I have a conflict :
Quote:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: More than one row with the given identifier was found: 1, for class: fr.model.hibernate.MissionGroup; nested exception is org.hibernate.HibernateException: More than one row with the given identifier was found: 1, for class: fr.model.hibernate.MissionGroup
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:406)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:348)
because in the meantime.. I have added some missionGroups ...
to avoid the problem, I actually put @Transient to the getDefaultGroup() method , that's mean each time I create a mission, I'd better create a missionGroup before, then I must select a missionGroup for the mission created.
And that's mean the defaultGroup is now totally useless ...
can the problem be solved in another way?