-
1. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
pmuir Jun 17, 2007 6:12 PM (in response to fhh)Yeah, the way I reimplemented it requires that the entities you feed to the entityconverter are managed. I updated the docs to reflect this. File a JIRA issue and I'll see if I can work around this (won't be for 1.3 though)
-
2. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
jazir1979 Jun 28, 2007 1:27 AM (in response to fhh)This a big step backwards in my opinion. I have a similar situation to the above, although my factories were for application scope, not even at the user session level.
Now to populate these select boxes I will have to hit the DB over and over. I guess the "widest" scope I can cache these now will be at the conversation level. I'll give that a go.
Did Felix create a JIRA, or would you like me to?
thanks,
Daniel."petemuir" wrote:
Yeah, the way I reimplemented it requires that the entities you feed to the entityconverter are managed. I updated the docs to reflect this. File a JIRA issue and I'll see if I can work around this (won't be for 1.3 though) -
3. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
jazir1979 Jun 28, 2007 1:56 AM (in response to fhh)Also, I have a quick question- would it be as simple as changing the PersistenceProvider.instance().getId() to do the same thing as the default getId() implementation (Entity.forClass( bean.getClass() ).getIdentifier(bean)) rather than delegating to Hibernate?
Or will I run into further TransientObjectExceptions later on? -
5. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
jamathison Jun 29, 2007 1:50 PM (in response to fhh)I'm getting this one too, in code that worked in 1.2.1.GA. (I already voted in Jira). I'm trying to upgrade to Seam 2.0.BETA1 and AS 4.2.GA.
I removed all outjection, and stripped it down to the following simple usecase: I have a stateless session bean that returns a list of entities, which are then immediately used to populate a selectOneMenu.
Bean:@Stateless @Name("itemTextDAO") public class ItemTextDAOBean implements ItemTextDAO { @PersistenceContext EntityManager entityManager; public List<ItemText> getTutorialCategories () { Query query = entityManager.createQuery ( "select it from ItemText it where it.itemCode.itemCodeType.name=:name "); query.setParameter ("name", "TUTORIAL_CATEGORY"); return (List<ItemText>) query.getResultList(); } }
html:<h:selectOneMenu value="#{tutorialEditAction.tutorialAdapter.categoryItemText}"> <s:convertEntity /> <s:selectItems value="#{itemTextDAO.tutorialCategories}" var="category" label="#{category.text}" noSelectionLabel="-- Select --" > </s:selectItems> </h:selectOneMenu>
I then get the same exception /stacktrace that Felix did.
Any ideas for a workaround would be greatly appreciated, or else I'll have to give up on upgrading for now...
thanks,
Al -
6. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
pmuir Jun 29, 2007 1:57 PM (in response to fhh)Use an SMPC and make sure you are in a conversation. If you are stateless this is fine. It's when you are in session scope its harder.
-
7. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
jamathison Jun 29, 2007 4:00 PM (in response to fhh)Hi Pete,
Thanks for the quick reply. I am using SMPCs, and I made all the config changes specified in the Seam 2.0 Migration Guide in Fisheye.
Aren't all requests wrapped in a temporary conversation? At any rate, I am inside a long running conversation. Originally, I was making the itemTextDAO.getTutorialCategories call from inside a SFSB with ScopeType.CONVERSATION and outjecting it. Then I made it a member (with a get/set) of that same SFSB instead of outjecting. All with the same outcome.
Here's the entity query in a conversation scoped SFSB:@Stateful @Name("tutorialEditAction") @Scope(ScopeType.CONVERSATION) public class EditActionBean implements EditAction, Serializable { @PersistenceContext(type=PersistenceContextType.EXTENDED) private EntityManager entityManager; @Logger private Log log; private List<ItemText> tutorialCategories; @Create @Begin(join=true) public String create() { return "created"; } @Begin(join=true) public String begin() { log.info ("Inside tutorialEditAction.begin"); return "begin"; } public List<ItemText> getTutorialCategories() { log.info ("Begin tutorialEditAction.getTutorialCategories()"); if (this.tutorialCategories == null) { try { Query query = entityManager.createQuery ( "select it from ItemText it where it.itemCode.itemCodeType.name=:name and it.locale=:locale order by it.text asc"); query.setParameter ("name", ItemCodeType.ItemCodeTypeEnum.TUTORIAL_CATEGORY); query.setParameter ("locale", Locale.US.toString()); this.tutorialCategories = (List<ItemText>) query.getResultList(); } catch (NoResultException ex) { this.tutorialCategories = new ArrayList<ItemText>(0); } } log.info ("End tutorialEditAction.getTutorialCategories()"); return this.tutorialCategories; } public String getCategory() { return "Application"; } public void setCategory(String value) { } @End public String save() { log.info("Inside tutorialEditAction.save()"); return "saved"; } @Destroy @Remove public void destroy() {} }
And my xhtml fragment:<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:form id='tutorialEditForm'> <h:selectOneMenu value="#{tutorialEditAction.category}"> <s:convertEntity /> <s:selectItems value="#{tutorialEditAction.tutorialCategories}" var="category" label="#{category.text}" noSelectionLabel="-- Select --" > </s:selectItems> </h:selectOneMenu> </h:form> </ui:composition>
components.xml:<?xml version="1.0" encoding="UTF-8"?> <components xmlns="http://jboss.com/products/seam/components" xmlns:core="http://jboss.com/products/seam/core" xmlns:drools="http://jboss.com/products/seam/drools" xmlns:jms="http://jboss.com/products/seam/jms" xmlns:persistence="http://jboss.com/products/seam/persistence" xmlns:security="http://jboss.com/products/seam/security" xmlns:web="http://jboss.com/products/seam/web" xmlns:theme="http://jboss.com/products/seam/theme" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd http://jboss.com/products/seam/jms http://jboss.com/products/seam/jms-2.0.xsd http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd http://jboss.com/products/seam/theme http://jboss.com/products/seam/theme-2.0.xsd http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd"> <core:init debug="true" jndi-pattern="PhoneScout/#{ejbName}/local"/> <core:manager concurrent-request-timeout="500" conversation-timeout="71000000" conversation-id-parameter="cid"/> <persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/phoneScoutEntityManagerFactory"/> <security:identity authenticate-method="#{authenticateAction.authenticate}"/> <web:context-filter url-pattern="*.ajax" /> <jms:managed-topic-publisher name="sharedDeviceTopic" auto-create="true" topic-jndi-name="topic/sharedDeviceTopic"/> <component class="org.jboss.seam.remoting.messaging.SubscriptionRegistry" installed="true"> <property name="allowedTopics">sharedDeviceTopic</property> </component> <event type="org.jboss.seam.notLoggedIn"> <action expression="#{redirect.captureCurrentView}"/> </event> <event type="org.jboss.seam.postAuthenticate"> <action expression="#{redirect.returnToCapturedView}"/> </event> <factory name='cmpContextRoot' value='#{facesContext.externalContext.request.contextPath}' /> <factory name='cmpDevicesSubdir' value='#{"/devices"}' /> <factory name='cmpGraphsSubdir' value='#{cmpDevicesSubdir}/#{deviceHome.id}/graphs' /> <factory name="cmpDevicesRoot" value="#{cmpContextRoot}/devices"/> <factory name='cmpDeviceRoot' value='#{cmpDevicesRoot}/#{deviceHome.id}' /> <factory name="cmpGraphRoot" value="#{cmpDeviceRoot}/graphs"/> <factory name='cmp360Subdir' value='/devices/#{deviceHome.id}/#{empty param.viewof ? "front" : param.viewof}' /> <factory name='cmp360Root' value='#{cmpContextRoot}#{cmp360Subdir}' /> </components>
The full stack trace:org.hibernate.TransientObjectException: The instance was not associated with this session at org.hibernate.impl.SessionImpl.getIdentifier(SessionImpl.java:1375) at org.hibernate.search.impl.FullTextSessionImpl.getIdentifier(FullTextSessionImpl.java:331) at org.jboss.seam.persistence.HibernateSessionProxy.getIdentifier(HibernateSessionProxy.java:205) at org.jboss.seam.persistence.HibernatePersistenceProvider.getId(HibernatePersistenceProvider.java:114) at org.jboss.seam.framework.EntityIdentifier.<init>(EntityIdentifier.java:15) at org.jboss.seam.ui.converter.EntityConverterStore.put(EntityConverterStore.java:60) at org.jboss.seam.ui.converter.EntityConverter.getAsString(EntityConverter.java:69) at org.jboss.seam.ui.converter.PrioritizableConverter.getAsString(PrioritizableConverter.java:67) at org.jboss.seam.ui.converter.ConverterChain.getAsString(ConverterChain.java:123) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:469) at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:502) at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:757) at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:811) at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:335) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:833) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896) at javax.faces.render.Renderer.encodeChildren(Renderer.java:137) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892) at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:577) at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108) at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:233) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106) at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:63) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73) at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:87) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:63) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:46) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127) at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277) at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:40) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:140) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:595)
Not sure how to proceed to debug the problem,
Thanks,
Al -
8. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
fhh Jun 29, 2007 4:29 PM (in response to fhh)@PersistenceContext(type=PersistenceContextType.EXTENDED) private EntityManager entityManager;
Doesn't look very Seam managed to me.
Regards
Felix -
9. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
jamathison Jun 29, 2007 4:31 PM (in response to fhh)I found that if instead of using the injected entityManager, I use the one returned by:
(EntityManager) Component.getInstance ("entityManager");
then it works for some reason...
- Al -
10. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
jamathison Jun 29, 2007 4:35 PM (in response to fhh)Felix,
I posted before seeing your reply. I'm confused. What's not SMPC about it? I'll go look at the docs again....
thanks,
al -
11. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
jamathison Jun 29, 2007 4:42 PM (in response to fhh)Got it. I thought @PersistenceContext and @In were equivalent if I declared the SMPC in components.xml. I've got it wrong all over my code....
thanks Pete & Felix for your help....
- Al -
12. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
billdurrell Jul 20, 2007 2:26 PM (in response to fhh)I have the same issue . Should I inject the EntityManager with @In or use
EntityManager entityManager=(EntityManager) Component.getInstance ("entityManager");
Which also works for me. What is the side effect of using both approaches ? -
13. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
hstang Jul 20, 2007 3:22 PM (in response to fhh)"billdurrell@hotmail.com" wrote:
I have the same issue . Should I inject the EntityManager with @In or use
EntityManager entityManager=(EntityManager) Component.getInstance ("entityManager");
Which also works for me. What is the side effect of using both approaches ?
The EM you receive from @PersistenceContext is container-managed whereas the EM from Component.getInstance() is Seam-managed scoped to the conversation context. -
14. Re: Seam 1.3.0.ALPHA entity converter: The instance was not
gavin.king Jul 21, 2007 5:31 PM (in response to fhh)Should I inject the EntityManager with @In or use EntityManager entityManager=(EntityManager) Component.getInstance ("entityManager");
They are exactly the same.