Thans Olivier for the reply. However, I am using Hibernate, FDS and
Flex 2.0 with MySQL - Much like the CRM sample application with
Hibernate. I didn't write my own DAO. The canvas has dept code, dept
name, emp first name, emp last name. On click of save, I want to save
dept info in DEPT table (ID, CODE, NAME) and EMP info in EMP table
(ID, DEPT_ID, FNAME, LNAME) with EMP.DEPT_ID as new DEPT.ID - the code
looks something like this - 

dept = new Dept();
dept.code = fcode.text;
dept.name = fname.text;
var ir:ItemReference = dataServiceDEPT.createItem(dept);
dataServiceDEPT.commit();

emp =new Emp();
emp.dept = dept;
emp.fname = ffname.text;
emp.lname = flname.text;
dataServiceEMP.createItem(emp);
dataServiceEMP.commit();

This code creates a new DEPT but not an EMP record. Help !!!

Thanks

--- In flexcoders@yahoogroups.com, "Stembert Olivier (BIL)"
<[EMAIL PROTECTED]> wrote:
>
> Hi,
> 
> You should set the id in your dao class.
> Here is an example with a dao using Spring:
> 
> public void create(Dept dept) throws DataAccessException
> {
> String sql = ...
> NamedParameterJdbcTemplate template = new
> NamedParameterJdbcTemplate(this.getDataSource());
> MapSqlParameterSource namedParameters = new MapSqlParameterSource();
> ...
> template.update(sql, namedParameters);
> int id = getJdbcTemplate().queryForInt("call identity()");
> dept.setDeptId(id);
> 
> }
> 
> Regards,
> 
> Olivier
> 
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of sunilpatel_10
> Sent: Saturday, January 20, 2007 2:25 PM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] FDS createItem - how to find ID of inserted
> record?
> 
> 
> 
> Hi,
> 
> I have a page where I capture DEPT and EMP data. On click of a button
> I want to save DEPT record and all the EMP records with ID of newly
> created DEPT as a parent. I use FDS, hibernate and db generated IDs.
> The problem I am facing is how do I get the ID of DEPT record created
> by createitem() and access it to assign this DEPT as a parent of EMP
> records that I want to create? If I examine ID of dept object used in
> createitem after FDS commit(), it is still 0. Appreciate your help.
> 
> 
> 
>  
> 
> ---------------------
> 
> An electronic message is not binding on its sender.
> 
> Any message referring to a binding engagement must be confirmed in
> writing and duly signed.
> 
> ---------------------
> 
>  
> 
> 
> ---------------------
> An electronic message is not binding on its sender.
> Any message referring to a binding engagement must be confirmed in
writing and duly signed.
> ---------------------
>


Reply via email to