mirror303 wrote:
To be able to get all these nice things, developers are required to be able to put Hibernate-managed pojo's in httpsession scope, without running into LazyInitialization problems.
You don't really need to do that. You can simply let the entities go in a detached state (and managed by jsf) .. And afterwards merge them back into managed state...
I use a simple transaction filter per request and this also avoids lazyinitialization problems... Hibernate uses
web.xml
Code:
<!-- wrap each request in a usertransaction -->
<filter>
<filter-name>transaction-filter</filter-name>
<filter-class>com.caucho.filters.TransactionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>transaction-filter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
persistence.xml
Code:
<persistence>
<persistence-unit name="regapan" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/regapan</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.jta.UserTransaction" value="java:comp/UserTransaction"/>
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.ResinTransactionManagerLookup"/>
</properties>
</persistence-unit>
</persistence>