summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/EmployeeAddressMOUniBean.java
blob: be74d184571c11204d6a8d8a5bfb30e9a486b16e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package examples.entity.uni.many_to_one;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import examples.entity.uni.many_to_one.interfaces.EmployeeAddressMOUni;

@Stateless
public class EmployeeAddressMOUniBean implements EmployeeAddressMOUni {
	@PersistenceContext
	EntityManager em;

	public void doSomeStuff() {
		BusinessAddress a = new BusinessAddress();
		a.setCity("Huntington Station");
		a.setZipcode("11746");
		
		Employee e = new Employee();
		e.setName("Micah Silverman");
		e.setAddress(a);
		em.persist(e);
		
		e = new Employee();
		e.setName("Tes Silverman");
		e.setAddress(a);
		em.persist(e);
		
		e = new Employee();
		e.setName("Shaina Silverman");
		e.setAddress(a);
		em.persist(e);
	}

	public List getEmployees() {
		Query q = em.createQuery("SELECT e FROM Employee e");
		return q.getResultList();
	}
}