Note that there are some explanatory texts on larger screens.

plurals
  1. PORandom errors with Threads and Hibernate sessions
    text
    copied!<p>Im using hibernate3 and spring.</p> <p>Java code:</p> <p>Class CommunicationServiceImpl, method sendAllMessages:</p> <pre><code>Collection&lt;MessageToSend&gt; messagesToSend = this.repositoriesLocator.getMessageToSendRepository().getMessagesToSend(); Iterator&lt;MessageToSend&gt; iteratorMesToSe = messagesToSend.iterator(); while (iteratorMesToSe.hasNext()) { MessageToSend mts = iteratorMesToSe.next(); MessageSender sender = new SmsSender(mts, this.repositoriesLocator); sender.start(); //run thread } </code></pre> <p>SmsSender:</p> <pre><code>public class SmsSender extends MessageSender { public SmsSender(MessageToSend messageToSend, RepositoriesLocator repositoriesLocator) { super(messageToSend, repositoriesLocator); } public void sendMessages() { try { MessageToSendSms messageToSendSms = (MessageToSendSms) this.messageToSend; Iterator&lt;CustomerByMessage&gt; itCbmsgs = messageToSendSms.getCustomerByMessage().iterator(); while (itCbmsgs.hasNext()) { CustomerByMessage cbm = (CustomerByMessage) itCbmsgs.next(); //sms sending String sResult = this.sendSMS(cb.getBody(), cbm.getCellPhone()); cbm.setStatus(CustomerByMessageStatus.SENT_OK); cbm.setSendingDate(Calendar.getInstance().getTime()); } messageToSendSms.setStatus(messageToSendStats.PROCESSED) this.log.info("saving messageToSend..."); //this line dont work! this.repositoriesLocator.getMessageToSendRepository().update(messageToSendSms); this.log.info("messageToSend saved!"); } catch (Exception e) { this.log.error("Error sms sender " + e.getMessage()); } } </code></pre> <p>This is a part of my appContext.xml:</p> <pre><code>&lt;bean id="serviceCommunication" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt; &lt;property name="transactionManager"&gt; &lt;ref local="transactionManager" /&gt; &lt;/property&gt; &lt;property name="target"&gt; &lt;ref local="communicationServiceImpl" /&gt; &lt;/property&gt; &lt;property name="transactionAttributes"&gt; &lt;props&gt; &lt;prop key="*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="communicationServiceImpl" class="com.ninatec.fnet3.services.communication.impl.CommunicationServiceImpl" parent="serviceParent"&gt; &lt;/bean&gt; </code></pre> <p>HibernateRepository<br> repositoriesLocator.getMessageToSendRepository().update CODE:</p> <pre><code>public void update(MessageToSend messageToSend) { try { this.getSession().update(messageToSend); } catch (HibernateException e) { this.log.error(e.getMessage(), e); throw e; } } </code></pre> <p>The entity MessageToSend, has never been updated.</p> <p>When I invoke CommunicationServiceImpl.sendAllMessages() I have in a collection all messagesToSend. For each MessageToSend I make a Thread to send the message. The Thread smsSender works good, but not the persistence in the data base. Changes in the object MessageToSend has not been updated in my database.</p> <p>Randoms errors are:</p> <p>session closed,</p> <p>could not initialize proxy - no Session,</p> <p>could not initialize proxy - the owning Session was closed,</p> <p>Illegal attempt to associate a collection with two open sessions in hibernate and</p> <p>failed to lazily initialize a collection of role: no session or session was closed</p> <hr> <ul> <li><ul> <li>about the thread. I want to use one thread for x sms. Every smsSender, send a group of sms.</li> </ul></li> </ul> <p>I dont understand how detach the objects from session explicitly in my architecture.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload