-
1. Re: EntityManager and hbm.xml mapping files
bill.burke Oct 25, 2004 9:30 PM (in response to igorfie)I guess I did not explain my usage scenario properly. I already have classes and corresponding *.hbm.xml files (actually, my classes have xdcolet tags, but that's not too important). I want to start writing new EJB3 stateless session beans, but do not want to remap all my entities with EJB3 annotations right now.
The prototype that I have is close to what are suggesting. Bascially, it adds all hbm.xml files from EJB3 module to Hibernate configuration used internally by EntityManager. As far as my session beans are concerned, they are dealing with EntityManager and EJB3 entity beans, and I can gradually replace hbm files with annotations "some time later" :-)
This also allows me to use EntityManager for things that are not possible yet to define using annotations (eg. CLOBs). -
2. Re: Nukes compatibility to JBoss upgrade path
bill.burke Oct 25, 2004 9:30 PM (in response to igorfie)ok, had some time today to have a look again...
The getNext() is now done in the AbstractInterceptor.Invoke()...
so I just deleted all the lines in the LifecycleInterceptor.
Some strange things happen now and then wenn in the LifeCycle the invoke() is called with type "invoke"... debug showed that "invoke, getLanguage" is called on the MBeanAttributeInterceptor, which then throws an Exception because it does not understand the command.
I just catched this exception and returned null in LifeCycle.invoke. It should not be done this way, but now nukes deploys, at least...
Next problem ist a nullpointer:
15:02:19,484 ERROR [Engine] StandardWrapperValve[NukeServlet]: Servlet.service()
for servlet NukeServlet threw exception
java.lang.NullPointerException: charsetName
at java.lang.String.(String.java:410)
at java.lang.String.(String.java:440)
at org.apache.coyote.tomcat5.CoyoteRequest.setCharacterEncoding(CoyoteRe
quest.java:1523)
at org.apache.coyote.tomcat5.CoyoteRequestFacade.setCharacterEncoding(Co
yoteRequestFacade.java:240)
at org.jboss.nukes.servlet.ParameterEncodingFilter.doFilter(ParameterEnc
odingFilter.java:58)
LifeCycleInterceptor:public class LifeCycleInterceptor extends AbstractInterceptor { // Attributes ---------------------------------------------------- private Logger log; // Constructors -------------------------------------------------- public LifeCycleInterceptor() { super(); this.log = Logger.getLogger(this.getClass()); log.debug("called no-args-constructor"); } public LifeCycleInterceptor(MBeanInfo info, MBeanInvoker invoker) { log.debug("called constructor:LifeCycleInterceptor(MBeanInfo info, MBeanInvoker invoker)"); this.name=info.getClassName(); this.log = Logger.getLogger(info.getClassName()); } // Public -------------------------------------------------------- public Object invoke(Invocation invocation) throws Exception,Throwable { this.name=invocation.getInvoker().getMetaData().getClassName(); this.log = Logger.getLogger(invocation.getInvoker().getMetaData().getClassName()); log.debug("LifeCycleInterceptor::invoke();invocation.getType()"+invocation.getType()); log.debug("LifeCycleInterceptor::invoke();invocation.getName()"+invocation.getName()); try { if (invocation.getType() == Invocation.OP_INVOKE && // changed here //if (invocation.getInvocationType() == Invocation.OPERATION && invocation.getSignature() != null && invocation.getSignature().length == 0) { if ("create".equals(invocation.getName())) { log.info("Creating"); create(invocation); log.info("Created"); return null; } else if ("start".equals(invocation.getName())) { log.info("Starting"); start(invocation); log.info("Started"); return null; } else if ("stop".equals(invocation.getName())) { log.info("Stopping"); stop(invocation); log.info("Stopped"); return null; } else if ("destroy".equals(invocation.getName())) { log.info("Destroying"); destroy(invocation); log.info("Destroyed"); return null; } } } catch (Throwable e) { log.error(e.getMessage()); log.debug("invocationtype:"+invocation.getType()); throw new Exception(e); } //getNext().invoke; log.debug("calling interceptor.invoke()"); try { return invocation.invoke(); } catch (Throwable e) {// changed here log.debug("catched exception "+e.getMessage()); return null; } } // Private ------------------------------------------------------- private void setState(int nextState, MBeanInvoker invoker) throws Exception { // if state changes if (getState(invoker) != nextState) { try { // update the state invoker.setAttribute(new Attribute("State", new Integer(nextState))); } catch (MBeanException e) { log.error("Cannot send state changed notification", e); } } } private int getState(MBeanInvoker invoker) throws Exception { return ((Integer) invoker.getAttribute("State")).intValue(); } private void create(Invocation invocation) throws Exception { setState(ServiceMBean.CREATED,invocation.getInvoker()); } private void start(Invocation invocation) throws Exception { int state = getState(invocation.getInvoker()); if (state == ServiceMBean.STARTING || state == ServiceMBean.STARTED) { return; } setState(ServiceMBean.STARTING,invocation.getInvoker()); transition(invocation, ServiceMBean.STARTED, ServiceMBean.FAILED); } private void stop(Invocation invocation) throws Exception { if (getState(invocation.getInvoker()) != ServiceMBean.STARTED) { return; } setState(ServiceMBean.STOPPING,invocation.getInvoker()); transition(invocation, ServiceMBean.STOPPED, ServiceMBean.FAILED); } private void destroy(Invocation invocation) throws Exception, Throwable { int state = getState(invocation.getInvoker()); if (state == ServiceMBean.DESTROYED) { return; } if (state == ServiceMBean.STOPPED) { invocation.getInvoker().invoke("stop", new Object[0], new String[0]); } setState(ServiceMBean.DESTROYED,invocation.getInvoker()); } private void transition(Invocation invocation, int success, int failure) throws Exception { try { setState(success,invocation.getInvoker()); } catch (Throwable e) { setState(failure,invocation.getInvoker()); throw new Exception(e); } } }
-
3. Re: EntityManager and hbm.xml mapping files
igorfie Oct 26, 2004 3:43 PM (in response to igorfie)I guess I did not explain my usage scenario properly. I already have classes and corresponding *.hbm.xml files (actually, my classes have xdcolet tags, but that's not too important). I want to start writing new EJB3 stateless session beans, but do not want to remap all my entities with EJB3 annotations right now.
The prototype that I have is close to what are suggesting. Bascially, it adds all hbm.xml files from EJB3 module to Hibernate configuration used internally by EntityManager. As far as my session beans are concerned, they are dealing with EntityManager and EJB3 entity beans, and I can gradually replace hbm files with annotations "some time later" :-)
This also allows me to use EntityManager for things that are not possible yet to define using annotations (eg. CLOBs).