[EJB/JBoss] - Problems with MDBs in JBoss 5.0
by javaJunior
Hi,
I'm starting with JBoss and having some problems with Message Driven Beans. I have a Messenger class that put a message in a queue. It works normally.
package com.jboss.ejb.teste.message;
|
| import javax.jms.Connection;
| import javax.jms.Destination;
| import javax.jms.MessageProducer;
| import javax.jms.ObjectMessage;
| import javax.jms.QueueConnectionFactory;
| import javax.jms.Session;
| import javax.naming.InitialContext;
|
| public class Messenger {
|
| private QueueConnectionFactory connectionFactory;
| private Destination destination;
|
| public Messenger() {
| try {
| InitialContext ctx = new InitialContext();
|
| connectionFactory = (QueueConnectionFactory) ctx.lookup("java:/ConnectionFactory");
| destination = (Destination) ctx.lookup("queue/JBossTesteQueue");
| }
| catch (Exception exc) {
| exc.printStackTrace();
| }
| }
|
| public void sendMessage(String nome) {
| try {
| Connection connection = connectionFactory.createQueueConnection();
| Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
|
| MessageProducer producer = session.createProducer(destination);
|
| ObjectMessage message = session.createObjectMessage();
| message.setObject(nome);
|
| producer.send(message);
|
| session.close();
| connection.close();
|
| System.out.println("Mensagem enviada com sucesso!");
| }
| catch (Exception exc) {
| exc.printStackTrace();
| }
| }
|
| }
And have this MDB, but it doesn't run. I've already tried everything i could but no success. No Exceptions, the deploy process is OK. It simply isn't called by the JBoss when i put a messege in the queue.
package com.jboss.ejb.teste.message;
|
| import java.sql.Connection;
| import java.sql.DriverManager;
| import java.sql.PreparedStatement;
| import java.text.SimpleDateFormat;
| import java.util.Date;
|
| import javax.annotation.Resource;
| import javax.ejb.ActivationConfigProperty;
| import javax.ejb.MessageDriven;
| import javax.ejb.MessageDrivenContext;
| import javax.jms.JMSException;
| import javax.jms.Message;
| import javax.jms.MessageListener;
| import javax.jms.ObjectMessage;
|
| @MessageDriven(
| name = "MessageConsumer",
| activationConfig = {
| @ActivationConfigProperty(
| propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
| @ActivationConfigProperty(
| propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
| @ActivationConfigProperty(
| propertyName = "destination", propertyValue = "queue/JBossTesteQueue")
| }
| )
| public class MessageConsumer implements MessageListener {
|
| @Resource
| private MessageDrivenContext context;
|
| public void onMessage(Message message) {
| try {
| ObjectMessage objectMessage = (ObjectMessage) message;
|
| String time = new SimpleDateFormat("dd/MM/yyyy - HH:mm:ss").format(new Date());
| System.out.println("Mensagem recebida em " + time);
| System.out.println("Content: " + objectMessage.getObject());
|
|
| Connection conn = null;
| PreparedStatement ps = null;
|
| try {
| Class.forName("com.mysql.jdbc.Driver");
| conn = DriverManager.getConnection("jdbc:mysql://localhost/JBossEJBTeste", "root", "admin");
|
| ps = conn.prepareStatement("insert into teste_table (descricao) values ?");
| ps.setString(1, objectMessage.getObject() + " - " + time);
|
| ps.execute();
| }
| catch (Exception exc) {
| exc.printStackTrace();
| }
| finally {
| try {
| ps.close();
| conn.close();
| }
| catch (Exception exc) {}
| }
|
| }
| catch (JMSException exc) {
| exc.printStackTrace();
| context.setRollbackOnly();
| }
| }
|
| }
Here is the ejb-jar.xml file:
<?xml version="1.0" encoding="UTF-8"?>
| <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
| <display-name>JBossEJBTeste_ejb</display-name>
| <enterprise-beans>
| <message-driven>
| <ejb-name>MessageConsumer</ejb-name>
| <ejb-class>com.jboss.ejb.teste.message.MessageConsumer</ejb-class>
| <transaction-type>Container</transaction-type>
| <message-destination-type>javax.jms.Queue</message-destination-type>
| </message-driven>
| </enterprise-beans>
| </ejb-jar>
| |
| | And here is the jboss.xml file:
| |
| | <?xml version="1.0" encoding="UTF-8"?>
| | |
| | | <jboss>
| | | <enterprise-beans>
| | | <message-driven>
| | | <ejb-name>MessageConsumer</ejb-name>
| | | <configuration-name>Standard Message Driven Bean</configuration-name>
| | | <destination-jndi-name>queue/JBossTesteQueue</destination-jndi-name>
| | | <activation-config>
| | | <activation-config-property>
| | | <activation-config-property-name>destinationType</activation-config-property-name>
| | | <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
| | | </activation-config-property>
| | | </activation-config>
| | | </message-driven>
| | | </enterprise-beans>
| | | </jboss>
| |
| | Could someone help me?
| |
| | Perhaps, i'm sorry about my english, i'm brazilian... but i think it can be read =)
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4227540#4227540
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4227540
15 years, 7 months
[JBoss jBPM] - Instance not of expected entity type -> Flush failed
by Stefan1509
Hi all,
Currently I get the following error message. Does someone knows what goes wrong?
Configuration:
Regards,
Stefan
2009-04-29 15:23:57,968 [server-tomcat-thread-2] ERROR org.jbpm.persistence.db.DbPersistenceService - hibernate flush failed
org.hibernate.HibernateException: instance not of expected entity type: org.jbpm.context.exe.variableinstance.UnpersistableInstance is not a: org.jbpm.context.exe.VariableInstance
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassEntityPersister(AbstractEntityPersister.java:3663)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1374)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:203)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:535)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:103)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:241)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:291)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:239)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:319)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:265)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
at org.hibernate.engine.Cascade.cascade(Cascade.java:153)
â¦â¦
2009-04-29 15:23:57,968 [server-tomcat-thread-2] ERROR org.jbpm.svc.Services - problem closing service 'persistence'
org.jbpm.persistence.JbpmPersistenceException: hibernate flush session failed
at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:207)
at org.jbpm.svc.Services.close(Services.java:243)
at org.jbpm.JbpmContext.close(JbpmContext.java:133)
â¦â¦.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4227527#4227527
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4227527
15 years, 7 months