Skip to content

Commit 5a8e87b

Browse files
committed
Merge pull request javaee-samples#202 from kubamarchwicki/jpa-exetended-context
JPA extended context
2 parents 44df212 + 87654aa commit 5a8e87b

File tree

11 files changed

+165
-364
lines changed

11 files changed

+165
-364
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.javaee7.jpa.extended.pc;
2+
3+
import javax.persistence.Column;
4+
import javax.persistence.Entity;
5+
import javax.persistence.Id;
6+
import javax.persistence.NamedQueries;
7+
import javax.persistence.NamedQuery;
8+
import javax.persistence.Table;
9+
import java.io.Serializable;
10+
11+
/**
12+
* @author Arun Gupta
13+
*/
14+
@Entity
15+
@Table(name="CHARACTERS")
16+
@NamedQueries({
17+
@NamedQuery(name = Character.FIND_ALL, query = "SELECT c FROM Character c")
18+
})
19+
public class Character implements Serializable {
20+
21+
public static final String FIND_ALL = "Character.findAll";
22+
23+
private static final long serialVersionUID = 1L;
24+
25+
@Id
26+
private int id;
27+
28+
@Column(length=50)
29+
private String name;
30+
31+
public Character() { }
32+
33+
public Character(int id, String name) {
34+
this.id = id;
35+
this.name = name;
36+
}
37+
38+
public Character(String name) {
39+
this.name = name;
40+
}
41+
42+
public int getId() {
43+
return id;
44+
}
45+
46+
public void setId(int id) {
47+
this.id = id;
48+
}
49+
50+
public String getName() {
51+
return name;
52+
}
53+
54+
public void setName(String name) {
55+
this.name = name;
56+
}
57+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.javaee7.jpa.extended.pc;
2+
3+
import javax.ejb.Stateful;
4+
import javax.ejb.TransactionAttribute;
5+
import javax.ejb.TransactionAttributeType;
6+
import javax.persistence.EntityManager;
7+
import javax.persistence.PersistenceContext;
8+
import javax.persistence.PersistenceContextType;
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* @author Kuba Marchwicki
14+
*/
15+
@Stateful
16+
@TransactionAttribute(TransactionAttributeType.NEVER)
17+
public class CharactersBean implements Serializable {
18+
19+
@PersistenceContext(type = PersistenceContextType.EXTENDED)
20+
EntityManager em;
21+
22+
public void save(Character e) {
23+
em.persist(e);
24+
}
25+
26+
@TransactionAttribute(TransactionAttributeType.REQUIRED)
27+
public void commitChanges() {
28+
29+
}
30+
31+
public List<Character> get() {
32+
return em.createNamedQuery(Character.FIND_ALL, Character.class).getResultList();
33+
}
34+
35+
}

jpa/extended-pc/src/main/java/org/javaee7/jpa/extended/pc/Employee.java

Lines changed: 0 additions & 92 deletions
This file was deleted.

jpa/extended-pc/src/main/java/org/javaee7/jpa/extended/pc/EmployeeBean.java

Lines changed: 0 additions & 72 deletions
This file was deleted.

jpa/extended-pc/src/main/java/org/javaee7/jpa/extended/pc/TestServlet.java

Lines changed: 0 additions & 134 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CREATE TABLE EMPLOYEE_SCHEMA_EXTENDED_PC ("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null)
1+
CREATE TABLE CHARACTERS ("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null)

0 commit comments

Comments
 (0)