users@glassfish.java.net

Re: org.hibernate.SessionException:Session is closed!

From: Sahoo <sahoo_at_sun.com>
Date: Tue, 25 Nov 2008 22:32:42 +0530

Why do you have this line of code:

em = DatabaseUtil.getEntityManager();


when you have the injected entity manager at your disposal? Use the
injected EM and let us know.

Thanks,
Sahoo
glassfish_at_javadesktop.org wrote:
> Well, I am using EntityManager in my application. Hiberanate is using other application which i am connecting to. but i don't know where is this exception is coming from. but i can see this exception on console after completion of process flow.
>
> Below is my MDB
>
> @MessageDriven(name = "ImportXMLMDB", activationConfig = {
> @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
> @ActivationConfigProperty(propertyName = "destination", propertyValue = "importXMLQueue"),
> @ActivationConfigProperty(propertyName = "sendUndeliverableMsgsToDMQ", propertyValue = "true")})
> @ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryAttempts", propertyValue = "1") })
>
> @TransactionAttribute(TransactionAttributeType.REQUIRED)
> public class ImportXMLMDB implements MessageListener {
>
> private final static Logger log = LoggerFactory.getLogger(ImportXMLMDB.class);
>
> @EJB
> private ProcessXMLLocal processXMLLocal;
>
> // @Resource
> // private SessionContext context;
> @PersistenceContext(unitName = "AOMAPersistence")
> private EntityManager em;
>
> /**
> * This method will call for each message to process.
> */
> public void onMessage(Message message) {
> try {
> em = DatabaseUtil.getEntityManager();
> if (message instanceof MapMessage) {
> log.info("i am calling MapMessage");
> MapMessage xmlMapMsg = (MapMessage) message;
> byte[] xmlMsg = xmlMapMsg.getBytes("xmlMapString");
> processXMLLocal.processXML(xmlMsg, em);
> log.info("processing of XML successful");
> }else if(message instanceof TextMessage) {
> log.info("i am calling TextMessage");
> TextMessage xmlTxtMsg = (TextMessage) message;
> String xmlMsg = xmlTxtMsg.getText();
> byte[] xmlMsgByte = xmlMsg.getBytes();
> processXMLLocal.processXML(xmlMsgByte, em);
> log.info("processing of XML successful");
> }
>
> } catch (Throwable e) {
> e.printStackTrace();
> // context.setRollbackOnly();
> log.error("Exception while getting text from message: {}", e.getMessage());
> // throw new RuntimeException(e);
> }finally {
> em.close();
> log.info("finally block of onMessage - ImportXMLMDB");
> }
> [Message sent by forum member 'chalava' (chalava)]
>
> http://forums.java.net/jive/thread.jspa?messageID=318674
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>