ejb-3.1

Can an EJB bean implement multiple interfaces?

不羁的心 提交于 2019-11-29 10:30:36
Can an EJB bean implement multiple user defined interfaces, except business interfaces (@Local, @Remote) or No-Interface view (@LocalBean)? For example define two interfaces UserInterface1 , UserInterface2 , with no annotation. Is this legal to implement: @Stateless public class MyBean implements UserInterface1, UserInterface2 { ... Then I have another confusion: @Stateless public class MyBean implements Runnable { ... //inside I won't try to manage thread } Is this legal or illegal, I found that glassfish support this situation. The given example is illegal, but nevertheless accepted by quite

In TDD, why OpenEJB and why Arquillian?

喜欢而已 提交于 2019-11-29 09:35:28
问题 I'm a web developer ended up in some Java EE development (Richfaces, Seam 2, EJB 3.1, JPA). To test JPA I use hypersonic and Mockito. But I lack deeper EJB knowledge. Some may argue that we should use OpenEJB and Arquillian, but for what? When do I need to do container dependent tests? What are the possible test scenarios where I need OpenEJB and Arquillian? Please enlighten me :) 回答1: There are two aspects in this case. Unit tests . These are intended to be very fast (execute the whole test

The mystery of Java EE 6 annotations inheritance

五迷三道 提交于 2019-11-29 02:03:20
I'm using inheritance with EJB in a few scenarios, sometimes with annotations in the super class like this generic entityDAO: public class JpaDAO<T>{ protected Class<T> entityClass; @PersistenceContext(unitName="CarrierPortalPU") protected EntityManager em; protected CriteriaBuilder cb; @PostConstruct private void init() { cb = em.getCriteriaBuilder(); } public JpaDAO(Class<T> type) { entityClass = type; } @TransactionAttribute(TransactionAttributeType.REQUIRED) public void create(T entity) { em.persist(entity); } @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public T find

Inject a stateless EJB with @Inject into CDI Weld ManagedBean (JSF 1.2 EJB Application on jboss 6 AS)

99封情书 提交于 2019-11-29 00:16:07
Currently I am trying to inject a stateless EJB into a CDI managed controller on Jboss 6 AS Final. The controller is managed in the context an accessible from the JSF pages. If I inject the stateless bean with @EJB it is working. If I inject the stateless EJB with @Inject I get the following Exception: My controller: @Named("TestController") public class TestController { @Inject private TestManagerLocal myTestManager; ... } } My stateless bean: @SuppressWarnings("unchecked") @Stateless public class TestManagerBean implements TestManagerLocal { @PersistenceContext private EntityManager em; ...

Using EJBContext getContextData - is this safe?

家住魔仙堡 提交于 2019-11-28 23:32:49
I am planning to use EJBContext to pass some properties around from the application tier (specifically, a message-driven bean) to a persistence lifecycle callback that cannot directly be injected or passed parameters (session listener in EclipseLink, entity lifecycle callback, etc.), and that callback is getting the EJBContext via JNDI. This appears to work but are there any hidden gotchas, like thread safety or object lifespan that I'm missing? (Assume the property value being passed is immutable like String or Long.) Sample bean code @MessageDriven public class MDB implements MessageListener

Why does CMT commit on exit of EJB method, when transaction attribute is “Required”?

假装没事ソ 提交于 2019-11-28 21:41:59
问题 I am consistently finding that my already-existing transaction is getting committed inside any method of an EJB marked @ejb.transaction type="Required" . Can this be correct? My expectation is, an EJB "requiring" a transaction means: if there's one already there, it will politely leave it uncommitted when done so that whoever invoked begin() can continue to use it for further operations before invoking commit() or rollback() . [Of course, if there was no transaction in the first place, then

Difference between @Stateless and @Singleton

你。 提交于 2019-11-28 20:58:59
问题 I'm following this tutorial which also uses an EJB: package exercise1; import java.util.Random; import javax.ejb.Stateless; import javax.inject.Named; @Stateless public class MessageServerBean { private int counter = 0; public String getMessage(){ Random random = new Random(); random.nextInt(9999999); int myRandomNumber = random.nextInt(); return "" + myRandomNumber; } public int getCounter(){ return counter++; } } Here is an output example: Hello from Facelets Message is: 84804258 Counter is

Can @Resource be used to inject primitives in EJB3.0?

北城余情 提交于 2019-11-28 17:20:17
Using Glassfish, I can setup a string jndi entry: JNDI name: "com/xyzcompany/echo/EchoServiceBean/viewName" Factory Class: org.glassfish.resources.custom.factory.PrimitivesAndStringFactory Properties: value="Testing123" I can then inject this container configured string into my EJB: @Resource(lookup = "com/xyzcompany/echo/EchoServiceBean/viewName") String viewName; The lookup= appears to internally do an InitialContext.lookup(...). However, this uses ejb3.1, but unfortunately my prod environment is only ejb3.0. I guess i'm trying to figure out is there a way to use @Resource(name=) or

CDI Extension for Flyway

眉间皱痕 提交于 2019-11-28 17:12:28
问题 I tried to run flyway in my application before hibernate is hooking in on my JBoss AS 7.1. I tried with an @javax.ejb.Startup annotation, but this gets executed AFTER Hibernate is initialized and the database scheme is checked. So as far as I understand we can use a CDI Extension which hooks in before Hibernate is initialized. Is there some support for that out of the box for flyway? And if not, has anyone tried to do this before? 回答1: Ok I finally found out how to do this: I had to use the

EJB 3.1 or Spring 3.. When to choose which one?

醉酒当歌 提交于 2019-11-28 16:28:12
问题 EJB achieved many improvements in 3.x versions, Spring is also commonly used and version 3 is a good alternative. There are many articles on web, but no exact comparison about ejb3x versus spring3x.. Do you have any ideas about them, in real world examples which one is better at which conditions? For example, we want to separate db and server, which means our application will be on a server, our database will be in another server.. EJB remoting vs Cluster4Spring etc ? Doing everyting