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
@Entity | |
@Table(name = "contact") | |
@NamedQueries({ | |
@NamedQuery(name="Contact.findById", | |
query="select distinct c from Contact c left join fetch c.contactTelDetails t left join fetch c.hobbies h where c.id = :id"), | |
@NamedQuery(name="Contact.findAllWithDetail", | |
query="select distinct c from Contact c left join fetch c.contactTelDetails t left join fetch c.hobbies h") | |
}) |
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
DROP TABLE IF EXISTS CONTACT_HOBBY_DETAIL; | |
DROP TABLE IF EXISTS CONTACT_TEL_DETAIL; | |
DROP TABLE IF EXISTS HOBBY; | |
DROP TABLE IF EXISTS CONTACT; | |
CREATE TABLE CONTACT ( | |
ID INT NOT NULL AUTO_INCREMENT | |
, FIRST_NAME VARCHAR(60) NOT NULL | |
, LAST_NAME VARCHAR(40) NOT NULL | |
, BIRTH_DATE DATE |
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
insert into contact (first_name, last_name, birth_date) values ('Clarence', 'Ho', '1980-07-30'); | |
insert into contact (first_name, last_name, birth_date) values ('Scott', 'Tiger', '1990-11-02'); | |
insert into contact (first_name, last_name, birth_date) values ('John', 'Smith', '1964-02-28'); | |
insert into contact_tel_detail (contact_id, tel_type, tel_number) values (1, 'Mobile', '1234567890'); | |
insert into contact_tel_detail (contact_id, tel_type, tel_number) values (1, 'Home', '1234567890'); | |
insert into contact_tel_detail (contact_id, tel_type, tel_number) values (2, 'Home', '1234567890'); | |
insert into hobby (hobby_id) values ('Swimming'); | |
insert into hobby (hobby_id) values ('Jogging'); |
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
log4j.rootCategory=INFO, stdout | |
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | |
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | |
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n | |
log4j.category.org.apache.activemq=ERROR | |
log4j.category.org.springframework.batch=DEBUG | |
log4j.category.org.springframework.transaction=INFO |
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; |
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
/** | |
* Created on Oct 12, 2011 | |
*/ | |
package com.company.app.domain; | |
import java.io.Serializable; | |
import java.util.Date; | |
import java.util.HashSet; | |
import java.util.Set; |
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
/** | |
* Created on Oct 12, 2011 | |
*/ | |
package com.company.app.domain; | |
import static javax.persistence.GenerationType.IDENTITY; | |
import java.io.Serializable; | |
import javax.persistence.Column; |
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
/** | |
* Created on Oct 12, 2011 | |
*/ | |
package com.company.app.domain; | |
import java.io.Serializable; | |
import java.util.HashSet; | |
import java.util.Set; | |
import javax.persistence.Column; |
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
<dependencies> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-entitymanager</artifactId> | |
<version>3.6.8.Final</version> | |
</dependency> | |
<dependency> | |
<groupId>javax.validation</groupId> | |
<artifactId>validation-api</artifactId> | |
<version>1.0.0.GA</version> |
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
private static final class ContactMapper implements RowMapper<Contact> { | |
public Contact mapRow(ResultSet rs, int rowNum) throws SQLException { | |
Contact contact = new Contact(); | |
contact.setId(rs.getLong("id")); | |
contact.setFirstName(rs.getString("first_name")); | |
contact.setLastName(rs.getString("last_name")); | |
contact.setBirthDate(rs.getDate("birth_date")); | |
return contact; |