[JBoss Seam] - Re: Why do I need to use entityManager.flush() ?
by w17chm4n
@Stateful
| @Scope(ScopeType.APPLICATION)
| @Name("questionTypeManager")
| public class QuestionTypeManagerBean implements QuestionTypeManager {
|
| @Logger
| Log log;
|
| @In
| EntityManager entityManager;
|
| public void addQuestionType(String questionType) {
| entityManager.persist(new QuestionType(questionType));
| entityManager.flush();
| log.info("Successfuly persisted question type");
| }
|
| public QuestionType getQuestionTypeByName(String questionTypeName) {
| return (QuestionType)entityManager.createQuery("from QuestionType q where q.questionType = '" + questionTypeName + "'").getSingleResult();
| }
|
| public List<QuestionType> getAllQuestionTypes() {
| return entityManager.createQuery("from QuestionType qt").getResultList();
| }
|
| @Remove @Destroy
| public void destroy() {}
|
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4111193#4111193
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4111193
18 years, 4 months
[EJB/JBoss] - Re: How tom make a jdbc request inside Stateless EJB method
by guix
"adrian(a)jboss.org" wrote : Look up the datasource and ask for a connection.
| The jca wrapper will enroll the connection in the
| current transaction.
|
| Make sure you close the connection and any statements
| in a finally block to return them to the pool.
|
| Regards,
| Adrian
Hi:
I am trying this in Jboss 4.0.4 and it does not work:
example:
| protected EJBContext myContext = null;
| public void setSessionContext (SessionContext ctx){
| myContext = ctx;
| }
| public void setUserData(String userId, String name, String roleId)
| throws RemoteException{
| try {
| UserLocal userLocal = UserFactoryLocal.getUser
| (userId); //Userlocal is an entity bean
| userLocal.setRoleId(roleId);
| Object object = myContext.lookup("java:/" + myDataSourceName); // Same datasoiurce name as the bean uses, it is a local datasource name
| Connection connection =
| ((DataSource)object).getConnection();
| connection.execute("update usuario set
| rol = '" + roleId + "' where usuario = '" + userId + "'";
|
| connection.close();
|
| userLocal.setUserName(name); //if this set fails there is no rollback performed to the previous execute
| }
| catch (Exception e) {
| e.printStackTrace();
| throw new EJBException(e);
| }
| }
The example as you can see is functionalitywise, bogus, but I can see that if the code fails in setUserName then the new role appears set in the database eventhoug There is a EJB exception thrown....
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4111190#4111190
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4111190
18 years, 4 months