hobby = new Hobby();
contacts = contactService.findAllWithDetail();
In Listing 11-48, the contact with an ID of 1 is first retrieved. Then, the first name is updated, the
home telephone record is removed, and a new hobby is added. Next, the save() method is called to save
the contact. Running the program will produce the following output (other output was omitted):
Contact - Id: 1, First name: Kim Fung, Last name: Ho, Birthday: Wed Jul 30 00:00:00 CST 1980
Contact Tel Detail - Id: 1, Contact id: 1, Type: Mobile, Number: 1234567890
Hobby :Movies
Hobby :Swimming
Hobby :Jogging
You can see that the contact was updated correctly.
Deleting Data
Deleting data is much easier. We just need to implement operations to delete the contact in the CONTACT
table, as well as the underlying records in the CONTACT_TEL_DETAIL and CONTACT_HOBBY_DETAIL tables,
respectively. Listings 11-49 and 11-50 show the new method deleteContact() for the ContactMapper
interface and the corresponding query mapping in the ContactMapper.xml file.
Listing 11-49. deleteContact Operation for ContactMapper
package com.apress.prospring3.ch11.persistence;
import java.util.List;
import com.apress.prospring3.ch11.domain.*;
public interface ContactMapper {
public List<Contact> findAll();
public List<Contact> findAllWithDetail();
public Contact findById(Long id);
public List<Contact> findByFirstNameAndLastName(SearchCriteria criteria);
public void insertContact(Contact contact);
public void updateContact(Contact contact);
void deleteContact(Long id);
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks