01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb3.test.standalone.flushmodenever;
23:
24: import javax.ejb.Remote;
25: import javax.ejb.Stateless;
26: import javax.ejb.EJB;
27: import javax.persistence.EntityManager;
28: import javax.persistence.EntityManagerFactory;
29: import javax.persistence.PersistenceContext;
30: import javax.persistence.PersistenceUnit;
31: import org.hibernate.SessionFactory;
32: import org.hibernate.Session;
33:
34: /**
35: * Comment
36: *
37: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
38: * @version $Revision: 60233 $
39: */
40: @Stateless
41: @Remote(Session1.class)
42: public class Session1Bean implements Session1 {
43: @PersistenceContext(unitName="manager1")
44: Session manager1;
45: @PersistenceContext(unitName="../flushmodenever-session2.jar#manager2")
46: EntityManager manager2;
47: @PersistenceUnit(unitName="manager1")
48: SessionFactory factory1;
49: @PersistenceUnit(unitName="../flushmodenever-session2.jar#manager2")
50: EntityManagerFactory factory2;
51: @EJB
52: Session2 session2;
53:
54: public int create1FromManager() {
55: Entity1 one = new Entity1();
56: one.setString("oneManager");
57: manager1.save(one);
58: return one.getId();
59: }
60:
61: public int create1FromFactory() {
62: Entity1 one = new Entity1();
63: Session m = factory1.openSession();
64: m.save(one);
65: // leak m.close();
66: return one.getId();
67: }
68:
69: public int create2FromManager() {
70: Entity2 two = new Entity2();
71: two.setString("twoManager");
72: manager2.persist(two);
73: return two.getId();
74: }
75:
76: public int create2FromFactory() {
77: Entity2 two = new Entity2();
78: EntityManager m = factory2.createEntityManager();
79: m.persist(two);
80: // leak m.close();
81: return two.getId();
82: }
83:
84: public void doUtil(Util ux) {
85: Util u = new Util();
86: u.setId(1);
87: u.setName("one");
88: manager1.persist(u);
89:
90: u = new Util();
91: u.setId(2);
92: u.setName("two");
93: manager2.persist(u);
94: }
95:
96: }
|