A small background: I'm actually using Spring and Hibernate to create simple domain / Dao / service structure. I am also using the operating system to inject all my greetings in my happy places.
While refactoring, I recently got all the very popular error messages "Could not Start Proxy - No Session" A FetchType.LAZY property on my hibernate object This is something like this: / P>
person in public class {... @ManyToOne (cascade = {}, fetch = fetchtype.LAZY) @JoinColumn (name = "pet_id", nullable = false) public pet getPet () { Return pet; } ...} I have a personal service bean that reached the stomach property, and there was no problem in doing so. However, I have recently modified the code again so that a Person Heller sees PersonService instead of PersonService under the purse. While my assistant beans can see the person, he can call to get the person, it can not use the stomach when my session is closed.
So, I think that when I loose my hibernate session all the configuration looks okay, and the DAO is injected into my assistant, just like I used to be injected into my service, I'm not sure That's how my service can get stomach right, but can not help me.
Any help in understanding this "session factor secret" has been well appreciated. I know that this can be a complex subject, so the links for some good reading material will become rocky.
I have since changed the code to Fleet type. EEGER (working fine), but this puzzle is completely burning my brain :).
View per request, here's a (simplified) view in my config:
& lt; Bean id = "personSvc" class = "org.comp.service.impl PersonServiceImpl" /> & Lt; Bean id = "personHelper" class = "org.comp.service.helper.PersonHelper" /> & Lt; Bean id = "persono" class = "org.comp.dao.hibernate.HibPersonDaoImpl" & gt; & Lt; Property Name = "sessionFactory" & gt; & Lt; Ref bean = "sessionFactory" /> & Lt; / Property & gt; & Lt; / Bean & gt; ... & lt; Bean id = "datasource" class = "org.apache.commons.dbcp.basicDataSource" deleted-method = "off" & gt; & Lt; / Bean & gt; & Lt; Bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.annotation.nnationationSessionFactoryBean" & gt; & Lt; Property Name = "Data Sources" & gt; & Lt; Ref bean = "dataSource" /> & Lt; / Property & gt; & Lt; Property Name = "packagesToScan" value = "org.comp.domain" /> & Lt; Property Name = "Schema Update" Value = "Correct" /> & Lt; Property Name = "Hibernate Properties" & gt; & Lt; Theater Content & gt; & Lt; Prop key = "hibernate.show_sql" & gt; False & lt; / Prop & gt; & Lt; Prop key = "hibernate.cache.provider_class" & gt; Org.hibernate.cache.EhCacheProvider & lt; / Prop & gt; & Lt; Prop key = "hibernate.cache.provider_configuration_file_resource_path" & gt; /hibernate-ehcache.xml< / Prop & gt; & Lt; / Theater & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt; Bean id = "transaction manager" category = "org.springframework.orm.hibernate3.HibernateTransactionManager" & gt; & Lt; Property Name = "sessionFactory" & gt; & Lt; Ref bean = "sessionFactory" /> & Lt; / Property & gt; & Lt; / Bean & gt; has been autotoded in the DAO subsidiary:
@Only Owned Personal Person Dao;
Without looking at the code / reference configuration for PersonService, I can only guess I worked before refactoring. If you wrap the session management around your DAO methods, then the method closes immediately after the method, unless it was previously opened (such as).
My guess is that during the refactoring, the scope of hibernate interceptor can change, so that the session is now closed immediately after the data is received. If you want to hibernate cover the scope of Intrseptr your service / business methods, in order to be enough time to lazy work session, or alternatively, OpenSessionInViewFilter Use Make sure that the session is always available.
Comments
Post a Comment