-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How I can write an xml file when all element is a collection
PostPosted: Wed Feb 09, 2005 8:38 am 
Beginner
Beginner

Joined: Fri Jan 07, 2005 2:47 pm
Posts: 45
Here is a table sample:

Id Observation Status
1 Look nice True
2 Good False
3 Could be better True


Normally we would considered each row as a transaction and my xml file will look like the one post under the mapping topic and hibernate will do the insert by doing a begin – saved – commit – close transaction. Perfect situation no problem with that.

But in fact what I must do is saved the first two rows in one transaction and the last row in another transaction. That’s the way I receive the data. More clearly I would have:
Begin transaction
Saved the two first row by insert……
Insert……
Commit
Close the transaction

Begin transaction
Saved the last row by insert……
Commit
Close the transaction

My question is how can I map my xml file to handle that situation???? Now I have to loop the collection as shown below and I post the code the begin and close transaction code at the begin transaction section.

public void addObservationByPatient(String followupid,
String observation,
String status){
Followup up = new Followup();
up.followupid = followupid;
up.observation = observation;
up.status = status;
follow.add(up);
}
//Create a new follow-up report
public void create() throws InfrastructureException{
try{
for (Iterator iter = follow.iterator();iter.hasNext();){
Followup followup = (Followup) iter.next();
this.followupid = followup.getFollowupid().toString();
this.observation = followup.getObservation().toString();
this.status = followup.getStatus().toString();
followupDAO.Create(this);
}



} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
}

Is hibernate can handle that type of situation??
Is it possible to have something like that??
<hibernate-mapping >

<class name="SAP.BusinessObjects.Followup"
table="X_FOLLOWUPS">

<set>
<id name="followupid"
type="java.lang.String"
column="FOLLOWUP_ID"
length="30">
<generator class="assigned"/>

</id>

<property name="status"
type="java.lang.String"
length="1"
column="FOLLOWUP_STATUS"
update="true"
insert="true"/>

<property name="observation"
type="java.lang.String"
length="2000"
column="FOLLOWUP_OBSERVATIONS"
update="true"
insert="true"/>

</set>

</class>

</hibernate-mapping>

I really need an answer.

Thanks





Hibernate version:
Hibernate 2.1.6

Mapping documents:
<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="status"
type="java.lang.String"
length="1"
column="FOLLOWUP_STATUS"
update="true"
insert="true"/>

<property name="observation"
type="java.lang.String"
length="2000"
column="FOLLOWUP_OBSERVATIONS"
update="true"
insert="true"/>



</class>

</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
//Add new data in the database.
public void Create(Object obj) throws HibernateException
{
HibernateUtil.beginTransaction();
super.create(obj);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
}
Full stack trace of any exception that occurs:
none if I considere each row as a transaction
Name and version of the database you are using:
Oracle 9
The generated SQL (show_sql=true):
Will show one insert sql at the time as it should if each row is a transaction
Debug level Hibernate log excerpt:
none


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.