3

I had a scenario in which I needed one bean (ReportManager) to be loaded at application startup, so it can schedule reports for execution (polled from database by DataStore bean).

Googling around I found @Singleton, @Startup and @DependsOn annotations, which I've used like this:

@Singleton
@Startup
@DependsOn("DataStore")
public class ReportManager {
    @EJB
    DataStore dataStore;

    @PostConstruct
    public void scheduleReports() {
       logger.log("INITIALIZED");
       List<Report> reports = dataStore.getReports();
       ....
    }
}

@Singleton
@RolesAllowed("user") //I had security checks implemented like that beforehand
public class DataStore {
    @PostConstruct
    public void initialize() {
        logger.log("INITIALIZED");
    }

    public List<Report> getReports() {
        ...
    }
}

The problem was that I was getting really strange exception during deployment time:

<2012-09-27 14:04:15 CEST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "app".>
<2012-09-27 14:04:15 CEST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: Exception starting module: EJBModule(app-ejb-1.0-SNAPSHOT.jar)

Unable to deploy EJB: ReportManager from app-ejb-1.0-SNAPSHOT.jar:

Singleton ReportManager(Application: app, EJBComponent: app-ejb-1.0-SNAPSHOT.jar) failed to initialize.

   at weblogic.ejb.container.deployer.EJBModule.start(EJBModule.java:592)
 .....

Caused By: weblogic.ejb.container.InternalException: Transaction marked rollback or not expected transaction status: 1
   at weblogic.ejb.container.manager.SingletonSessionManager.postCallback(SingletonSessionManager.java:464)

Not really heplful exception message. Especially that I was also not getting any "INITIALIZED" log entries. When I commented out the dataStore.getReports() invocation everything was working fine and beans were constructed in proper order ("INITIALIZED" messages were produced). Including dataStore method invocation was causing above error and was somehow supressing all the log output.

I am using Weblogic 12c.

Kangur
  • 7,823
  • 3
  • 30
  • 32

2 Answers2

4

Finally I've figured out what was causing the error. It was the @RolesAllowed declaration which was blocking method invocation due to the empty security context, not set in @PostConstruct method when executed in @Startup bean (From EJB 3.1 spec, ch. 4.3.4: The PostConstruct lifecycle callback interceptor methods execute in an unspecified security context.).

What was needed to make it work was just the addition of @PermitAll to the invoked method:

@PermitAll
public List<Report> getReports() {
   ...
}

The error was so misleasing I've decided to put this case here, as I couldn't google the answer.

Kangur
  • 7,823
  • 3
  • 30
  • 32
  • There is no mention about interceptors in the question. And then you justify the answer with a reference to the specification regarding the interceptor security context execution (which is unspecified). And then you add a @PermittAll to the session bean method, what does it have to do with the interceptor security context if it will be unspecified? This answer makes no sense unless you found something which relies on the Weblogic unspecified behaviour. – fidudidu Oct 02 '18 at 10:22
1

In my case, I'm using SpringLoader.java class which is a @Singleton that loads Spring configuration. Spring is configured with Quartz scheduler that is trying accessing its DB table(s) (as part of some transaction).

So in my case, it helped adding the following line to this SpringLoader class: @TransactionManagement(TransactionManagementType.BEAN)

After that, some more meaningful error message is displayed: ORA-00942: table or view does not exist.

BTW: Its was also worth adding this line: @ConcurrencyManagement(ConcurrencyManagementType.BEAN)

  • After finding out what was the cause of the problem (and created required Quartz DB tables), I returned back for CONTAINER_MANAGER transaction and everything worked pretty well. – Rostislav Stribrny Aug 11 '13 at 13:58