ejb-3.1

@Asynchronous private method in EJB

I have an asynchronous method in my EJB singleton that's called from another method in the same class. I already know that I can't call the asynchronous method directly, I have to obtain an EJB proxy. The problem is, I don't want the asynchronous method to be visible outside the class; but when I make it private, it's not executed asynch...

How to handle JPA Many-to-One Relation?

Hi, I am designing an application for collecting weather data. I have 2 POJO objects "Location" and "Record". Location contains information about latitude and longitude and the current weather conditions, and Record contains all the weather information over time for a specific location thus having a Many-to-one relation with Location. T...

Add Security Role References programmatically (without using declarative EJB Deployment Descriptor)

I'm developing a Java EE 6 application using Glassfish 3.1, B06. To secure my app, i'm using a JDBCRealm and programmatic security. This works fine to check username and password. But when it comes to declaring security roles, i have a problem: To use Security Roles in Java EE 6, i have to declare those roles both in the EJB deployment ...

How to unit testing EJBs when using JPA2?

How would you go about unit testing an EJB that uses JPA? For example, if I have an Order entity and and OrderEJB that is supposed to calculate the total of an order (as defined below) how would I go about unit testing the EJB without touching the database? Also, how would you define values for your entities, so you can assert the expect...

Can i make my own Singleton Stateless Bean with EJB 3.0 ?

Now, with EJB 3.1, we can find the javax.ejb.Singleton annocation that can ensure that this bean is going to be singleton. Is there a way that i can ensure singleton using stateless beans in EJB 3.0 with some modifications in my code (use of the keyword static, or other way to do that....) ...

Do I need to install glassfish server to use it as embedded server in application?

Hi, I am trying to use glassfish as a embedded server in my ejb3.1 project. below are my maven dependencies.. But when I run my tests it fails to deploy ejb modules. do I need to set javaee.home or some more variable ? <dependency> <groupId>org.glassfish.extras</groupId> <artifactId>glassfish-embedded-all</artifa...

Runtime Exceptions in EJB3 thrown as EJBTransactionRollbackException

I recently migrated from JBoss4.x using ejb3 to JBoss5.x using ejb3. When a runtime exception like NullPointerException is thrown, instead of the exception bubbling up so I can handle it via try-catch, I get an EJBTransactionRolledBackException instead which terminates the transaction without allowing me a chance to handle the error gra...

ejb 3.1 config schedule without hard coded

Hi! How can I configure a schedule intervals (@Schedule(persistent=true, minute="", second="/5", hour="*") ) outside from application: How can I configure it in ejb-jar.xml? Can I configure it outside from application (kind of properties file)? Thanks! ...

Do I need to use @Remote when I want to expose an EJB to a different application on same app server?

I have a @Stateless @Local Bean successfully deployed in an ear. I can see the new EJB 3.1 standard global JNDI name when I browse the JNDI tree. (java:global/product/product-ejb/ProductManagement) I want to use this EJB in a different application on the same app server. Do I need to add a remote interface for this EJB? ...

Default EJB transaction mode for asynchronous methods?

When I have an @Asynchronous method in an EJB, and I don't specify the @TransactionAttribute, then how exactly does the container handle the transaction boundaries? Obviously, it can't use the calling thread's transaction, so what does it do? Same question, but regarding methods that are triggered by the TimerService. EDIT: I think...

Debugging transactions in Java EE

I have an @Stateless EJB method in which I delete some entries from a database using JPA remove()'s throw an Exception that is annotated as @ApplicationException(rollback=true) I have no other transaction-specific annotations for the method (I set @TransactionAttribute(TransactionAttributeType.REQUIRED) but that should be the defau...

shared ejb 3 for multiple web project with glassfish

Hi all, I currently have a J2EE project containing an EJB and a WAR. Everything goes fine while I have only one WAR and one EJB module bundled in the final EAR. I now need to develop an other WAR using the same EJB module. So, I added the EJB module in the library of the new WAR. The problem is when I try to deploy the EAR bundled with...

CDI: Using Interceptors across different modules / bean archives

My Java EE 6 application consists of a war and an ejb module packaged in ear file. I'm using CDI for DI (i.e. I have a beans.xml file in both modules). I want to use a logging interceptor that is defined in the ejb module in the war module, as well. I've enabled the interceptor in the ejb's beans.xml: <beans> <interceptors> ...