ejb-3.0

How to use JNDI to obtain a new Stateful Session Bean, in EJB3?

筅森魡賤 提交于 2019-12-05 05:38:04
问题 I'm trying to use JNDI to obtain a new Stateful Session Bean in a servlet (as a local variable). My doGet() method has the following: Bean bean = (Bean) new InitialContext().lookup("beanName"); I've tried including java:comp/env but all of my attempts have led to naming exceptions. I'm attempting to bind the bean in the @Stateful annotation, using various guesses like @Stateful(name="beanName") and @Stateful(mappedName="beanName") 回答1: What I needed was to use the @EJB annotation on the

EntityManager.flush() commits the transaction in a Java web service

时间秒杀一切 提交于 2019-12-05 05:17:14
EDIT : Thanks everybody for your answers, but the problem was with my data source configuration, which was actually in auto-commit mode. See my answer below for details. Both the Javadoc of the EntityManager.flush() method and searching for it in Google seem to suggest that the flush method only sends the pending statements to the database and does not commit the transaction. But a simple test web service I created (in Java 7, Oracle 11gR2, JBoss 7.1 and the Web service is packaged as a jar file) seem to indicate otherwise: This is the table creation script: CREATE TABLE test( id INTEGER NOT

Using EJB interceptors after a method call

假如想象 提交于 2019-12-05 02:31:23
I know one can use interceptors before a method call by using the @AroundInvoke annotation. What I would like to do is execute certain code after the method call, so that I can for example create a log entry before and after a method execution. Is this possible with EJB3, or do I need to use AOP? @AroundInvoke interceptor is passed InvocationContext, and proceed() must be called to advance the method. Thus: @AroundInvoke public Object log(InvocationContext ic) throws Exception { logEntry(); try { return ic.proceed(); } finally { logExit(); } } Depending on your needs, you could also log the

REQUIRES_NEW within REQUIRES_NEW within REQUIRES_NEW … on and on

半腔热情 提交于 2019-12-05 02:20:49
问题 JBoss 4.x EJB 3.0 I've seen code like the following (greatly abbreviated): @Stateless @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public class EJB1 implements IEJB1 { @EJB private IEJB1 self; @EJB private IEJB2 ejb2; @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public boolean someMethod1() { return someMethod2(); } @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public boolean someMethod2() { return self.someMethod3(); } @TransactionAttribute

EJB specifications and Java versions - backwards compatibility

与世无争的帅哥 提交于 2019-12-05 01:42:42
问题 This is my understanding of relationship between the EJB spec and Java versions EJB 2.0 was part of J2EE 1.3 platform, which was on top J2SE 1.3 or JDK 1.3.x EJB 2.1 was part of J2EE 1.4 platform, which was on top of J2SE 1.4 or JDK 1.4.x The EJB 2.1 specification requires backward compatibility for EJB 2.0, so containers supporting EJB 2.1 and running in JDK 1.4.x will be able to run EJB 2.0 beans as well. EJB 3.0 is part of Java EE 5 platform, which required Java SE 5 (JDK 5) for

How do I access EJB bean when inside a custom Converter [duplicate]

江枫思渺然 提交于 2019-12-04 21:04:58
This question already has an answer here: How to inject @EJB, @PersistenceContext, @Inject, @Autowired, etc in @FacesConverter? 5 answers This converter is called from my JSF. I already register it inside faces-config.xml public class ProjectConverter implements Converter{ @EJB DocumentSBean sBean; @ManagedProperty(value="#{logging}") private Logging log; public ProjectConverter(){ } public Object getAsObject(FacesContext context, UIComponent component, String value) { if(value.trim().equals("")){ return null; } return sBean.getProjectById(value); } public String getAsString(FacesContext

EJB3 vs Data Access Objects

跟風遠走 提交于 2019-12-04 18:29:07
I am working on a project where we need to decide how we are going to expose our persistence layer. There are currently two options on the table: 1) Use plain DAOs. These would implement an interface and be injected (probably using Weld) in the Business Components which are EJBs. Internally they would use JPA/Hibernate for persistence. 2) Rather than injecting the DAOs using Weld, they would be implemented as EJBs, and injected with @EJB in the Business Components. Does it really make sense to use EJBs for the persistence layer when we are not using its capabilities (e.g. transaction

Can an EJB3 bean “self inject” and call its own methods via EJB container?

这一生的挚爱 提交于 2019-12-04 17:56:18
问题 Is it possible to "self inject" an EJB in order to call local methods as bean methods? There are some cases where this could be favorable, for example if container managed transactions are used and something should be accomplished in a new transaction. An example how this could work: Foo.java: @Local public interface FoO { public void doSomething(); public void processWithNewTransaction(); // this should actually be private } FooBean.java: @Stateless public class FooBean implements Foo { @EJB

Publishing EJB's local interface in weblogic

笑着哭i 提交于 2019-12-04 17:33:41
is there a way to lookup an EJB in weblogic if it implements only local interface? If I use this @Remote public interface TestSessionRemote { public void businessMethod(); } @Stateless(mappedName = "A") public class TestSessionBean implements TestSessionRemote { public void businessMethod() { } } the EJB can be looked up using this name: "A#" + TestSessionRemote.class.getName() If I change the annotation for TestSessionRemote from @Remote to @Local the EJB disappears from JNDI. Is there a way around this? EDIT: I was working with Weblogic 10.3.x (aka 11g) at that time. No, it is not possible.

Can we use both Stateless and Stateful session beans in a J2EE application?

独自空忆成欢 提交于 2019-12-04 16:00:02
Is it good way to use both Stateless and Stateful session beans for the different modules if the requirement demands ? ewernli You question is quite vague, but it seems like you basically ask for advice whether it's good to use either stateless or stateful session beans. Stateless session beans (SLSB) are definitively easy to use. There is almost nothing to configure, and they are ideal to expose service. Stateful session beans (SFSB) are superficially similar to SLSB. But the fact their are stateful make their programming model different, and are harder to use. For instance you will need to