Created
October 15, 2014 07:00
-
-
Save gabanox/b1d03197ae3bbad588a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company.hibernate; | |
import java.util.Date; | |
import java.util.List; | |
import java.util.Set; | |
import org.springframework.context.support.GenericXmlApplicationContext; | |
import com.company.hibernate.dao.ContactDao; | |
import com.company.hibernate.domain.Contact; | |
import com.company.hibernate.domain.ContactTelDetail; | |
import com.company.hibernate.domain.Hobby; | |
public class SpringHibernateSample { | |
public static void main(String[] args) { | |
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); | |
ctx.load("classpath:app-context.xml"); | |
ctx.refresh(); | |
ContactDao contactDao = ctx.getBean("contactDao", ContactDao.class); | |
// List contacts without details | |
// List contacts with details | |
// Find contact by ID | |
// Add new contact | |
// Update contact | |
// Delete contact | |
} | |
private static void listContacts(List<Contact> contacts) { | |
System.out.println(""); | |
System.out.println("Listing contacts without details:"); | |
for (Contact contact: contacts) { | |
System.out.println(contact); | |
System.out.println(); | |
} | |
} | |
private static void listContactsWithDetail(List<Contact> contacts) { | |
System.out.println(""); | |
System.out.println("Listing contacts with details:"); | |
for (Contact contact: contacts) { | |
System.out.println(contact); | |
if (contact.getContactTelDetails() != null) { | |
for (ContactTelDetail contactTelDetail: contact.getContactTelDetails()) { | |
System.out.println(contactTelDetail); | |
} | |
} | |
if (contact.getHobbies() != null) { | |
for (Hobby hobby: contact.getHobbies()) { | |
System.out.println(hobby); | |
} | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment