[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - JPA query.getSingleResult throws java.lang.IllegalStateExcep

motte79 do-not-reply at jboss.com
Tue Sep 11 08:09:36 EDT 2007


Here is the snippet of code i'm processing 


  | Label l;
  | for (Label newLabel : labels) {
  | 	l = entityManager.createQuery(
  | 	     "from Label where name = :name and appId = :appId")
  |              .setParameter("name", newLabel.getName())
  |              .setParameter("appId", appId);
  |         l = (Label) q.getSingleResult();
  | 	if (l != null) {
  | 		l.setTrafficLight(tl);
  | 		entityManager.merge(l);
  | 	} else {
  | 		newLabel.setTrafficLight(tl);
  | 		newLabel.setAppId(appId);
  | 		newLabels.add(newLabel);
  | 	}
  | }
  | 
  | 

The loop iterates once and merges the first existing 'Label'. I got the Exception an next q.getSingleResult() ....

I did no flush between merge and getSingleResult () ..... 

Any ideas?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4082975#4082975

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4082975



More information about the jboss-user mailing list