My question:
I am still in the learning curve regarding Hibernate including Java. So please your help would be wonderful.
Assuming that you receive a collection, a list or the type doesn’t matter if that contains more than one element. So think about followupid = “OK1_1”, “OK1_2”…
Observation = “Good”, “Ok”, “Bad”…. And status = “I”
To have a better understanding I also included my class below. How can I map the followup xml file to be able to insert all elements of my collection in one call? Can hibernate do that or do I have to insert the element by calling hibernate for each element through a loop from the business object?
Thanks in advance for your output.
My class :
import java.util.Collection;
import SAP.Utility.InfrastructureException;
import SAP.DAOObjects.FollowupDAO;
import net.sf.hibernate.*;
//import java.util.HashSet;
import java.util.*;
public class Followup {
private Set followupid = new HashSet();
Here I tried different type of collection one at the time without success.
private List observation = new ArrayList();
private String status;
private FollowupDAO followupDAO = new FollowupDAO();
//Constructor
public Followup(){}
public Set getFollowupid() {
return followupid;
}
public void setFollowupid(Set followupid) {
this.followupid = followupid;
}
public List getObservation() {
return observation;
}
public String getStatus() {
return status;
}
public void setObservation(List observation) {
this.observation = observation;
}
public void setStatus(String status) {
this.status = status;
}
Hibernate version:
Hibernate 2.1.6
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping >
<class name="SAP.BusinessObjects.Followup"
table="X_FOLLOWUPS">
<id name="followupid"
type="java.lang.String"
column="FOLLOWUP_ID"
length="30">
<generator class="assigned"/>
</id>
<property name="observation"
type="java.lang.String"
length="2000"
column="FOLLOWUP_OBSERVATIONS"
update="true"
insert="true"/>
<property name="status"
type="java.lang.String"
length="1"
column="FOLLOWUP_STATUS"
update="true"
insert="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
//Constructor
public FollowupDAO(){
HibernateUtil.beginTransaction();
}
public void Create(Object obj) throws HibernateException
{
super.create(obj);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
}
Full stack trace of any exception that occurs:
None. The insert working fine if I save the data without using a collection. So for normal saving activity everything is ok.
Name and version of the database you are using:
Oracle 9
The generated SQL (show_sql=true):
I never get to that level when I am trying to set the mapping file to be able to save a collection using set or a list.
Debug level Hibernate log excerpt:
|