Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problem with DescriptorEventAdapter and EJBContext
Problem with DescriptorEventAdapter and EJBContext [message #530891] Sun, 02 May 2010 12:37 Go to next message
John99  is currently offline John99 Friend
Messages: 4
Registered: May 2010
Junior Member
Hello.
I have an AuditLogger class which extends
DescriptorEventAdapter for storing all the changes of all entities in the system.

The problem is that a can't get a reference to EJBContext in AuditLogger for current user reteriving.
i tried both variants: get EJBContext by using @Resource annotation and by using direct jndi lookup. Result is always the same: EJBContext is null.

AuditLogger class:
public class AuditHandler extends DescriptorEventAdapter implements
		DescriptorCustomizer {

	@Resource
	private SessionContext ctx;
	
	protected EJBContext getContext() {
		EJBContext result = null;
        try {
	       InitialContext context = new InitialContext();
	       result = (EJBContext)context.lookup("java:comp/EJBContext");
        } catch (NamingException e) {
        	e.printStackTrace();
        }
        return result;
    };

    ......



i map AuditLogger to entity by using @Customizer annotation:
@Customizer(value=com.es.ejb.server.util.audit.AuditHandler.class)

@Entity
@Table(name = "WM_USER")
public class EJBUser {

.....



Please help me) what i'am doing wrong?

[Updated on: Sun, 02 May 2010 12:38]

Report message to a moderator

Re: Problem with DescriptorEventAdapter and EJBContext [message #531069 is a reply to message #530891] Mon, 03 May 2010 15:27 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Injection will not work, as you can only inject SessionBeans. The JNDI lookup should work, provided you URL is correct and there is an EJBContext. What error do you get?


James : Wiki : Book : Blog : Twitter
Re: Problem with DescriptorEventAdapter and EJBContext [message #531092 is a reply to message #531069] Mon, 03 May 2010 16:54 Go to previous messageGo to next message
John99  is currently offline John99 Friend
Messages: 4
Registered: May 2010
Junior Member
Hello James!

I have NamingException during EJBContext lookup:


[#|2010-05-03T20:50:09.144+0400|SEVERE|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=25;_ThreadName=Thread-1;|javax.naming.NamingException: Lookup failed for 'java:comp/EJBContext' in SerialContext  [Root exception is javax.naming.NameNotFoundException: No object bound for java:comp/EJBContext [Root exception is java.lang.IllegalStateException: Illegal invocation type for EJB Context : SERVLET_INVOCATION]]
	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)
	at com.es.ejb.server.util.audit.AuditHandler.getContext(AuditHandler.java:42)
	at com.es.ejb.server.util.audit.AuditHandler.postUpdate(AuditHandler.java:134)



App server: glassfishv3.0
Does 'java:comp/EJBContext' correct lookup name? As i understand this is the default name for EJBContext

Thanx
Re: Problem with DescriptorEventAdapter and EJBContext [message #536392 is a reply to message #530891] Thu, 27 May 2010 23:52 Go to previous message
Joel Goldberger is currently offline Joel GoldbergerFriend
Messages: 2
Registered: May 2010
Junior Member
I was getting this same error in a stateless sessionbean exposed as a web service. Finally found WebServiceContext which works in my case. Maybe this will help your issue as well.

@Resource
private WebServiceContext context

- Joel -
Previous Topic:Getting OptimisticLockException on new Entity
Next Topic:Disable eclipselink caching and query caching - not working?
Goto Forum:
  


Current Time: Mon Dec 22 05:53:35 GMT 2014

Powered by FUDForum. Page generated in 0.02038 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software