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
<class>com.craigew.entity.Address</class> |
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
@OneToOne(cascade = CascadeType.ALL, optional=false) | |
@JoinColumn(name="RESIDENTIAL_ADDRESS_ID") | |
private Address residentialAddress; | |
@OneToOne(cascade = CascadeType.ALL, optional=true) | |
@JoinColumn(name="POSTAL_ADDRESS_ID") | |
private Address postalAddress; |
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
protected List<T> queryString(String sql){ | |
EntityManagerFactory factory = Persistence.createEntityManagerFactory("JPAIntroduction"); | |
EntityManager em = factory.createEntityManager(); | |
List<T> results= em.createQuery(sql).getResultList(); | |
em.close(); | |
factory.close(); | |
return results; | |
} |
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
public List<Customer> returnAllCustomers() { | |
return queryString("SELECT e FROM Customer e"); | |
} | |
public List<Customer> returnCustomersForACountry(String country) { | |
return queryString("SELECT e FROM Customer e WHERE e.residentialAddress.country='" + country + "'"); | |
} |
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.craigew.service; | |
import com.craigew.entity.Address; | |
import com.craigew.entity.Customer; | |
import junit.framework.Assert; | |
import org.junit.Test; | |
import javax.persistence.EntityNotFoundException; | |
import java.util.List; |
OlderNewer