use of javax.ejb.TransactionAttribute in project wildfly by wildfly.
the class TransactedTopicMessageSender method sendToTopicSuccessfully.
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void sendToTopicSuccessfully() throws Exception {
Connection connection = null;
Session session = null;
try {
logger.trace("Creating a Connection");
connection = factory.createConnection();
logger.trace("Creating a Session");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
Message message = session.createTextMessage("Hello world!");
logger.trace("Sending message");
producer.send(message);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
}
use of javax.ejb.TransactionAttribute in project hibernate-orm by hibernate.
the class CmtSfStatefulBean method start.
@TransactionAttribute(TransactionAttributeType.NEVER)
public void start() {
try {
Configuration configuration = new Configuration();
configuration = configuration.configure("hibernate.cfg.xml");
configuration.addAnnotatedClass(WildFlyDdlEntity.class);
sessionFactory = configuration.buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
use of javax.ejb.TransactionAttribute in project wildfly by wildfly.
the class SFSB method setupConfig.
@TransactionAttribute(TransactionAttributeType.NEVER)
public void setupConfig() {
// static {
try {
// prepare the configuration
Configuration configuration = new Configuration().setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class);
configuration.getProperties().put(AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta");
configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
// fetch the properties
Properties properties = new Properties();
configuration = configuration.configure("hibernate.cfg.xml");
properties.putAll(configuration.getProperties());
Environment.verifyProperties(properties);
ConfigurationHelper.resolvePlaceHolders(properties);
sessionFactory = configuration.buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
ex.printStackTrace();
throw new ExceptionInInitializerError(ex);
}
}
use of javax.ejb.TransactionAttribute in project wildfly by wildfly.
the class SFSBCMT method queryEmployeeNameRequireNewTX.
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Employee queryEmployeeNameRequireNewTX(int id) {
Query q = em.createQuery("SELECT e FROM Employee e where id=?");
q.setParameter(1, new Integer(id));
return (Employee) q.getSingleResult();
}
use of javax.ejb.TransactionAttribute in project wildfly by wildfly.
the class TransactedQueueMessageSender method sendToQueueAndRollback.
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void sendToQueueAndRollback() throws JMSException {
Connection connection = null;
Session session = null;
try {
logger.trace("Creating a Connection");
connection = factory.createConnection();
logger.trace("Creating a Session");
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
Message message = session.createTextMessage("Hello world 2!");
logger.trace("Sending message");
producer.send(message);
// ROLLBACK
ctx.setRollbackOnly();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
}
Aggregations