You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rick Gruber-Riemer <ri...@vanosten.net> on 2005/08/31 12:11:49 UTC

JSF + Spring + Hibernate

Hej

I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my webapplication. When I get a list of records from the database in a table or make a new record using a form everything works fine. However when I try to edit a record in a form, I get a org.hibernate.LazyInitializationException error on opening the editform.
I understand this has something to do with the Hibernate sessions. And it has nothing to do with MyFaces in particular. And I have found some hints by googeling like Spring's OpenSessionInViewFilter. However I do not have a clue what to change where in the configuration.

=> Has somebody used JSF+Spring+Hibernate successfully?
=> Downloadable sample code?
=> Do I need the jsf-spring integration library?

Any hint would be much appreciated ... Rick

<hibernate-mapping>
	<class name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink"
		table="DANAFILE.SCANJOUR_LINK">
		<id name="id" type="long" column="ROW_ID">
			<meta attribute="scope-set">protected</meta>
			<generator class="sequence">
                <param name="sequence">DANAFILE.SEQNUMBER</param>
        	</generator>
        </id>
		<version column="REVISION" name="revision" />
		<property name="objId" type="string" not-null="true"/>
		<property name="scanJourNumber" type="int" column="SCANJOUR_NUMBER" not-null="true"/>
		<property name="notes" type="string" column="NOTES" not-null="false"/>
		<property name="active" type="yes_no" column="ACTIVE" not-null="true" />
		<property name="createdBy" type="string" column="CREATED_BY" not-null="true"/>
		<property name="lastUpdatedBy" type="string" column="LAST_UPD_BY" not-null="true"/>
		<property name="createdDate" type="timestamp" column="CREATED_DT" not-null="true"/>
		<property name="lastUpdatedDate" type="timestamp" column="LAST_UPD_DT" not-null="true"/>		
	</class>
</hibernate-mapping>

<beans>
	<bean id="danafileHbmDS" class="oracle.jdbc.pool.OracleDataSource">
		<property name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
		<property name="URL"><value>jdbc:oracle:thin:@10.0.0.3:1521:dhdvl</value></property>
		<property name="user"><value>danafile_web</value></property>
		<property name="password"><value>styr3ls3n</value></property>
	</bean>
	
	<!-- Hibernate SessionFactories -->
	<bean id="danafileHbmSF" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource"><ref local="danafileHbmDS"/></property>
		<property name="mappingResources">
			<list>
				<value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLink.hbm.xml</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
				<prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>

	<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory"><ref local="danafileHbmSF"/></property>
	</bean>
		
	<bean id="scanJourLinkDAO" class="dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLinkHbmDAO">
		<property name="sessionFactory"><ref local="danafileHbmSF"/></property>
	</bean>
</beans>


ERROR - LazyInitializationException.<init>(19) | could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
        at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
        at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
        at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
        at dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:419)
        at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:104)
        at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:555)
        at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
        at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:441)
  

Re: JSF + Spring + Hibernate

Posted by Rick Gruber-Riemer <ri...@vanosten.net>.
Thank you Turgay

The solution unfortunately does not work for me. 

Maybe I do something stupid. So I have to read through all the other replies 
and try to understand ...

Regards ... Rick

Onsdag 31 august 2005 12:18 skrev Turgay Zengin:
> Sorry, I forgot the filter mapping part. You should also add this to
> web.xml:
>
> <filter-mapping>
>         <filter-name>hibernateFilter</filter-name>
>         <url-pattern>*.do</url-pattern>
> </filter-mapping>
>
> Just replace the url-pattern with the correct pattern you use for JSF
> (*.jsf for example)
>
> -Turgay
>
> On 8/31/05, Turgay Zengin <tu...@gmail.com> wrote:
> > Did you try the OpenSessionInViewFilter?
> > In web.xml, define this filter:
> >
> > <filter>
> >     <filter-name>hibernateFilter</filter-name>
> > <filter-class>org.springframework.orm.hibernate.support.OpenSessionInView
> >Filter</filter-class> </filter>
> >
> > I have not tried this with MyFaces yet, but with Struts this worked for
> > me.
> >
> > HTH,
> > Turgay.

Re: JSF + Spring + Hibernate

Posted by Turgay Zengin <tu...@gmail.com>.
Sorry, I forgot the filter mapping part. You should also add this to web.xml:

<filter-mapping>
        <filter-name>hibernateFilter</filter-name>
        <url-pattern>*.do</url-pattern>
</filter-mapping>

Just replace the url-pattern with the correct pattern you use for JSF
(*.jsf for example)

-Turgay

On 8/31/05, Turgay Zengin <tu...@gmail.com> wrote:
> Did you try the OpenSessionInViewFilter?
> In web.xml, define this filter:
> 
> <filter>
>     <filter-name>hibernateFilter</filter-name>
> <filter-class>org.springframework.orm.hibernate.support.OpenSessionInViewFilter</filter-class>
> </filter>
> 
> I have not tried this with MyFaces yet, but with Struts this worked for me.
> 
> HTH,
> Turgay.

Re: JSF + Spring + Hibernate

Posted by Turgay Zengin <tu...@gmail.com>.
Did you try the OpenSessionInViewFilter?
In web.xml, define this filter:

<filter>
    <filter-name>hibernateFilter</filter-name>               
<filter-class>org.springframework.orm.hibernate.support.OpenSessionInViewFilter</filter-class>
</filter>

I have not tried this with MyFaces yet, but with Struts this worked for me.

HTH,
Turgay.

On 8/31/05, Rick Gruber-Riemer <ri...@vanosten.net> wrote:
> Hej
> 
> I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my webapplication. When I get a list of records from the database in a table or make a new record using a form everything works fine. However when I try to edit a record in a form, I get a org.hibernate.LazyInitializationException error on opening the editform.
> I understand this has something to do with the Hibernate sessions. And it has nothing to do with MyFaces in particular. And I have found some hints by googeling like Spring's OpenSessionInViewFilter. However I do not have a clue what to change where in the configuration.
> 
> => Has somebody used JSF+Spring+Hibernate successfully?
> => Downloadable sample code?
> => Do I need the jsf-spring integration library?
> 
> Any hint would be much appreciated ... Rick
> 
> <hibernate-mapping>
>         <class name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink"
>                 table="DANAFILE.SCANJOUR_LINK">
>                 <id name="id" type="long" column="ROW_ID">
>                         <meta attribute="scope-set">protected</meta>
>                         <generator class="sequence">
>                 <param name="sequence">DANAFILE.SEQNUMBER</param>
>                 </generator>
>         </id>
>                 <version column="REVISION" name="revision" />
>                 <property name="objId" type="string" not-null="true"/>
>                 <property name="scanJourNumber" type="int" column="SCANJOUR_NUMBER" not-null="true"/>
>                 <property name="notes" type="string" column="NOTES" not-null="false"/>
>                 <property name="active" type="yes_no" column="ACTIVE" not-null="true" />
>                 <property name="createdBy" type="string" column="CREATED_BY" not-null="true"/>
>                 <property name="lastUpdatedBy" type="string" column="LAST_UPD_BY" not-null="true"/>
>                 <property name="createdDate" type="timestamp" column="CREATED_DT" not-null="true"/>
>                 <property name="lastUpdatedDate" type="timestamp" column="LAST_UPD_DT" not-null="true"/>
>         </class>
> </hibernate-mapping>
> 
> <beans>
>         <bean id="danafileHbmDS" class="oracle.jdbc.pool.OracleDataSource">
>                 <property name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
>                 <property name="URL"><value>jdbc:oracle:thin:@10.0.0.3:1521:dhdvl</value></property>
>                 <property name="user"><value>danafile_web</value></property>
>                 <property name="password"><value>styr3ls3n</value></property>
>         </bean>
> 
>         <!-- Hibernate SessionFactories -->
>         <bean id="danafileHbmSF" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
>                 <property name="dataSource"><ref local="danafileHbmDS"/></property>
>                 <property name="mappingResources">
>                         <list>
>                                 <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLink.hbm.xml</value>
>                         </list>
>                 </property>
>                 <property name="hibernateProperties">
>                         <props>
>                                 <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
>                                 <prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
>                                 <prop key="hibernate.show_sql">true</prop>
>                         </props>
>                 </property>
>         </bean>
> 
>         <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
>         <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
>                 <property name="sessionFactory"><ref local="danafileHbmSF"/></property>
>         </bean>
> 
>         <bean id="scanJourLinkDAO" class="dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLinkHbmDAO">
>                 <property name="sessionFactory"><ref local="danafileHbmSF"/></property>
>         </bean>
> </beans>
> 
> 
> ERROR - LazyInitializationException.<init>(19) | could not initialize proxy - the owning Session was closed
> org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
>         at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
>         at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
>         at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
>         at dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:419)
>         at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:104)
>         at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:555)
>         at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
>         at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:441)
> 
> 


-- 
Regards,
Turgay Zengin

RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
What has worked for me is using a request scoped managed bean to provide the
session (thread local, for the time being), and a PhaseListener to close it
when the rendering is complete.   This approach allows my JSF view to use
lists and proxy objects returned directly from Hibernate (which I think is
what you want to do?).   I'm not using Spring for this project right now,
but it seems like it wouldn't be too hard to take advantage of Spring's
thread local session feature with a PhaseListener and simple managed bean
that provides sessions.
 
- Josh
joshua@hibernate.org


  _____  

From: Enrique Medina [mailto:e.medina.m@gmail.com] 
Sent: Wednesday, August 31, 2005 6:41 AM
To: MyFaces Discussion; martin@marinschek.com
Subject: Re: JSF + Spring + Hibernate


I also run into problems when using lazy loading due to the fact that an
object related to my object was also lazy.

So I solved it by extending the ListDataModel class with a callback
mechanism that allows me to define some kind of logic in every row of the
data table (the logic is reattaching the object to the current Hibernate
session, of course).

Let me show you some code:

public class LazyListDataModel extends ListDataModel
{

    private DataModelCallback dataModelCallback;

    private LazyListDataModel()
    {
    }

    private LazyListDataModel(List list)
    {
    }

    public LazyListDataModel(List list, DataModelCallback dataModelCallback)
    {
        super(list);

        this.dataModelCallback = dataModelCallback;
    }

    public Object getRowData()
    {
        // Get the object...
        Object objeto = super.getRowData();

        // ...invoke the callback before returning it.
        if (this.dataModelCallback != null)
        {
            this.dataModelCallback.execute(objeto);
        }

        return objeto;
    }

}

public interface DataModelCallback
{

    public abstract void execute(Object objeto);

}

Example of use:

        this.politicasDataModel = new LazyListDataModel(this
                .busquedaPoliticas(), new DataModelCallback()
        {

            public void execute(Object objeto)
            {
                WebappUtils.reasociarObjeto(objeto);
            }
        });

and the reattachment code:

    public static void reasociarObjeto(Object objeto)
    {
        ((DummyDAOHibernateImpl) FacesUtils.getBean("dummyDAO"))
                .getHibernateTemplate().lock(objeto, LockMode.NONE);
    }

Notice that I use a dummyDAO object just to be able to use Hibernate's DAO
support by Spring ;-)

Also my 2 cents ;-)


2005/8/31, Martin Marinschek <ma...@gmail.com>: 

A very short hint from my side:

that exception means this object is not in the session anymore. You
can easily reapply it to the session by calling

session.update(object)

If you are sure that your object has not changed since it was last in 
the session, you can call:

session.lock(object, LockMode.NONE);

regards,

Martin

On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> I think before giving a short answer... I will give you a detailed 
> explanation via a links:
>
>
http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate%29
>
> This small article describes exactly the problems you run into and how
> to solve them...
>
> Werner
>
>
>
> Rick Gruber-Riemer wrote:
> > Hej
> >
> > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my
webapplication. When I get a list of records from the database in a table or
make a new record using a form everything works fine. However when I try to
edit a record in a form, I get a org.hibernate.LazyInitializationException
error on opening the editform.
> > I understand this has something to do with the Hibernate sessions. And
it has nothing to do with MyFaces in particular. And I have found some hints
by googeling like Spring's OpenSessionInViewFilter. However I do not have a
clue what to change where in the configuration.
> >
> > => Has somebody used JSF+Spring+Hibernate successfully?
> > => Downloadable sample code?
> > => Do I need the jsf-spring integration library? 
> >
> > Any hint would be much appreciated ... Rick
> >
> > <hibernate-mapping>
> >       <class
name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLin
k "
> >               table="DANAFILE.SCANJOUR_LINK">
> >               <id name="id" type="long" column="ROW_ID">
> >                       <meta attribute="scope-set">protected</meta>
> >                       <generator class="sequence">
> >                 <param name="sequence">DANAFILE.SEQNUMBER</param>
> >               </generator>
> >         </id>
> >               <version column="REVISION" name="revision" />
> >               <property name="objId" type="string" not-null="true"/>
> >               <property name="scanJourNumber" type="int"
column="SCANJOUR_NUMBER" not-null="true"/>
> >               <property name="notes" type="string" column="NOTES"
not-null="false"/>
> >               <property name="active" type="yes_no" column="ACTIVE"
not-null="true" />
> >               <property name="createdBy" type="string"
column="CREATED_BY" not-null="true"/>
> >               <property name="lastUpdatedBy" type="string"
column="LAST_UPD_BY" not-null="true"/>
> >               <property name="createdDate" type="timestamp"
column="CREATED_DT" not-null="true"/>
> >               <property name="lastUpdatedDate" type="timestamp"
column="LAST_UPD_DT" not-null="true"/>
> >       </class>
> > </hibernate-mapping>
> >
> > <beans>
> >       <bean id="danafileHbmDS" class="
oracle.jdbc.pool.OracleDataSource">
> >               <property
name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
> >               <property
name="URL"><value>jdbc:oracle:thin:@10.0.0.3:1521:dhdvl</value></property>
> >               <property
name="user"><value>danafile_web</value></property>
> >               <property
name="password"><value>styr3ls3n</value></property>
> >       </bean>
> >
> >       <!-- Hibernate SessionFactories -->
> >       <bean id="danafileHbmSF" class="
org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> >               <property name="dataSource"><ref
local="danafileHbmDS"/></property>
> >               <property name="mappingResources">
> >                       <list>
> >
<value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLi
nk.hbm.xml</value>
> >                       </list>
> >               </property>
> >               <property name="hibernateProperties">
> >                       <props>
> >                               <prop
key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
> >                               <prop
key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
> >                               <prop key="hibernate.show_sql">true</prop>
> >                       </props>
> >               </property>
> >       </bean>
> >
> >       <!-- Transaction manager for a single Hibernate SessionFactory
(alternative to JTA) -->
> >       <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> >               <property name="sessionFactory"><ref
local="danafileHbmSF"/></property>
> >       </bean>
> >
> >       <bean id="scanJourLinkDAO"
class="dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLi
nkHbmDAO ">
> >               <property name="sessionFactory"><ref
local="danafileHbmSF"/></property>
> >       </bean>
> > </beans>
> >
> >
> > ERROR - LazyInitializationException.<init>(19) | could not initialize
proxy - the owning Session was closed 
> > org.hibernate.LazyInitializationException: could not initialize proxy -
the owning Session was closed
> >         at
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializ
er.java :53)
> >         at
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyIn
itializer.java:84)
> >         at
org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java
:134)
> >         at
dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$Enh
ancerByCGLIB$$c24a4569.getScanJourNumber(<generated>)
> >         at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
> >         at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
> >         at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java :25)
> >         at java.lang.reflect.Method.invoke(Method.java:585)
> >         at
org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.
java:419)
> >         at org.apache.myfaces.el.PropertyResolverImpl.getValue
(PropertyResolverImpl.java:104)
> >         at
org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelpe
r.java:555)
> >         at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java
:145)
> >         at
org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:441)
> >
> >
>
>


--

http://www.irian.at 
Your JSF powerhouse -
JSF Trainings in English and German




Re: JSF + Spring + Hibernate

Posted by Enrique Medina <e....@gmail.com>.
Hope that "nice one" does not refer to its slang meaning -> good joke 
(slang)

Forget it, it just another "nice one" from me ;-)

2005/8/31, Martin Marinschek <ma...@gmail.com>:
> 
> Nice One!
> 
> regards,
> 
> Martin
> 
> On 8/31/05, Enrique Medina <e....@gmail.com> wrote:
> > I also run into problems when using lazy loading due to the fact that an
> > object related to my object was also lazy.
> >
> > So I solved it by extending the ListDataModel class with a callback
> > mechanism that allows me to define some kind of logic in every row of 
> the
> > data table (the logic is reattaching the object to the current Hibernate
> > session, of course).
> >
> > Let me show you some code:
> >
> > public class LazyListDataModel extends ListDataModel
> > {
> >
> > private DataModelCallback dataModelCallback;
> >
> > private LazyListDataModel()
> > {
> > }
> >
> > private LazyListDataModel(List list)
> > {
> > }
> >
> > public LazyListDataModel(List list, DataModelCallback
> > dataModelCallback)
> > {
> > super(list);
> >
> > this.dataModelCallback = dataModelCallback;
> > }
> >
> > public Object getRowData()
> > {
> > // Get the object...
> > Object objeto = super.getRowData();
> >
> > // ...invoke the callback before returning it.
> > if (this.dataModelCallback != null)
> > {
> > this.dataModelCallback.execute(objeto);
> > }
> >
> > return objeto;
> > }
> >
> > }
> >
> > public interface DataModelCallback
> > {
> >
> > public abstract void execute(Object objeto);
> >
> > }
> >
> > Example of use:
> >
> > this.politicasDataModel = new LazyListDataModel(this
> > .busquedaPoliticas(), new DataModelCallback()
> > {
> >
> > public void execute(Object objeto)
> > {
> > WebappUtils.reasociarObjeto(objeto);
> > }
> > });
> >
> > and the reattachment code:
> >
> > public static void reasociarObjeto(Object objeto)
> > {
> > ((DummyDAOHibernateImpl) FacesUtils.getBean("dummyDAO"))
> > .getHibernateTemplate().lock(objeto,
> > LockMode.NONE);
> > }
> >
> > Notice that I use a dummyDAO object just to be able to use Hibernate's 
> DAO
> > support by Spring ;-)
> >
> > Also my 2 cents ;-)
> >
> > 2005/8/31, Martin Marinschek <ma...@gmail.com>:
> > > A very short hint from my side:
> > >
> > > that exception means this object is not in the session anymore. You
> > > can easily reapply it to the session by calling
> > >
> > > session.update(object)
> > >
> > > If you are sure that your object has not changed since it was last in
> > > the session, you can call:
> > >
> > > session.lock(object, LockMode.NONE);
> > >
> > > regards,
> > >
> > > Martin
> > >
> > > On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> > > > I think before giving a short answer... I will give you a detailed
> > > > explanation via a links:
> > > >
> > > >
> > 
> http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate%29
> > > >
> > > > This small article describes exactly the problems you run into and 
> how
> > > > to solve them...
> > > >
> > > > Werner
> > > >
> > > >
> > > >
> > > > Rick Gruber-Riemer wrote:
> > > > > Hej
> > > > >
> > > > > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my
> > webapplication. When I get a list of records from the database in a 
> table or
> > make a new record using a form everything works fine. However when I try 
> to
> > edit a record in a form, I get a
> > org.hibernate.LazyInitializationException error on opening
> > the editform.
> > > > > I understand this has something to do with the Hibernate sessions. 
> And
> > it has nothing to do with MyFaces in particular. And I have found some 
> hints
> > by googeling like Spring's OpenSessionInViewFilter. However I do not 
> have a
> > clue what to change where in the configuration.
> > > > >
> > > > > => Has somebody used JSF+Spring+Hibernate successfully?
> > > > > => Downloadable sample code?
> > > > > => Do I need the jsf-spring integration library?
> > > > >
> > > > > Any hint would be much appreciated ... Rick
> > > > >
> > > > > <hibernate-mapping>
> > > > > <class
> > name="
> dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink
> > "
> > > > > table="DANAFILE.SCANJOUR_LINK">
> > > > > <id name="id" type="long" column="ROW_ID">
> > > > > <meta
> > attribute="scope-set">protected</meta>
> > > > > <generator class="sequence">
> > > > > <param name="sequence">DANAFILE.SEQNUMBER</param>
> > > > > </generator>
> > > > > </id>
> > > > > <version column="REVISION" name="revision" />
> > > > > <property name="objId" type="string" not-null="true"/>
> > > > > <property name="scanJourNumber" type="int"
> > column="SCANJOUR_NUMBER" not-null="true"/>
> > > > > <property name="notes" type="string" column="NOTES"
> > not-null="false"/>
> > > > > <property name="active" type="yes_no" column="ACTIVE"
> > not-null="true" />
> > > > > <property name="createdBy" type="string"
> > column="CREATED_BY" not-null="true"/>
> > > > > <property name="lastUpdatedBy" type="string"
> > column="LAST_UPD_BY" not-null="true"/>
> > > > > <property name="createdDate" type="timestamp"
> > column="CREATED_DT" not-null="true"/>
> > > > > <property name="lastUpdatedDate" type="timestamp"
> > column="LAST_UPD_DT" not-null="true"/>
> > > > > </class>
> > > > > </hibernate-mapping>
> > > > >
> > > > > <beans>
> > > > > <bean id="danafileHbmDS" class="
> > oracle.jdbc.pool.OracleDataSource">
> > > > > <property
> > name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
> > > > > <property
> > name="URL"><value>jdbc:oracle:thin:@10.0.0.3
> :1521:dhdvl</value></property>
> > > > > <property
> > name="user"><value>danafile_web</value></property>
> > > > > <property
> > name="password"><value>styr3ls3n</value></property>
> > > > > </bean>
> > > > >
> > > > > <!-- Hibernate SessionFactories -->
> > > > > <bean id="danafileHbmSF" class="
> > org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> > > > > <property name="dataSource"><ref
> > local="danafileHbmDS"/></property>
> > > > > <property name="mappingResources">
> > > > > <list>
> > > > >
> > 
> <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLink.hbm.xml</value>
> > > > > </list>
> > > > > </property>
> > > > > <property name="hibernateProperties">
> > > > > <props>
> > > > > <prop
> > key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
> > > > > <prop
> > key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
> > > > > <prop
> > key="hibernate.show_sql">true</prop>
> > > > > </props>
> > > > > </property>
> > > > > </bean>
> > > > >
> > > > > <!-- Transaction manager for a single Hibernate SessionFactory
> > (alternative to JTA) -->
> > > > > <bean id="transactionManager"
> > class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> > > > > <property name="sessionFactory"><ref
> > local="danafileHbmSF"/></property>
> > > > > </bean>
> > > > >
> > > > > <bean id="scanJourLinkDAO"
> > class="
> dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLinkHbmDAO
> > ">
> > > > > <property name="sessionFactory"><ref
> > local="danafileHbmSF"/></property>
> > > > > </bean>
> > > > > </beans>
> > > > >
> > > > >
> > > > > ERROR - LazyInitializationException.<init>(19) |
> > could not initialize proxy - the owning Session was closed
> > > > > org.hibernate.LazyInitializationException: could not
> > initialize proxy - the owning Session was closed
> > > > > at
> > org.hibernate.proxy.AbstractLazyInitializer.initialize(
> AbstractLazyInitializer.java
> > :53)
> > > > > at
> > org.hibernate.proxy.AbstractLazyInitializer.getImplementation(
> AbstractLazyInitializer.java:84)
> > > > > at
> > org.hibernate.proxy.CGLIBLazyInitializer.intercept(
> CGLIBLazyInitializer.java
> > :134)
> > > > > at
> > 
> dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$EnhancerByCGLIB$$c24a4569.getScanJourNumber
> (<generated>)
> > > > > at
> > sun.reflect.NativeMethodAccessorImpl.invoke0 (Native
> > Method)
> > > > > at
> > sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:39)
> > > > > at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(
> DelegatingMethodAccessorImpl.java
> > :25)
> > > > > at java.lang.reflect.Method.invoke(Method.java:585)
> > > > > at
> > org.apache.myfaces.el.PropertyResolverImpl.getProperty(
> PropertyResolverImpl.java:419)
> > > > > at
> > org.apache.myfaces.el.PropertyResolverImpl.getValue
> > (PropertyResolverImpl.java:104)
> > > > > at
> > org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(
> ELParserHelper.java:555)
> > > > > at
> > org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java
> > :145)
> > > > > at
> > org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java
> :441)
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > > --
> > >
> > > http://www.irian.at
> > > Your JSF powerhouse -
> > > JSF Trainings in English and German
> > >
> >
> >
> 
> 
> --
> 
> http://www.irian.at
> Your JSF powerhouse -
> JSF Trainings in English and German
>

Re: JSF + Spring + Hibernate

Posted by Martin Marinschek <ma...@gmail.com>.
Nice One!

regards,

Martin

On 8/31/05, Enrique Medina <e....@gmail.com> wrote:
> I also run into problems when using lazy loading due to the fact that an
> object related to my object was also lazy.
>  
>  So I solved it by extending the ListDataModel class with a callback
> mechanism that allows me to define some kind of logic in every row of the
> data table (the logic is reattaching the object to the current Hibernate
> session, of course).
>  
>  Let me show you some code:
>  
>  public class LazyListDataModel extends ListDataModel
>  {
>  
>      private DataModelCallback dataModelCallback;
>  
>      private LazyListDataModel()
>      {
>      }
>  
>      private LazyListDataModel(List list)
>      {
>      }
>  
>      public LazyListDataModel(List list, DataModelCallback
> dataModelCallback)
>      {
>          super(list);
>  
>          this.dataModelCallback = dataModelCallback;
>      }
>  
>      public Object getRowData()
>      {
>          // Get the object...
>          Object objeto = super.getRowData();
>  
>          // ...invoke the callback before returning it.
>          if (this.dataModelCallback != null)
>          {
>              this.dataModelCallback.execute(objeto);
>          }
>  
>          return objeto;
>      }
>  
>  }
>  
>  public interface DataModelCallback
>  {
>  
>      public abstract void execute(Object objeto);
>  
>  }
>  
>  Example of use:
>  
>          this.politicasDataModel = new LazyListDataModel(this
>                  .busquedaPoliticas(), new DataModelCallback()
>          {
>  
>              public void execute(Object objeto)
>              {
>                  WebappUtils.reasociarObjeto(objeto);
>              }
>          });
>  
>  and the reattachment code:
>  
>      public static void reasociarObjeto(Object objeto)
>      {
>          ((DummyDAOHibernateImpl) FacesUtils.getBean("dummyDAO"))
>                  .getHibernateTemplate().lock(objeto,
> LockMode.NONE);
>      }
>  
>  Notice that I use a dummyDAO object just to be able to use Hibernate's DAO
> support by Spring ;-)
>  
>  Also my 2 cents ;-)
> 
> 2005/8/31, Martin Marinschek <ma...@gmail.com>:
> > A very short hint from my side:
> > 
> > that exception means this object is not in the session anymore. You
> > can easily reapply it to the session by calling
> > 
> > session.update(object)
> > 
> > If you are sure that your object has not changed since it was last in 
> > the session, you can call:
> > 
> > session.lock(object, LockMode.NONE);
> > 
> > regards,
> > 
> > Martin
> > 
> > On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> > > I think before giving a short answer... I will give you a detailed 
> > > explanation via a links:
> > >
> > >
> http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate%29
> > >
> > > This small article describes exactly the problems you run into and how
> > > to solve them...
> > >
> > > Werner
> > >
> > >
> > >
> > > Rick Gruber-Riemer wrote:
> > > > Hej
> > > >
> > > > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my
> webapplication. When I get a list of records from the database in a table or
> make a new record using a form everything works fine. However when I try to
> edit a record in a form, I get a
> org.hibernate.LazyInitializationException error on opening
> the editform.
> > > > I understand this has something to do with the Hibernate sessions. And
> it has nothing to do with MyFaces in particular. And I have found some hints
> by googeling like Spring's OpenSessionInViewFilter. However I do not have a
> clue what to change where in the configuration.
> > > >
> > > > => Has somebody used JSF+Spring+Hibernate successfully?
> > > > => Downloadable sample code?
> > > > => Do I need the jsf-spring integration library? 
> > > >
> > > > Any hint would be much appreciated ... Rick
> > > >
> > > > <hibernate-mapping>
> > > >       <class
> name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink
> "
> > > >               table="DANAFILE.SCANJOUR_LINK">
> > > >               <id name="id" type="long" column="ROW_ID">
> > > >                       <meta
> attribute="scope-set">protected</meta>
> > > >                       <generator class="sequence">
> > > >                 <param name="sequence">DANAFILE.SEQNUMBER</param>
> > > >               </generator>
> > > >         </id>
> > > >               <version column="REVISION" name="revision" />
> > > >               <property name="objId" type="string" not-null="true"/>
> > > >               <property name="scanJourNumber" type="int"
> column="SCANJOUR_NUMBER" not-null="true"/>
> > > >               <property name="notes" type="string" column="NOTES"
> not-null="false"/>
> > > >               <property name="active" type="yes_no" column="ACTIVE"
> not-null="true" />
> > > >               <property name="createdBy" type="string"
> column="CREATED_BY" not-null="true"/>
> > > >               <property name="lastUpdatedBy" type="string"
> column="LAST_UPD_BY" not-null="true"/>
> > > >               <property name="createdDate" type="timestamp"
> column="CREATED_DT" not-null="true"/>
> > > >               <property name="lastUpdatedDate" type="timestamp"
> column="LAST_UPD_DT" not-null="true"/>
> > > >       </class>
> > > > </hibernate-mapping>
> > > >
> > > > <beans>
> > > >       <bean id="danafileHbmDS" class="
> oracle.jdbc.pool.OracleDataSource">
> > > >               <property
> name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
> > > >               <property
> name="URL"><value>jdbc:oracle:thin:@10.0.0.3:1521:dhdvl</value></property>
> > > >               <property
> name="user"><value>danafile_web</value></property>
> > > >               <property
> name="password"><value>styr3ls3n</value></property>
> > > >       </bean>
> > > >
> > > >       <!-- Hibernate SessionFactories -->
> > > >       <bean id="danafileHbmSF" class="
> org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> > > >               <property name="dataSource"><ref
> local="danafileHbmDS"/></property>
> > > >               <property name="mappingResources">
> > > >                       <list>
> > > >                              
> <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLink.hbm.xml</value>
> > > >                       </list>
> > > >               </property>
> > > >               <property name="hibernateProperties">
> > > >                       <props>
> > > >                               <prop
> key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
> > > >                               <prop
> key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
> > > >                               <prop
> key="hibernate.show_sql">true</prop>
> > > >                       </props>
> > > >               </property>
> > > >       </bean>
> > > >
> > > >       <!-- Transaction manager for a single Hibernate SessionFactory
> (alternative to JTA) -->
> > > >       <bean id="transactionManager"
> class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> > > >               <property name="sessionFactory"><ref
> local="danafileHbmSF"/></property>
> > > >       </bean>
> > > >
> > > >       <bean id="scanJourLinkDAO"
> class="dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLinkHbmDAO
> ">
> > > >               <property name="sessionFactory"><ref
> local="danafileHbmSF"/></property>
> > > >       </bean>
> > > > </beans>
> > > >
> > > >
> > > > ERROR - LazyInitializationException.<init>(19) |
> could not initialize proxy - the owning Session was closed 
> > > > org.hibernate.LazyInitializationException: could not
> initialize proxy - the owning Session was closed
> > > >         at
> org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java
> :53)
> > > >         at
> org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
> > > >         at
> org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java
> :134)
> > > >         at
> dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>)
> > > >         at
> sun.reflect.NativeMethodAccessorImpl.invoke0 (Native
> Method)
> > > >         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > >         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
> :25)
> > > >         at java.lang.reflect.Method.invoke(Method.java:585)
> > > >         at
> org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:419)
> > > >         at
> org.apache.myfaces.el.PropertyResolverImpl.getValue
> (PropertyResolverImpl.java:104)
> > > >         at
> org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:555)
> > > >         at
> org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java
> :145)
> > > >         at
> org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:441)
> > > >
> > > >
> > >
> > >
> > 
> > 
> > --
> > 
> > http://www.irian.at 
> > Your JSF powerhouse -
> > JSF Trainings in English and German
> > 
> 
>  


-- 

http://www.irian.at
Your JSF powerhouse - 
JSF Trainings in English and German

Re: JSF + Spring + Hibernate

Posted by Enrique Medina <e....@gmail.com>.
I also run into problems when using lazy loading due to the fact that an 
object related to my object was also lazy.

So I solved it by extending the ListDataModel class with a callback 
mechanism that allows me to define some kind of logic in every row of the 
data table (the logic is reattaching the object to the current Hibernate 
session, of course).

Let me show you some code:

public class LazyListDataModel extends ListDataModel
{

private DataModelCallback dataModelCallback;

private LazyListDataModel()
{
}

private LazyListDataModel(List list)
{
}

public LazyListDataModel(List list, DataModelCallback dataModelCallback)
{
super(list);

this.dataModelCallback = dataModelCallback;
}

public Object getRowData()
{
// Get the object...
Object objeto = super.getRowData();

// ...invoke the callback before returning it.
if (this.dataModelCallback != null)
{
this.dataModelCallback.execute(objeto);
}

return objeto;
}

}

public interface DataModelCallback
{

public abstract void execute(Object objeto);

}

Example of use:

this.politicasDataModel = new LazyListDataModel(this
.busquedaPoliticas(), new DataModelCallback()
{

public void execute(Object objeto)
{
WebappUtils.reasociarObjeto(objeto);
}
});

and the reattachment code:

public static void reasociarObjeto(Object objeto)
{
((DummyDAOHibernateImpl) FacesUtils.getBean("dummyDAO"))
.getHibernateTemplate().lock(objeto, LockMode.NONE);
}

Notice that I use a dummyDAO object just to be able to use Hibernate's DAO 
support by Spring ;-)

Also my 2 cents ;-)

2005/8/31, Martin Marinschek <ma...@gmail.com>:
> 
> A very short hint from my side:
> 
> that exception means this object is not in the session anymore. You
> can easily reapply it to the session by calling
> 
> session.update(object)
> 
> If you are sure that your object has not changed since it was last in
> the session, you can call:
> 
> session.lock(object, LockMode.NONE);
> 
> regards,
> 
> Martin
> 
> On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> > I think before giving a short answer... I will give you a detailed
> > explanation via a links:
> >
> > 
> http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate%29
> >
> > This small article describes exactly the problems you run into and how
> > to solve them...
> >
> > Werner
> >
> >
> >
> > Rick Gruber-Riemer wrote:
> > > Hej
> > >
> > > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my 
> webapplication. When I get a list of records from the database in a table or 
> make a new record using a form everything works fine. However when I try to 
> edit a record in a form, I get a org.hibernate.LazyInitializationExceptionerror on opening the editform.
> > > I understand this has something to do with the Hibernate sessions. And 
> it has nothing to do with MyFaces in particular. And I have found some hints 
> by googeling like Spring's OpenSessionInViewFilter. However I do not have a 
> clue what to change where in the configuration.
> > >
> > > => Has somebody used JSF+Spring+Hibernate successfully?
> > > => Downloadable sample code?
> > > => Do I need the jsf-spring integration library?
> > >
> > > Any hint would be much appreciated ... Rick
> > >
> > > <hibernate-mapping>
> > > <class name="
> dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink"
> > > table="DANAFILE.SCANJOUR_LINK">
> > > <id name="id" type="long" column="ROW_ID">
> > > <meta attribute="scope-set">protected</meta>
> > > <generator class="sequence">
> > > <param name="sequence">DANAFILE.SEQNUMBER</param>
> > > </generator>
> > > </id>
> > > <version column="REVISION" name="revision" />
> > > <property name="objId" type="string" not-null="true"/>
> > > <property name="scanJourNumber" type="int" column="SCANJOUR_NUMBER" 
> not-null="true"/>
> > > <property name="notes" type="string" column="NOTES" not-null="false"/>
> > > <property name="active" type="yes_no" column="ACTIVE" not-null="true" 
> />
> > > <property name="createdBy" type="string" column="CREATED_BY" 
> not-null="true"/>
> > > <property name="lastUpdatedBy" type="string" column="LAST_UPD_BY" 
> not-null="true"/>
> > > <property name="createdDate" type="timestamp" column="CREATED_DT" 
> not-null="true"/>
> > > <property name="lastUpdatedDate" type="timestamp" column="LAST_UPD_DT" 
> not-null="true"/>
> > > </class>
> > > </hibernate-mapping>
> > >
> > > <beans>
> > > <bean id="danafileHbmDS" class="oracle.jdbc.pool.OracleDataSource">
> > > <property name="driverType"><value>oracle.jdbc.OracleDriver
> </value></property>
> > > <property name="URL"><value>jdbc:oracle:thin:@10.0.0.3
> :1521:dhdvl</value></property>
> > > <property name="user"><value>danafile_web</value></property>
> > > <property name="password"><value>styr3ls3n</value></property>
> > > </bean>
> > >
> > > <!-- Hibernate SessionFactories -->
> > > <bean id="danafileHbmSF" class="
> org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> > > <property name="dataSource"><ref local="danafileHbmDS"/></property>
> > > <property name="mappingResources">
> > > <list>
> > > 
> <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLink.hbm.xml</value>
> > > </list>
> > > </property>
> > > <property name="hibernateProperties">
> > > <props>
> > > <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect
> </prop>
> > > <prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
> > > <prop key="hibernate.show_sql">true</prop>
> > > </props>
> > > </property>
> > > </bean>
> > >
> > > <!-- Transaction manager for a single Hibernate SessionFactory 
> (alternative to JTA) -->
> > > <bean id="transactionManager" class="
> org.springframework.orm.hibernate3.HibernateTransactionManager">
> > > <property name="sessionFactory"><ref 
> local="danafileHbmSF"/></property>
> > > </bean>
> > >
> > > <bean id="scanJourLinkDAO" class="
> dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLinkHbmDAO
> ">
> > > <property name="sessionFactory"><ref 
> local="danafileHbmSF"/></property>
> > > </bean>
> > > </beans>
> > >
> > >
> > > ERROR - LazyInitializationException.<init>(19) | could not initialize 
> proxy - the owning Session was closed
> > > org.hibernate.LazyInitializationException: could not initialize proxy 
> - the owning Session was closed
> > > at org.hibernate.proxy.AbstractLazyInitializer.initialize(
> AbstractLazyInitializer.java:53)
> > > at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(
> AbstractLazyInitializer.java:84)
> > > at org.hibernate.proxy.CGLIBLazyInitializer.intercept(
> CGLIBLazyInitializer.java:134)
> > > at 
> dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$EnhancerByCGLIB$$c24a4569.getScanJourNumber
> (<generated>)
> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > at sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:39)
> > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(
> DelegatingMethodAccessorImpl.java:25)
> > > at java.lang.reflect.Method.invoke(Method.java:585)
> > > at org.apache.myfaces.el.PropertyResolverImpl.getProperty(
> PropertyResolverImpl.java:419)
> > > at org.apache.myfaces.el.PropertyResolverImpl.getValue(
> PropertyResolverImpl.java:104)
> > > at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(
> ELParserHelper.java:555)
> > > at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
> > > at org.apache.myfaces.el.ValueBindingImpl.getValue(
> ValueBindingImpl.java:441)
> > >
> > >
> >
> >
> 
> 
> --
> 
> http://www.irian.at
> Your JSF powerhouse -
> JSF Trainings in English and German
>

Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Actually some valid points here, but the whole
opensessioninviewfilter technique is more like
a keep the session open as long as possible technique, so
that you do not have to care about it anywhere.

so basically what happens is following, that
normally you have the problem of keeping track of prefetching etc...
and often the session handling on dao level,
now the session handling is moved into the request cycle and now should 
be fully transparent to the user (not allways but often enough)

the benefit you get from this, is that you do not run into the lazy 
loading issues as often as with small dedicated sessions...

So what happens if you move lets say from Hibernate to plain JDBC...
you simple remove the opensessioninview filter
and from the outside you handle the pojos the same, all which happens is
that you replace lots of lazy loaded classes and some dao code with
the same classes prefilled from the jdbc connection...

the OpenSessionInView filter basically just eases the pain of having to 
keep track of lazily loaded classes in many instances (not in all)
but besides that is rather transparent to the implementation if done well...

I wil give you an example....

without OpenSessionInView...

load some person classes

getHibernateTemplate().load(Person.class, id);

with OpenSessionInView

getHibernateTemplate().load(Person.class, id);


the main difference is, that if person in the first case references 
another bunch of lazy objects
like:
person.getAddress().getStreetName()...
you might get an error while rendering the data or doing something with it


in the second case you wont get the error, because the lazy loading 
still can be done due to the open session.

ideal would be to have some kind of session per session filter
but in most circumstances that is not possible, so opensessioninview
is the second best choice you can get.



Werner




Ken Weiner wrote:
> I have a question about designing a webapp to use a DAO layer, lazily 
> loaded objects, Hibernate, and the OpenSessionInView technique.
> 
> Doesn't this strategy make it very difficult to reimplement the DAO 
> layer sometime in the future?  If you switched a DAO implementation from 
> Hibernate to let's say, Spring JDBC, then how would all the lazy loading 
> work?  There would be no equivalent OpenSessionInView technique for 
> Spring JDBC.  For this reason, I have been shying away from designing my 
> domain objects such that the rest of the app expects them to lazily load 
> data.
> 
> So, instead of a Company class having a getEmployees() method, I would 
> choose, instead, to have a CompanyDao.getEmployees(Company company) 
> method that must be called at the point my webapp needs all the 
> Employees for a Company.
> 
> Have any of you had the same concerns?  Or am I missing how a webapp 
> that relies on lazy-loaded object graphs can change DAO implementations 
> easily?
> 
> -Ken


Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
No you are definitely right, having a few automatically mapped beans
is much better, one reasony why I use hibernate, but mapping objects
add an additional coding effort to the mix which cannot be underestimated...

Although mapping objects in my opinion are the cleanest way to bypass 
the hibernate session problem, but they should not be needed...

Werner


Joshua Davis wrote:
>  
> 
> 
>>-----Original Message-----
>>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
>>Sent: Thursday, September 01, 2005 4:29 AM
>>To: users@myfaces.apache.org
>>Subject: Re: JSF + Spring + Hibernate
>>
>>
>>>The point is (if I understand the Transfer Object stuff correctly) 
>>>that transfer objects arent a good solution.
>>>
>>
>>In my opinion no, because once things get more complicated 
>>(some relational stuff etc...) you run into myriads of 
>>problems which you have to handcode, which you probably could 
>>avoid if you just use the pojos from the db....
>>
>>Doing a transfer object means, either flat out the data, or 
>>also transfer the relational data into other transfer objects...
>>you end up basically with twice the work, and not really a 
>>timesaving to plain jdbc... access or a rather simple direct 
>>table to object mapper.
> 
> 
> Maybe it's just my opinion, but I'd rather make a few simple java beans than
> deal with lots of JDBC code that is completely locked in to a particular DB
> vendor.  But... To each his own.  Use what works for you. :)
> 
> Heck, I liked Hibernate so much I joined the project!  So perhaps my opinion
> is biased. ;)
> 
> joshua@hibernate.org
> 
> 
> 


Re: JSF + Spring + Hibernate

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
>>
>> The point is (if I understand the Transfer Object stuff correctly) 
>> that transfer objects arent a good solution.
>>
> In my opinion no, because once things get more complicated (some 
> relational stuff etc...) you run into myriads of problems which you 
> have to handcode, which you probably could avoid if you just use the 
> pojos from the db....
But this is what I wrote - at least I tried it ;-) - transfer objects 
ARE NOT a good solution.


---
Mario


RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
 

> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
> Sent: Thursday, September 01, 2005 4:29 AM
> To: users@myfaces.apache.org
> Subject: Re: JSF + Spring + Hibernate
> 
> > The point is (if I understand the Transfer Object stuff correctly) 
> > that transfer objects arent a good solution.
> > 
> In my opinion no, because once things get more complicated 
> (some relational stuff etc...) you run into myriads of 
> problems which you have to handcode, which you probably could 
> avoid if you just use the pojos from the db....
> 
> Doing a transfer object means, either flat out the data, or 
> also transfer the relational data into other transfer objects...
> you end up basically with twice the work, and not really a 
> timesaving to plain jdbc... access or a rather simple direct 
> table to object mapper.

Maybe it's just my opinion, but I'd rather make a few simple java beans than
deal with lots of JDBC code that is completely locked in to a particular DB
vendor.  But... To each his own.  Use what works for you. :)

Heck, I liked Hibernate so much I joined the project!  So perhaps my opinion
is biased. ;)

joshua@hibernate.org



Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Mario Ivankovits wrote:
> Werner Punz wrote:
> 
>>>> To me, it makes sense to use Transfer Objects,
>>>>  
>>>
>>> * How do you deal with versioning?
>>
>> To enable versioning, you have to set a version field in your table,
>> I tried that approach with my last JSF project, it works like a charm...
> 
> I know this, and I use it myself already.
> 
> The question is what if one use "Transfer Objects" they are detached 
> from the hibernate object itself, arent they?
> 
> So the workflow with transfer objects is:
> 
> * DAO->hibernate->Transfer Object
> * request,response
> * reload hibernate object from database and apply the transfer object 
> values on it
> 
> If you use this scheme, your are not able to rely on hibernates 
> versioning as you always load the current version of the object from the 
> database and override its values.
> 

not if you transfer the versioning data as well...



> 
> The point is (if I understand the Transfer Object stuff correctly) that 
> transfer objects arent a good solution.
> 
In my opinion no, because once things get more complicated (some 
relational stuff etc...) you run into myriads of problems which you have 
to handcode, which you probably could avoid if you just use the pojos 
from the db....

Doing a transfer object means, either flat out the data, or also 
transfer the relational data into other transfer objects...
you end up basically with twice the work, and not really a timesaving to
plain jdbc... access or a rather simple direct table to object mapper.


Re: JSF + Spring + Hibernate

Posted by Mario Ivankovits <ma...@ops.co.at>.
Werner Punz wrote:
>>> To me, it makes sense to use Transfer Objects,
>>>  
>> * How do you deal with versioning?
> To enable versioning, you have to set a version field in your table,
> I tried that approach with my last JSF project, it works like a charm...
I know this, and I use it myself already.

The question is what if one use "Transfer Objects" they are detached 
from the hibernate object itself, arent they?

So the workflow with transfer objects is:

* DAO->hibernate->Transfer Object
* request,response
* reload hibernate object from database and apply the transfer object 
values on it

If you use this scheme, your are not able to rely on hibernates 
versioning as you always load the current version of the object from the 
database and override its values.


The point is (if I understand the Transfer Object stuff correctly) that 
transfer objects arent a good solution.

Ciao,
Mario


Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Mario Ivankovits wrote:
> Hi!
> 
>> To me, it makes sense to use Transfer Objects,
>>  
> 
> * How do you deal with versioning?
> 
> If you directly use the hibernate object and use lock() to reassociate 
> it you can use hibernates versioning check to see if another
> user already changed this object too and can tell the user its change is 
> no longer valid.
> 

Works only if you  have not changed the data in between...
But update also cries if the data has been altered...

To enable versioning, you have to set a version field in your table,
I tried that approach with my last JSF project, it works like a charm...

The flow sort of was like this...

Version field..  let hibernate do the version checking
hibernate throws an exception... push the exception through the spring 
layer, let a dedicated interceptor (a spring AOP construct would be 
possible) deal with the error in a standardized way and push the error 
message to the user interface layer...

That way you simply have a good error handling as long as you use a 
BO/DAO approach with automated error message feedback.
The ideal case would be to weave that stuff via aspects directly over 
the BOs/DAOs and dont code anything yourself in that area....

JSF enforces that pattern because you can set the error messages over 
singleton/factory constructs, which are theoretically accessible from 
any layer, and from any interceptor class. With Struts it was much 
harder to do that, in the end I had to move the error interceptor doing 
that stuff into a base supporting class which basically was woven around 
the Struts Actions execute method. One of the areas, where I really 
prefer JSF over Struts, at first it looked weird to have everything 
accessible over a central Singleton/Factoriy but the deeper you dive 
into such things, the more you see that those things make a lot of sense.






RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
It just seemed to me like we were talking more about using Hibernate in a
web container than about JSF/MyFaces.  I thought the Hibernate user
community might benefit from the conversation. 

But... If the MyFaces community doesn't mind, it's fine with me to leave the
thread here.

> -----Original Message-----
> From: Mario Ivankovits [mailto:mario@ops.co.at] 
> Sent: Thursday, September 01, 2005 6:17 AM
> To: MyFaces Discussion
> Subject: Re: JSF + Spring + Hibernate
> 
> Joshua Davis wrote:
> >Perhaps we should move this conversation to the Hibernate forum?
> >  
> Why do you think this would be a better place?
> 
> 
> ---
> Mario
> 
> 



Re: JSF + Spring + Hibernate

Posted by Mario Ivankovits <ma...@ops.co.at>.
Joshua Davis wrote:
>Perhaps we should move this conversation to the Hibernate forum?
>  
Why do you think this would be a better place?


---
Mario


RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
Perhaps we should move this conversation to the Hibernate forum?

joshua@hibernate.org 

> -----Original Message-----
> From: Mario Ivankovits [mailto:mario@ops.co.at] 
> Sent: Thursday, September 01, 2005 1:54 AM
> To: MyFaces Discussion
> Subject: Re: JSF + Spring + Hibernate
> 
> Hi!
> >To me, it makes sense to use Transfer Objects,
> >  
> * How do you deal with versioning?
> 
> If you directly use the hibernate object and use lock() to 
> reassociate it you can use hibernates versioning check to see 
> if another user already changed this object too and can tell 
> the user its change is no longer valid.
> 
> You might have to do this yourself if you detach your object 
> into a transfer object, dont you?
> 
> 
> * How do you know which fields in your transfer object have changed?
> 
> You can use aspectj or simply booleans, but this also sound a 
> little bit 
> of duplicate programming with respect to hibernate which 
> already handles it.
> 
> 
> I am fully convinced it is best to reload hibernate objects 
> and utilize 
> the second level cache where possible, but when it comes to 
> "data change 
> forms" (user loads a record/edit it/save it some times later) 
> its better 
> to use a "page scoped" hibernate object.
> So in fact it would be great to have a method to reattach 
> those objects 
> before any other action will be executed.
> 
> What I would try is to give my hibernate object a marker interface 
> "PersistentObject" and create a converter for it. So x:saveState use 
> this converter and on recreation of this object it should be 
> possible to 
> reattach it. If it is a stale object a custom error page can 
> be displayed.
> 
> 
> ---
> Mario
> 
> 



Re: JSF + Spring + Hibernate

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
>To me, it makes sense to use Transfer Objects,
>  
* How do you deal with versioning?

If you directly use the hibernate object and use lock() to reassociate 
it you can use hibernates versioning check to see if another
user already changed this object too and can tell the user its change is 
no longer valid.

You might have to do this yourself if you detach your object into a 
transfer object, dont you?


* How do you know which fields in your transfer object have changed?

You can use aspectj or simply booleans, but this also sound a little bit 
of duplicate programming with respect to hibernate which already handles it.


I am fully convinced it is best to reload hibernate objects and utilize 
the second level cache where possible, but when it comes to "data change 
forms" (user loads a record/edit it/save it some times later) its better 
to use a "page scoped" hibernate object.
So in fact it would be great to have a method to reattach those objects 
before any other action will be executed.

What I would try is to give my hibernate object a marker interface 
"PersistentObject" and create a converter for it. So x:saveState use 
this converter and on recreation of this object it should be possible to 
reattach it. If it is a stale object a custom error page can be displayed.


---
Mario


Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Joshua Davis wrote:

> RE: the m:n problem, I imagine the design of the
> backing beans and DAOs (and transfer objects, in my
> case ;) )  would depend on the UI.   When you say m:n,
> you mean many-to-many, right?  What would be a good
> example UI design for managing a m:n relationship?
> 
Well the best option I found so far was to set
the relation in a tabbed pane and use ajax with
a popup window for editing deleting and adding...
with a save in the end...

ajax for refreshing without having to go the roundtrip cycle...

optionally if you can bypass the validation you can do the same without 
ajax with a normal refresh of the form
(the ajax helped me not to refresh the entire form just the subpanel)

another option if the program permits it is to set a link to the 
relational data from a master view that way you can do the relational 
data like you would do normal data...

the third option is to handle the relational data entirely in a popup 
reachable from the master form.


Re: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
Well, the free documentation is kind of terse.   I
read slowly, so I like that. :)

I'm working on a simple example with just Hibernate
and JSF as a way to learn JSF (which is involving some
of my own head banging, but that's just me being a JSF
newbie).   I'll probably post my JSF/Hibernate session
management example to my blog at some point.  

RE: the m:n problem, I imagine the design of the
backing beans and DAOs (and transfer objects, in my
case ;) )  would depend on the UI.   When you say m:n,
you mean many-to-many, right?  What would be a good
example UI design for managing a m:n relationship?

--- Werner Punz <we...@gmx.at> wrote:

> Ah no need for excuse, I value Hibernate
> as what it is, one of the best orm solutions in
> existence,
> the head banging is mostly a documentation problem.
> 
> 
> Actually, I think the main problem is, that there is
> no real page
> with code templates for standard situations in a
> webcentric manner,
> which would resolve those issues to 90%
> 
> I will give you an example, you have the classical
> m:n situation in a 
> webcentric manner,
> you want to add form data, the classical error you
> run into, is that you 
> have some form data traversed over the session
> boundary, and
> you want to set the m:n relational data to the new
> state...
> 
> Hibernate has some examples on how to deal with m:n
> relations
> (basically dump the relation and set it anew)
> now you have the classical situation you load one
> side of the relation
> you set rootboject.getRelset().clear();
> update(rootboject)
> 
> and you nail the external data in...
> now you get the error, object has been reused in the
> session
> because the old relational objects are still in
> there.
> 
> I tried in hibernate 2 at such as stage a session
> clear()
> that did not work, with no indications why (probably
> a mixtore on non 
> lazy and garbage collection)...
> So I reverted to mapping objects, to get the work up
> and running.
> 
> I am not sure how to resolve such an issue in a
> decent manner,
> probably by saving the relational data on the n side
> first
> and then breaking up the relation and setting it
> anew, that way
> hibernate should use the incoming data first...
> 
> but the ideal case would be to just dump the pojos
> in the relation
> and have hibernate figure out, that those pojos come
> from the outside
> and basically are new values...
> 
> What is needed is additional documentation for such
> cases...
> especially once you have to deal with one to many,
> many-to many stuff
> in a webcentric context, things can become really
> messy....
> 
> 
> 
> Werner
> 
> Joshua Davis wrote:
> > Sorry 'bout the head banging! :(  If there's
> anything I can do to help, let
> > me know.
> > 
> > You are absolutely, positively 100% correct about
> 'getting a grip' on
> > Hibernate.
> > 
> > It's actually more fundamental than that: You need
> to have a good
> > understanding of ORM in general in order to use
> Hibernate (or EJB Entities,
> > or TOPLink, etc.) effectively.  For me,
> understanding ORM was a 'leap' that
> > was similar to when I went from structured
> programming to OOP.
> > 
> > joshua@hibernate.org
> > 
> > 
> 
> 


Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Ah no need for excuse, I value Hibernate
as what it is, one of the best orm solutions in existence,
the head banging is mostly a documentation problem.


Actually, I think the main problem is, that there is no real page
with code templates for standard situations in a webcentric manner,
which would resolve those issues to 90%

I will give you an example, you have the classical m:n situation in a 
webcentric manner,
you want to add form data, the classical error you run into, is that you 
have some form data traversed over the session boundary, and
you want to set the m:n relational data to the new state...

Hibernate has some examples on how to deal with m:n relations
(basically dump the relation and set it anew)
now you have the classical situation you load one side of the relation
you set rootboject.getRelset().clear();
update(rootboject)

and you nail the external data in...
now you get the error, object has been reused in the session
because the old relational objects are still in there.

I tried in hibernate 2 at such as stage a session clear()
that did not work, with no indications why (probably a mixtore on non 
lazy and garbage collection)...
So I reverted to mapping objects, to get the work up and running.

I am not sure how to resolve such an issue in a decent manner,
probably by saving the relational data on the n side first
and then breaking up the relation and setting it anew, that way
hibernate should use the incoming data first...

but the ideal case would be to just dump the pojos in the relation
and have hibernate figure out, that those pojos come from the outside
and basically are new values...

What is needed is additional documentation for such cases...
especially once you have to deal with one to many, many-to many stuff
in a webcentric context, things can become really messy....



Werner

Joshua Davis wrote:
> Sorry 'bout the head banging! :(  If there's anything I can do to help, let
> me know.
> 
> You are absolutely, positively 100% correct about 'getting a grip' on
> Hibernate.
> 
> It's actually more fundamental than that: You need to have a good
> understanding of ORM in general in order to use Hibernate (or EJB Entities,
> or TOPLink, etc.) effectively.  For me, understanding ORM was a 'leap' that
> was similar to when I went from structured programming to OOP.
> 
> joshua@hibernate.org
> 
> 


Re: JSF + Spring + Hibernate

Posted by David Haynes <da...@sympatico.ca>.
Thank you for contributing nothing to the discussion.

Rob Decker wrote:

>Reading is good...let me know when you find the book that tells you how to
>start with the correct model. I definitely want to get a copy ;)
>
>Rob
>
>@objectsource.org
>
>
>----- Original Message ----- 
>From: "David Haynes" <da...@sympatico.ca>
>To: "MyFaces Discussion" <us...@myfaces.apache.org>
>Sent: Thursday, September 01, 2005 9:32 AM
>Subject: Re: JSF + Spring + Hibernate
>
>
>  
>
>>Well, there was no smiley on this, so I will assume you are serious in
>>your question.
>>
>>This may have been true for Thomas Edison, but I don't think you went
>>out and tried to build your own light bulb. Even if you did, you would
>>use the knowledge that you observed from looking at Edison's working
>>version (and via the patent would be able to see how Edison's worked).
>>
>>I don't claim to be an Edison, but I can learn from them instead of
>>starting with first principles every time. There is a book series called
>>"Think in Java" that doesn't spend a lot of time documenting every
>>feature of the Java language but, instead, talks about how to think
>>about your problem in terms of the Java programming model. What I was
>>expressing was my desire for something similar for data-coupled web
>>applications.
>>
>>-david-
>>
>>Rob Decker wrote:
>>
>>    
>>
>>>What makes you think you start with the correct model? You have to be
>>>      
>>>
>able
>  
>
>>>to create 2000 incorrect models; then you can create the correct one.
>>>      
>>>
>Just
>  
>
>>>ask Thomas Edison.
>>>
>>>
>>>Rob
>>>
>>>@objectsource.org
>>>
>>>----- Original Message ----- 
>>>From: "David Haynes" <da...@sympatico.ca>
>>>To: "MyFaces Discussion" <us...@myfaces.apache.org>
>>>Sent: Thursday, September 01, 2005 9:00 AM
>>>Subject: Re: JSF + Spring + Hibernate
>>>
>>>
>>>
>>>
>>>      
>>>
>>>>I'm going through that phase now waiting for the epiphany to strike...
>>>>
>>>>What I would really like is an article about thinking in ORM (ala
>>>>Hibernate or EJB) that doesn't talk about how the APIs are put together
>>>>but, instead, deals with concepts like: this is how to think about
>>>>modeling in ORM, this is how to structure stuff in Hibernate for a
>>>>data-backed bean, or this is how to set up your source area to make all
>>>>this a little clearer. A diagrammatic modeling method would also be of
>>>>great value. Heck, even a suggested naming practice would be nice! Is
>>>>that XxxAction, XxxController, XxxBean, XxxBackingBean, XxxModel,
>>>>XxxDAO, etc.?
>>>>
>>>>Maybe I'm being a little selfish, but it seems to me that the majority
>>>>of postings about backing-store issues are from poor sods such as myself
>>>>who are trying to simply create data-coupled web applications that won't
>>>>fall apart with the first change. (i.e. that use well structured
>>>>toolkits to assist). With all the options that are available, it is
>>>>difficult to get one scenario working, let alone being able to compare
>>>>solutions in some meaningful way. Every time an issue comes up, the
>>>>answer seems to be to add another software layer, from another
>>>>development group, with another model/philosophy for how the solution
>>>>should be coded. Having reference implementations helps to some degree,
>>>>but if you are missing the fundamental concepts, the reference
>>>>implementations can end up being confusing since they tend to highlight
>>>>the differences/features of the particular implementation over the
>>>>competition. Even the books with implementations in them tend to dive
>>>>directly into the code without addressing the modeling aspect and the
>>>>thinking that goes into creating the correct model to begin with.
>>>>
>>>>-david-
>>>>
>>>>Joshua Davis wrote:
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>Sorry 'bout the head banging! :(  If there's anything I can do to help,
>>>>>
>>>>>
>>>>>          
>>>>>
>>>let
>>>
>>>
>>>      
>>>
>>>>>me know.
>>>>>
>>>>>You are absolutely, positively 100% correct about 'getting a grip' on
>>>>>Hibernate.
>>>>>
>>>>>It's actually more fundamental than that: You need to have a good
>>>>>understanding of ORM in general in order to use Hibernate (or EJB
>>>>>
>>>>>
>>>>>          
>>>>>
>>>Entities,
>>>
>>>
>>>      
>>>
>>>>>or TOPLink, etc.) effectively.  For me, understanding ORM was a 'leap'
>>>>>
>>>>>
>>>>>          
>>>>>
>>>that
>>>
>>>
>>>      
>>>
>>>>>was similar to when I went from structured programming to OOP.
>>>>>
>>>>>joshua@hibernate.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>>>-----Original Message-----
>>>>>>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
>>>>>>Sent: Thursday, September 01, 2005 3:56 AM
>>>>>>To: users@myfaces.apache.org
>>>>>>Subject: Re: JSF + Spring + Hibernate
>>>>>>
>>>>>>One of the reasons why I am not that much a friend of
>>>>>>Hibernate anymore.
>>>>>>I did 4 projects with it, and the problems always were the same...
>>>>>>Overkill in mapping details, Session handling and choking on
>>>>>>pojos in which made things more complicated than they should
>>>>>>be, failurs in dependency resolution on write over more
>>>>>>complicated data structures, which then had to be resolved manually...
>>>>>>
>>>>>>Constant banging the heads on small stuff, like having a
>>>>>>clean and proper way to resolve m:n issues. Sometimes there
>>>>>>are errors where Hibernate simply does nothing but does not
>>>>>>even throw errors.
>>>>>>
>>>>>>Dont get me wrong, Hibernate is an excellent tool, and
>>>>>>basically has solved most of not all issues you constantly
>>>>>>run into with Object Relational mappins and OODBs, but it is
>>>>>>options overkill and definitely not easy to handle.
>>>>>>I am not sure which is more complicated the EJB approach or
>>>>>>the options overkill in Hibernate, which does not force you
>>>>>>into anything, but often simply fails with leaving you
>>>>>>standing in the rain.
>>>>>>
>>>>>>My opinion is, there must be some kind of middle way, to give
>>>>>>you enough flexibility but does not push you into such a huge
>>>>>>complex layer, Hibernate has evolved into, also 90% of the
>>>>>>main problem you constantly have with hibernate is the
>>>>>>complicated way the session handles the pojos... Dump the
>>>>>>wrong pojo into the session and you get a object has been
>>>>>>used failure.... Run out of the session hibernate chokes on
>>>>>>lazy access instead of trying to resolve the problem by
>>>>>>opening another one and trying to load the rest automatically...
>>>>>>
>>>>>>I would say, Hibernate is the worst/best working solution you
>>>>>>can get from OSS in regards to ORM mapping, but one thing is
>>>>>>for sure, it made things definitely not easier, although if
>>>>>>you have a grip on it, you can save a lot of time, but
>>>>>>aquiring the grip is a hard task, even with the excellent docs.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>        
>>>>
>>>
>>>
>>>      
>>>
>>    
>>
>
>
>  
>



Re: JSF + Spring + Hibernate

Posted by Rob Decker <ro...@objectsource.org>.
Reading is good...let me know when you find the book that tells you how to
start with the correct model. I definitely want to get a copy ;)

Rob

@objectsource.org


----- Original Message ----- 
From: "David Haynes" <da...@sympatico.ca>
To: "MyFaces Discussion" <us...@myfaces.apache.org>
Sent: Thursday, September 01, 2005 9:32 AM
Subject: Re: JSF + Spring + Hibernate


> Well, there was no smiley on this, so I will assume you are serious in
> your question.
>
> This may have been true for Thomas Edison, but I don't think you went
> out and tried to build your own light bulb. Even if you did, you would
> use the knowledge that you observed from looking at Edison's working
> version (and via the patent would be able to see how Edison's worked).
>
> I don't claim to be an Edison, but I can learn from them instead of
> starting with first principles every time. There is a book series called
> "Think in Java" that doesn't spend a lot of time documenting every
> feature of the Java language but, instead, talks about how to think
> about your problem in terms of the Java programming model. What I was
> expressing was my desire for something similar for data-coupled web
> applications.
>
> -david-
>
> Rob Decker wrote:
>
> >What makes you think you start with the correct model? You have to be
able
> >to create 2000 incorrect models; then you can create the correct one.
Just
> >ask Thomas Edison.
> >
> >
> >Rob
> >
> >@objectsource.org
> >
> >----- Original Message ----- 
> >From: "David Haynes" <da...@sympatico.ca>
> >To: "MyFaces Discussion" <us...@myfaces.apache.org>
> >Sent: Thursday, September 01, 2005 9:00 AM
> >Subject: Re: JSF + Spring + Hibernate
> >
> >
> >
> >
> >>I'm going through that phase now waiting for the epiphany to strike...
> >>
> >>What I would really like is an article about thinking in ORM (ala
> >>Hibernate or EJB) that doesn't talk about how the APIs are put together
> >>but, instead, deals with concepts like: this is how to think about
> >>modeling in ORM, this is how to structure stuff in Hibernate for a
> >>data-backed bean, or this is how to set up your source area to make all
> >>this a little clearer. A diagrammatic modeling method would also be of
> >>great value. Heck, even a suggested naming practice would be nice! Is
> >>that XxxAction, XxxController, XxxBean, XxxBackingBean, XxxModel,
> >>XxxDAO, etc.?
> >>
> >>Maybe I'm being a little selfish, but it seems to me that the majority
> >>of postings about backing-store issues are from poor sods such as myself
> >>who are trying to simply create data-coupled web applications that won't
> >>fall apart with the first change. (i.e. that use well structured
> >>toolkits to assist). With all the options that are available, it is
> >>difficult to get one scenario working, let alone being able to compare
> >>solutions in some meaningful way. Every time an issue comes up, the
> >>answer seems to be to add another software layer, from another
> >>development group, with another model/philosophy for how the solution
> >>should be coded. Having reference implementations helps to some degree,
> >>but if you are missing the fundamental concepts, the reference
> >>implementations can end up being confusing since they tend to highlight
> >>the differences/features of the particular implementation over the
> >>competition. Even the books with implementations in them tend to dive
> >>directly into the code without addressing the modeling aspect and the
> >>thinking that goes into creating the correct model to begin with.
> >>
> >>-david-
> >>
> >>Joshua Davis wrote:
> >>
> >>
> >>
> >>>Sorry 'bout the head banging! :(  If there's anything I can do to help,
> >>>
> >>>
> >let
> >
> >
> >>>me know.
> >>>
> >>>You are absolutely, positively 100% correct about 'getting a grip' on
> >>>Hibernate.
> >>>
> >>>It's actually more fundamental than that: You need to have a good
> >>>understanding of ORM in general in order to use Hibernate (or EJB
> >>>
> >>>
> >Entities,
> >
> >
> >>>or TOPLink, etc.) effectively.  For me, understanding ORM was a 'leap'
> >>>
> >>>
> >that
> >
> >
> >>>was similar to when I went from structured programming to OOP.
> >>>
> >>>joshua@hibernate.org
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>>-----Original Message-----
> >>>>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
> >>>>Sent: Thursday, September 01, 2005 3:56 AM
> >>>>To: users@myfaces.apache.org
> >>>>Subject: Re: JSF + Spring + Hibernate
> >>>>
> >>>>One of the reasons why I am not that much a friend of
> >>>>Hibernate anymore.
> >>>>I did 4 projects with it, and the problems always were the same...
> >>>>Overkill in mapping details, Session handling and choking on
> >>>>pojos in which made things more complicated than they should
> >>>>be, failurs in dependency resolution on write over more
> >>>>complicated data structures, which then had to be resolved manually...
> >>>>
> >>>>Constant banging the heads on small stuff, like having a
> >>>>clean and proper way to resolve m:n issues. Sometimes there
> >>>>are errors where Hibernate simply does nothing but does not
> >>>>even throw errors.
> >>>>
> >>>>Dont get me wrong, Hibernate is an excellent tool, and
> >>>>basically has solved most of not all issues you constantly
> >>>>run into with Object Relational mappins and OODBs, but it is
> >>>>options overkill and definitely not easy to handle.
> >>>>I am not sure which is more complicated the EJB approach or
> >>>>the options overkill in Hibernate, which does not force you
> >>>>into anything, but often simply fails with leaving you
> >>>>standing in the rain.
> >>>>
> >>>>My opinion is, there must be some kind of middle way, to give
> >>>>you enough flexibility but does not push you into such a huge
> >>>>complex layer, Hibernate has evolved into, also 90% of the
> >>>>main problem you constantly have with hibernate is the
> >>>>complicated way the session handles the pojos... Dump the
> >>>>wrong pojo into the session and you get a object has been
> >>>>used failure.... Run out of the session hibernate chokes on
> >>>>lazy access instead of trying to resolve the problem by
> >>>>opening another one and trying to load the rest automatically...
> >>>>
> >>>>I would say, Hibernate is the worst/best working solution you
> >>>>can get from OSS in regards to ORM mapping, but one thing is
> >>>>for sure, it made things definitely not easier, although if
> >>>>you have a grip on it, you can save a lot of time, but
> >>>>aquiring the grip is a hard task, even with the excellent docs.
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >
> >
> >
> >
>
>


Re: JSF + Spring + Hibernate

Posted by David Haynes <da...@sympatico.ca>.
Well, there was no smiley on this, so I will assume you are serious in 
your question.

This may have been true for Thomas Edison, but I don't think you went 
out and tried to build your own light bulb. Even if you did, you would 
use the knowledge that you observed from looking at Edison's working 
version (and via the patent would be able to see how Edison's worked).

I don't claim to be an Edison, but I can learn from them instead of 
starting with first principles every time. There is a book series called 
"Think in Java" that doesn't spend a lot of time documenting every 
feature of the Java language but, instead, talks about how to think 
about your problem in terms of the Java programming model. What I was 
expressing was my desire for something similar for data-coupled web 
applications.

-david-

Rob Decker wrote:

>What makes you think you start with the correct model? You have to be able
>to create 2000 incorrect models; then you can create the correct one. Just
>ask Thomas Edison.
>
>
>Rob
>
>@objectsource.org
>
>----- Original Message ----- 
>From: "David Haynes" <da...@sympatico.ca>
>To: "MyFaces Discussion" <us...@myfaces.apache.org>
>Sent: Thursday, September 01, 2005 9:00 AM
>Subject: Re: JSF + Spring + Hibernate
>
>
>  
>
>>I'm going through that phase now waiting for the epiphany to strike...
>>
>>What I would really like is an article about thinking in ORM (ala
>>Hibernate or EJB) that doesn't talk about how the APIs are put together
>>but, instead, deals with concepts like: this is how to think about
>>modeling in ORM, this is how to structure stuff in Hibernate for a
>>data-backed bean, or this is how to set up your source area to make all
>>this a little clearer. A diagrammatic modeling method would also be of
>>great value. Heck, even a suggested naming practice would be nice! Is
>>that XxxAction, XxxController, XxxBean, XxxBackingBean, XxxModel,
>>XxxDAO, etc.?
>>
>>Maybe I'm being a little selfish, but it seems to me that the majority
>>of postings about backing-store issues are from poor sods such as myself
>>who are trying to simply create data-coupled web applications that won't
>>fall apart with the first change. (i.e. that use well structured
>>toolkits to assist). With all the options that are available, it is
>>difficult to get one scenario working, let alone being able to compare
>>solutions in some meaningful way. Every time an issue comes up, the
>>answer seems to be to add another software layer, from another
>>development group, with another model/philosophy for how the solution
>>should be coded. Having reference implementations helps to some degree,
>>but if you are missing the fundamental concepts, the reference
>>implementations can end up being confusing since they tend to highlight
>>the differences/features of the particular implementation over the
>>competition. Even the books with implementations in them tend to dive
>>directly into the code without addressing the modeling aspect and the
>>thinking that goes into creating the correct model to begin with.
>>
>>-david-
>>
>>Joshua Davis wrote:
>>
>>    
>>
>>>Sorry 'bout the head banging! :(  If there's anything I can do to help,
>>>      
>>>
>let
>  
>
>>>me know.
>>>
>>>You are absolutely, positively 100% correct about 'getting a grip' on
>>>Hibernate.
>>>
>>>It's actually more fundamental than that: You need to have a good
>>>understanding of ORM in general in order to use Hibernate (or EJB
>>>      
>>>
>Entities,
>  
>
>>>or TOPLink, etc.) effectively.  For me, understanding ORM was a 'leap'
>>>      
>>>
>that
>  
>
>>>was similar to when I went from structured programming to OOP.
>>>
>>>joshua@hibernate.org
>>>
>>>
>>>
>>>      
>>>
>>>>-----Original Message-----
>>>>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
>>>>Sent: Thursday, September 01, 2005 3:56 AM
>>>>To: users@myfaces.apache.org
>>>>Subject: Re: JSF + Spring + Hibernate
>>>>
>>>>One of the reasons why I am not that much a friend of
>>>>Hibernate anymore.
>>>>I did 4 projects with it, and the problems always were the same...
>>>>Overkill in mapping details, Session handling and choking on
>>>>pojos in which made things more complicated than they should
>>>>be, failurs in dependency resolution on write over more
>>>>complicated data structures, which then had to be resolved manually...
>>>>
>>>>Constant banging the heads on small stuff, like having a
>>>>clean and proper way to resolve m:n issues. Sometimes there
>>>>are errors where Hibernate simply does nothing but does not
>>>>even throw errors.
>>>>
>>>>Dont get me wrong, Hibernate is an excellent tool, and
>>>>basically has solved most of not all issues you constantly
>>>>run into with Object Relational mappins and OODBs, but it is
>>>>options overkill and definitely not easy to handle.
>>>>I am not sure which is more complicated the EJB approach or
>>>>the options overkill in Hibernate, which does not force you
>>>>into anything, but often simply fails with leaving you
>>>>standing in the rain.
>>>>
>>>>My opinion is, there must be some kind of middle way, to give
>>>>you enough flexibility but does not push you into such a huge
>>>>complex layer, Hibernate has evolved into, also 90% of the
>>>>main problem you constantly have with hibernate is the
>>>>complicated way the session handles the pojos... Dump the
>>>>wrong pojo into the session and you get a object has been
>>>>used failure.... Run out of the session hibernate chokes on
>>>>lazy access instead of trying to resolve the problem by
>>>>opening another one and trying to load the rest automatically...
>>>>
>>>>I would say, Hibernate is the worst/best working solution you
>>>>can get from OSS in regards to ORM mapping, but one thing is
>>>>for sure, it made things definitely not easier, although if
>>>>you have a grip on it, you can save a lot of time, but
>>>>aquiring the grip is a hard task, even with the excellent docs.
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>
>>>
>>>
>>>      
>>>
>>    
>>
>
>
>  
>



Re: JSF + Spring + Hibernate

Posted by Rob Decker <ro...@objectsource.org>.
What makes you think you start with the correct model? You have to be able
to create 2000 incorrect models; then you can create the correct one. Just
ask Thomas Edison.


Rob

@objectsource.org

----- Original Message ----- 
From: "David Haynes" <da...@sympatico.ca>
To: "MyFaces Discussion" <us...@myfaces.apache.org>
Sent: Thursday, September 01, 2005 9:00 AM
Subject: Re: JSF + Spring + Hibernate


> I'm going through that phase now waiting for the epiphany to strike...
>
> What I would really like is an article about thinking in ORM (ala
> Hibernate or EJB) that doesn't talk about how the APIs are put together
> but, instead, deals with concepts like: this is how to think about
> modeling in ORM, this is how to structure stuff in Hibernate for a
> data-backed bean, or this is how to set up your source area to make all
> this a little clearer. A diagrammatic modeling method would also be of
> great value. Heck, even a suggested naming practice would be nice! Is
> that XxxAction, XxxController, XxxBean, XxxBackingBean, XxxModel,
> XxxDAO, etc.?
>
> Maybe I'm being a little selfish, but it seems to me that the majority
> of postings about backing-store issues are from poor sods such as myself
> who are trying to simply create data-coupled web applications that won't
> fall apart with the first change. (i.e. that use well structured
> toolkits to assist). With all the options that are available, it is
> difficult to get one scenario working, let alone being able to compare
> solutions in some meaningful way. Every time an issue comes up, the
> answer seems to be to add another software layer, from another
> development group, with another model/philosophy for how the solution
> should be coded. Having reference implementations helps to some degree,
> but if you are missing the fundamental concepts, the reference
> implementations can end up being confusing since they tend to highlight
> the differences/features of the particular implementation over the
> competition. Even the books with implementations in them tend to dive
> directly into the code without addressing the modeling aspect and the
> thinking that goes into creating the correct model to begin with.
>
> -david-
>
> Joshua Davis wrote:
>
> >Sorry 'bout the head banging! :(  If there's anything I can do to help,
let
> >me know.
> >
> >You are absolutely, positively 100% correct about 'getting a grip' on
> >Hibernate.
> >
> >It's actually more fundamental than that: You need to have a good
> >understanding of ORM in general in order to use Hibernate (or EJB
Entities,
> >or TOPLink, etc.) effectively.  For me, understanding ORM was a 'leap'
that
> >was similar to when I went from structured programming to OOP.
> >
> >joshua@hibernate.org
> >
> >
> >
> >>-----Original Message-----
> >>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
> >>Sent: Thursday, September 01, 2005 3:56 AM
> >>To: users@myfaces.apache.org
> >>Subject: Re: JSF + Spring + Hibernate
> >>
> >>One of the reasons why I am not that much a friend of
> >>Hibernate anymore.
> >>I did 4 projects with it, and the problems always were the same...
> >>Overkill in mapping details, Session handling and choking on
> >>pojos in which made things more complicated than they should
> >>be, failurs in dependency resolution on write over more
> >>complicated data structures, which then had to be resolved manually...
> >>
> >>Constant banging the heads on small stuff, like having a
> >>clean and proper way to resolve m:n issues. Sometimes there
> >>are errors where Hibernate simply does nothing but does not
> >>even throw errors.
> >>
> >>Dont get me wrong, Hibernate is an excellent tool, and
> >>basically has solved most of not all issues you constantly
> >>run into with Object Relational mappins and OODBs, but it is
> >>options overkill and definitely not easy to handle.
> >>I am not sure which is more complicated the EJB approach or
> >>the options overkill in Hibernate, which does not force you
> >>into anything, but often simply fails with leaving you
> >>standing in the rain.
> >>
> >>My opinion is, there must be some kind of middle way, to give
> >>you enough flexibility but does not push you into such a huge
> >>complex layer, Hibernate has evolved into, also 90% of the
> >>main problem you constantly have with hibernate is the
> >>complicated way the session handles the pojos... Dump the
> >>wrong pojo into the session and you get a object has been
> >>used failure.... Run out of the session hibernate chokes on
> >>lazy access instead of trying to resolve the problem by
> >>opening another one and trying to load the rest automatically...
> >>
> >>I would say, Hibernate is the worst/best working solution you
> >>can get from OSS in regards to ORM mapping, but one thing is
> >>for sure, it made things definitely not easier, although if
> >>you have a grip on it, you can save a lot of time, but
> >>aquiring the grip is a hard task, even with the excellent docs.
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> >
>
>


Re: JSF + Spring + Hibernate

Posted by Enrique Medina <e....@gmail.com>.
In the meantime, you can have a look at the books I used to learn all this 
stuff:

Hibernate in Action
JSF in Action
Programming Professional Java Applications with Spring

As I think I cannot recommend a shop from here, please send me a private 
email if you're interested (nothing to be with me, but great shop where I 
have bought nearly all my IT books) ;-)

2005/9/1, David Haynes <da...@sympatico.ca>:
> 
> Enrique:
> That sounds promising. I am also doing my PMP prep and am trying to put
> together a JSF/Hibernate application now, so I am a bit behind you on
> the learning curve. I have also been thinking about how a web
> application is really a finite state automata and how the diagramming
> tools from those may be used for modeling. It's early days on that train
> of thought though.
> 
> -david-
> 
> Enrique Medina wrote:
> 
> > You're absolutely right.
> >
> > I'm currently very busy in preparing my PMP and finishing my JSF
> > application, but I will be delighted to transfer all my experience and
> > knowledge in this matter as soon as a I find a couple of free weekends
> > (I was exactly in the same position that you are now when I began some
> > time ago with all this technology, so I can precisely imagine the kind
> > of tutorial you are waiting for ;-)
> >
> > Sorry, but I can only ask for patience right now.
> >
> > 2005/9/1, David Haynes <david.haynes2@sympatico.ca
> > <ma...@sympatico.ca>>:
> >
> > I'm going through that phase now waiting for the epiphany to strike...
> >
> > What I would really like is an article about thinking in ORM (ala
> > Hibernate or EJB) that doesn't talk about how the APIs are put
> > together
> > but, instead, deals with concepts like: this is how to think about
> > modeling in ORM, this is how to structure stuff in Hibernate for a
> > data-backed bean, or this is how to set up your source area to
> > make all
> > this a little clearer. A diagrammatic modeling method would also
> > be of
> > great value. Heck, even a suggested naming practice would be nice! Is
> > that XxxAction, XxxController, XxxBean, XxxBackingBean, XxxModel,
> > XxxDAO, etc.?
> >
> > Maybe I'm being a little selfish, but it seems to me that the
> > majority
> > of postings about backing-store issues are from poor sods such as
> > myself
> > who are trying to simply create data-coupled web applications that
> > won't
> > fall apart with the first change. (i.e. that use well structured
> > toolkits to assist). With all the options that are available, it is
> > difficult to get one scenario working, let alone being able to compare
> > solutions in some meaningful way. Every time an issue comes up, the
> > answer seems to be to add another software layer, from another
> > development group, with another model/philosophy for how the solution
> > should be coded. Having reference implementations helps to some
> > degree,
> > but if you are missing the fundamental concepts, the reference
> > implementations can end up being confusing since they tend to
> > highlight
> > the differences/features of the particular implementation over the
> > competition. Even the books with implementations in them tend to dive
> > directly into the code without addressing the modeling aspect and the
> > thinking that goes into creating the correct model to begin with.
> >
> > -david-
> >
> > Joshua Davis wrote:
> >
> > >Sorry 'bout the head banging! :( If there's anything I can do to
> > help, let
> > >me know.
> > >
> > >You are absolutely, positively 100% correct about 'getting a
> > grip' on
> > >Hibernate.
> > >
> > >It's actually more fundamental than that: You need to have a good
> > >understanding of ORM in general in order to use Hibernate (or EJB
> > Entities,
> > >or TOPLink, etc.) effectively. For me, understanding ORM was a
> > 'leap' that
> > >was similar to when I went from structured programming to OOP.
> > >
> > >joshua@hibernate.org <ma...@hibernate.org>
> > >
> > >
> > >
> > >>-----Original Message-----
> > >>From: news [mailto: news@sea.gmane.org
> > <ma...@sea.gmane.org>] On Behalf Of Werner Punz
> > >>Sent: Thursday, September 01, 2005 3:56 AM
> > >>To: users@myfaces.apache.org <ma...@myfaces.apache.org>
> > >>Subject: Re: JSF + Spring + Hibernate
> > >>
> > >>One of the reasons why I am not that much a friend of
> > >>Hibernate anymore.
> > >>I did 4 projects with it, and the problems always were the same...
> > >>Overkill in mapping details, Session handling and choking on
> > >>pojos in which made things more complicated than they should
> > >>be, failurs in dependency resolution on write over more
> > >>complicated data structures, which then had to be resolved
> > manually...
> > >>
> > >>Constant banging the heads on small stuff, like having a
> > >>clean and proper way to resolve m:n issues. Sometimes there
> > >>are errors where Hibernate simply does nothing but does not
> > >>even throw errors.
> > >>
> > >>Dont get me wrong, Hibernate is an excellent tool, and
> > >>basically has solved most of not all issues you constantly
> > >>run into with Object Relational mappins and OODBs, but it is
> > >>options overkill and definitely not easy to handle.
> > >>I am not sure which is more complicated the EJB approach or
> > >>the options overkill in Hibernate, which does not force you
> > >>into anything, but often simply fails with leaving you
> > >>standing in the rain.
> > >>
> > >>My opinion is, there must be some kind of middle way, to give
> > >>you enough flexibility but does not push you into such a huge
> > >>complex layer, Hibernate has evolved into, also 90% of the
> > >>main problem you constantly have with hibernate is the
> > >>complicated way the session handles the pojos... Dump the
> > >>wrong pojo into the session and you get a object has been
> > >>used failure.... Run out of the session hibernate chokes on
> > >>lazy access instead of trying to resolve the problem by
> > >>opening another one and trying to load the rest automatically...
> > >>
> > >>I would say, Hibernate is the worst/best working solution you
> > >>can get from OSS in regards to ORM mapping, but one thing is
> > >>for sure, it made things definitely not easier, although if
> > >>you have a grip on it, you can save a lot of time, but
> > >>aquiring the grip is a hard task, even with the excellent docs.
> > >>
> > >>
> > >>
> > >>
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> 
> 
>

Re: JSF + Spring + Hibernate

Posted by David Haynes <da...@sympatico.ca>.
Enrique:
That sounds promising. I am also doing my PMP prep and am trying to put 
together a JSF/Hibernate application now, so I am a bit behind you on 
the learning curve. I have also been thinking about how a web 
application is really a finite state automata and how the diagramming 
tools from those may be used for modeling. It's early days on that train 
of thought though.

-david-

Enrique Medina wrote:

> You're absolutely right.
>
> I'm currently very busy in preparing my PMP and finishing my JSF 
> application, but I will be delighted to transfer all my experience and 
> knowledge in this matter as soon as a I find a couple of free weekends 
> (I was exactly in the same position that you are now when I began some 
> time ago with all this technology, so I can precisely imagine the kind 
> of tutorial you are waiting for ;-)
>
> Sorry, but I can only ask for patience right now.
>
> 2005/9/1, David Haynes <david.haynes2@sympatico.ca 
> <ma...@sympatico.ca>>:
>
>     I'm going through that phase now waiting for the epiphany to strike...
>
>     What I would really like is an article about thinking in ORM (ala
>     Hibernate or EJB) that doesn't talk about how the APIs are put
>     together
>     but, instead, deals with concepts like: this is how to think about
>     modeling in ORM, this is how to structure stuff in Hibernate for a
>     data-backed bean, or this is how to set up your source area to
>     make all
>     this a little clearer. A diagrammatic modeling method would also
>     be of
>     great value. Heck, even a suggested naming practice would be nice! Is
>     that XxxAction, XxxController, XxxBean, XxxBackingBean, XxxModel,
>     XxxDAO, etc.?
>
>     Maybe I'm being a little selfish, but it seems to me that the
>     majority
>     of postings about backing-store issues are from poor sods such as
>     myself
>     who are trying to simply create data-coupled web applications that
>     won't
>     fall apart with the first change. (i.e. that use well structured
>     toolkits to assist). With all the options that are available, it is
>     difficult to get one scenario working, let alone being able to compare
>     solutions in some meaningful way. Every time an issue comes up, the
>     answer seems to be to add another software layer, from another
>     development group, with another model/philosophy for how the solution
>     should be coded. Having reference implementations helps to some
>     degree,
>     but if you are missing the fundamental concepts, the reference
>     implementations can end up being confusing since they tend to
>     highlight
>     the differences/features of the particular implementation over the
>     competition. Even the books with implementations in them tend to dive
>     directly into the code without addressing the modeling aspect and the
>     thinking that goes into creating the correct model to begin with.
>
>     -david-
>
>     Joshua Davis wrote:
>
>     >Sorry 'bout the head banging! :(  If there's anything I can do to
>     help, let
>     >me know.
>     >
>     >You are absolutely, positively 100% correct about 'getting a
>     grip' on
>     >Hibernate.
>     >
>     >It's actually more fundamental than that: You need to have a good
>     >understanding of ORM in general in order to use Hibernate (or EJB
>     Entities,
>     >or TOPLink, etc.) effectively.  For me, understanding ORM was a
>     'leap' that
>     >was similar to when I went from structured programming to OOP.
>     >
>     >joshua@hibernate.org <ma...@hibernate.org>
>     >
>     >
>     >
>     >>-----Original Message-----
>     >>From: news [mailto: news@sea.gmane.org
>     <ma...@sea.gmane.org>] On Behalf Of Werner Punz
>     >>Sent: Thursday, September 01, 2005 3:56 AM
>     >>To: users@myfaces.apache.org <ma...@myfaces.apache.org>
>     >>Subject: Re: JSF + Spring + Hibernate
>     >>
>     >>One of the reasons why I am not that much a friend of
>     >>Hibernate anymore.
>     >>I did 4 projects with it, and the problems always were the same...
>     >>Overkill in mapping details, Session handling and choking on
>     >>pojos in which made things more complicated than they should
>     >>be, failurs in dependency resolution on write over more
>     >>complicated data structures, which then had to be resolved
>     manually...
>     >>
>     >>Constant banging the heads on small stuff, like having a
>     >>clean and proper way to resolve m:n issues. Sometimes there
>     >>are errors where Hibernate simply does nothing but does not
>     >>even throw errors.
>     >>
>     >>Dont get me wrong, Hibernate is an excellent tool, and
>     >>basically has solved most of not all issues you constantly
>     >>run into with Object Relational mappins and OODBs, but it is
>     >>options overkill and definitely not easy to handle.
>     >>I am not sure which is more complicated the EJB approach or
>     >>the options overkill in Hibernate, which does not force you
>     >>into anything, but often simply fails with leaving you
>     >>standing in the rain.
>     >>
>     >>My opinion is, there must be some kind of middle way, to give
>     >>you enough flexibility but does not push you into such a huge
>     >>complex layer, Hibernate has evolved into, also 90% of the
>     >>main problem you constantly have with hibernate is the
>     >>complicated way the session handles the pojos... Dump the
>     >>wrong pojo into the session and you get a object has been
>     >>used failure.... Run out of the session hibernate chokes on
>     >>lazy access instead of trying to resolve the problem by
>     >>opening another one and trying to load the rest automatically...
>     >>
>     >>I would say, Hibernate is the worst/best working solution you
>     >>can get from OSS in regards to ORM mapping, but one thing is
>     >>for sure, it made things definitely not easier, although if
>     >>you have a grip on it, you can save a lot of time, but
>     >>aquiring the grip is a hard task, even with the excellent docs.
>     >>
>     >>
>     >>
>     >>
>     >
>     >
>     >
>     >
>     >
>
>
>



Re: JSF + Spring + Hibernate

Posted by Enrique Medina <e....@gmail.com>.
You're absolutely right.

I'm currently very busy in preparing my PMP and finishing my JSF 
application, but I will be delighted to transfer all my experience and 
knowledge in this matter as soon as a I find a couple of free weekends (I 
was exactly in the same position that you are now when I began some time ago 
with all this technology, so I can precisely imagine the kind of tutorial 
you are waiting for ;-)

Sorry, but I can only ask for patience right now.

2005/9/1, David Haynes <da...@sympatico.ca>:
> 
> I'm going through that phase now waiting for the epiphany to strike...
> 
> What I would really like is an article about thinking in ORM (ala
> Hibernate or EJB) that doesn't talk about how the APIs are put together
> but, instead, deals with concepts like: this is how to think about
> modeling in ORM, this is how to structure stuff in Hibernate for a
> data-backed bean, or this is how to set up your source area to make all
> this a little clearer. A diagrammatic modeling method would also be of
> great value. Heck, even a suggested naming practice would be nice! Is
> that XxxAction, XxxController, XxxBean, XxxBackingBean, XxxModel,
> XxxDAO, etc.?
> 
> Maybe I'm being a little selfish, but it seems to me that the majority
> of postings about backing-store issues are from poor sods such as myself
> who are trying to simply create data-coupled web applications that won't
> fall apart with the first change. (i.e. that use well structured
> toolkits to assist). With all the options that are available, it is
> difficult to get one scenario working, let alone being able to compare
> solutions in some meaningful way. Every time an issue comes up, the
> answer seems to be to add another software layer, from another
> development group, with another model/philosophy for how the solution
> should be coded. Having reference implementations helps to some degree,
> but if you are missing the fundamental concepts, the reference
> implementations can end up being confusing since they tend to highlight
> the differences/features of the particular implementation over the
> competition. Even the books with implementations in them tend to dive
> directly into the code without addressing the modeling aspect and the
> thinking that goes into creating the correct model to begin with.
> 
> -david-
> 
> Joshua Davis wrote:
> 
> >Sorry 'bout the head banging! :( If there's anything I can do to help, 
> let
> >me know.
> >
> >You are absolutely, positively 100% correct about 'getting a grip' on
> >Hibernate.
> >
> >It's actually more fundamental than that: You need to have a good
> >understanding of ORM in general in order to use Hibernate (or EJB 
> Entities,
> >or TOPLink, etc.) effectively. For me, understanding ORM was a 'leap' 
> that
> >was similar to when I went from structured programming to OOP.
> >
> >joshua@hibernate.org
> >
> >
> >
> >>-----Original Message-----
> >>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
> >>Sent: Thursday, September 01, 2005 3:56 AM
> >>To: users@myfaces.apache.org
> >>Subject: Re: JSF + Spring + Hibernate
> >>
> >>One of the reasons why I am not that much a friend of
> >>Hibernate anymore.
> >>I did 4 projects with it, and the problems always were the same...
> >>Overkill in mapping details, Session handling and choking on
> >>pojos in which made things more complicated than they should
> >>be, failurs in dependency resolution on write over more
> >>complicated data structures, which then had to be resolved manually...
> >>
> >>Constant banging the heads on small stuff, like having a
> >>clean and proper way to resolve m:n issues. Sometimes there
> >>are errors where Hibernate simply does nothing but does not
> >>even throw errors.
> >>
> >>Dont get me wrong, Hibernate is an excellent tool, and
> >>basically has solved most of not all issues you constantly
> >>run into with Object Relational mappins and OODBs, but it is
> >>options overkill and definitely not easy to handle.
> >>I am not sure which is more complicated the EJB approach or
> >>the options overkill in Hibernate, which does not force you
> >>into anything, but often simply fails with leaving you
> >>standing in the rain.
> >>
> >>My opinion is, there must be some kind of middle way, to give
> >>you enough flexibility but does not push you into such a huge
> >>complex layer, Hibernate has evolved into, also 90% of the
> >>main problem you constantly have with hibernate is the
> >>complicated way the session handles the pojos... Dump the
> >>wrong pojo into the session and you get a object has been
> >>used failure.... Run out of the session hibernate chokes on
> >>lazy access instead of trying to resolve the problem by
> >>opening another one and trying to load the rest automatically...
> >>
> >>I would say, Hibernate is the worst/best working solution you
> >>can get from OSS in regards to ORM mapping, but one thing is
> >>for sure, it made things definitely not easier, although if
> >>you have a grip on it, you can save a lot of time, but
> >>aquiring the grip is a hard task, even with the excellent docs.
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> >
> 
> 
>

Re: JSF + Spring + Hibernate

Posted by David Haynes <da...@sympatico.ca>.
That's the conclusion I came to. I did JSP/Hibernate first and will then 
change the JSP to JSF as the next stage.

-david-

Werner Punz wrote:

> There is something on the wiki already...
> it just needs a little bit more flesh and a few corrections...
> But I would say one step at a time, both JSF and Hibernate are
> huge frameworks, so it is better to concentrate on one
> and then on the other, before you combine both.
>
>
> Werner
>
>
> Joshua Davis wrote:
>
>> Well, If I can manage to learn JSF well enough I should be able to write
>> something up about how to use the backing beans with Hibernate.   
>> Maybe I
>> will re-use Spring's Hibernate support eventually, but for now I'm 
>> just my
>> own simplistic Hibnerate-JSF integration so I can concentrate on 
>> learning
>> JSF.
>>
>>
>>> -----Original Message-----
>>> From: David Haynes [mailto:david.haynes2@sympatico.ca] Sent: 
>>> Thursday, September 01, 2005 9:00 AM
>>> To: MyFaces Discussion
>>> Subject: Re: JSF + Spring + Hibernate
>>>
>>> I'm going through that phase now waiting for the epiphany to strike...
>>>
>>> What I would really like is an article about thinking in ORM (ala 
>>> Hibernate or EJB) that doesn't talk about how the APIs are put 
>>> together but, instead, deals with concepts like: this is how to 
>>> think about modeling in ORM, this is how to structure stuff in 
>>> Hibernate for a data-backed bean, or this is how to set up your 
>>> source area to make all this a little clearer. A diagrammatic 
>>> modeling method would also be of great value. Heck, even a suggested 
>>> naming practice would be nice! Is that XxxAction, XxxController, 
>>> XxxBean, XxxBackingBean, XxxModel, XxxDAO, etc.?
>>>
>>> Maybe I'm being a little selfish, but it seems to me that the 
>>> majority of postings about backing-store issues are from poor sods 
>>> such as myself who are trying to simply create data-coupled web 
>>> applications that won't fall apart with the first change. (i.e. that 
>>> use well structured toolkits to assist). With all the options that 
>>> are available, it is difficult to get one scenario working, let 
>>> alone being able to compare solutions in some meaningful way. Every 
>>> time an issue comes up, the answer seems to be to add another 
>>> software layer, from another development group, with another 
>>> model/philosophy for how the solution should be coded. Having 
>>> reference implementations helps to some degree, but if you are 
>>> missing the fundamental concepts, the reference implementations can 
>>> end up being confusing since they tend to highlight the 
>>> differences/features of the particular implementation over the 
>>> competition. Even the books with implementations in them tend to 
>>> dive directly into the code without addressing the modeling aspect 
>>> and the thinking that goes into creating the correct model to begin 
>>> with.
>>>
>>> -david-
>>>
>>> Joshua Davis wrote:
>>>
>>>
>>>> Sorry 'bout the head banging! :(  If there's anything I can 
>>>
>>>
>>> do to help,
>>>
>>>> let me know.
>>>>
>>>> You are absolutely, positively 100% correct about 'getting a 
>>>
>>>
>>> grip' on
>>>
>>>> Hibernate.
>>>>
>>>> It's actually more fundamental than that: You need to have a good 
>>>> understanding of ORM in general in order to use Hibernate (or EJB 
>>>> Entities, or TOPLink, etc.) effectively.  For me, 
>>>
>>>
>>> understanding ORM was
>>>
>>>> a 'leap' that was similar to when I went from structured 
>>>
>>>
>>> programming to OOP.
>>>
>>>> joshua@hibernate.org
>>>>
>>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
>>>>> Sent: Thursday, September 01, 2005 3:56 AM
>>>>> To: users@myfaces.apache.org
>>>>> Subject: Re: JSF + Spring + Hibernate
>>>>>
>>>>> One of the reasons why I am not that much a friend of Hibernate 
>>>>> anymore.
>>>>> I did 4 projects with it, and the problems always were the same...
>>>>> Overkill in mapping details, Session handling and choking 
>>>>
>>>
>>> on pojos in
>>>
>>>>> which made things more complicated than they should be, failurs in 
>>>>> dependency resolution on write over more complicated data 
>>>>
>>>
>>> structures,
>>>
>>>>> which then had to be resolved manually...
>>>>>
>>>>> Constant banging the heads on small stuff, like having a clean and 
>>>>> proper way to resolve m:n issues. Sometimes there are errors where 
>>>>> Hibernate simply does nothing but does not even throw errors.
>>>>>
>>>>> Dont get me wrong, Hibernate is an excellent tool, and 
>>>>
>>>
>>> basically has
>>>
>>>>> solved most of not all issues you constantly run into with Object 
>>>>> Relational mappins and OODBs, but it is options overkill and 
>>>>> definitely not easy to handle.
>>>>> I am not sure which is more complicated the EJB approach or the 
>>>>> options overkill in Hibernate, which does not force you 
>>>>
>>>
>>> into anything,
>>>
>>>>> but often simply fails with leaving you standing in the rain.
>>>>>
>>>>> My opinion is, there must be some kind of middle way, to give you 
>>>>> enough flexibility but does not push you into such a huge complex 
>>>>> layer, Hibernate has evolved into, also 90% of the main problem 
>>>>> you constantly have with hibernate is the complicated way the 
>>>>> session handles the pojos... Dump the wrong pojo into the session 
>>>>
>>>
>>> and you get
>>>
>>>>> a object has been used failure.... Run out of the session 
>>>>> hibernate chokes on lazy access instead of trying to resolve the 
>>>>> problem by opening another one and trying to load the rest 
>>>>> automatically...
>>>>>
>>>>> I would say, Hibernate is the worst/best working solution 
>>>>
>>>
>>> you can get
>>>
>>>>> from OSS in regards to ORM mapping, but one thing is for 
>>>>
>>>
>>> sure, it made
>>>
>>>>> things definitely not easier, although if you have a grip 
>>>>
>>>
>>> on it, you
>>>
>>>>> can save a lot of time, but aquiring the grip is a hard task, even 
>>>>> with the excellent docs.
>>>>>
>>>>>
>>>>>  
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
There is something on the wiki already...
it just needs a little bit more flesh and a few corrections...
But I would say one step at a time, both JSF and Hibernate are
huge frameworks, so it is better to concentrate on one
and then on the other, before you combine both.


Werner


Joshua Davis wrote:
> Well, If I can manage to learn JSF well enough I should be able to write
> something up about how to use the backing beans with Hibernate.   Maybe I
> will re-use Spring's Hibernate support eventually, but for now I'm just my
> own simplistic Hibnerate-JSF integration so I can concentrate on learning
> JSF.
> 
> 
>>-----Original Message-----
>>From: David Haynes [mailto:david.haynes2@sympatico.ca] 
>>Sent: Thursday, September 01, 2005 9:00 AM
>>To: MyFaces Discussion
>>Subject: Re: JSF + Spring + Hibernate
>>
>>I'm going through that phase now waiting for the epiphany to strike...
>>
>>What I would really like is an article about thinking in ORM 
>>(ala Hibernate or EJB) that doesn't talk about how the APIs 
>>are put together but, instead, deals with concepts like: this 
>>is how to think about modeling in ORM, this is how to 
>>structure stuff in Hibernate for a data-backed bean, or this 
>>is how to set up your source area to make all this a little 
>>clearer. A diagrammatic modeling method would also be of 
>>great value. Heck, even a suggested naming practice would be 
>>nice! Is that XxxAction, XxxController, XxxBean, 
>>XxxBackingBean, XxxModel, XxxDAO, etc.?
>>
>>Maybe I'm being a little selfish, but it seems to me that the 
>>majority of postings about backing-store issues are from poor 
>>sods such as myself who are trying to simply create 
>>data-coupled web applications that won't fall apart with the 
>>first change. (i.e. that use well structured toolkits to 
>>assist). With all the options that are available, it is 
>>difficult to get one scenario working, let alone being able 
>>to compare solutions in some meaningful way. Every time an 
>>issue comes up, the answer seems to be to add another 
>>software layer, from another development group, with another 
>>model/philosophy for how the solution should be coded. Having 
>>reference implementations helps to some degree, but if you 
>>are missing the fundamental concepts, the reference 
>>implementations can end up being confusing since they tend to 
>>highlight the differences/features of the particular 
>>implementation over the competition. Even the books with 
>>implementations in them tend to dive directly into the code 
>>without addressing the modeling aspect and the thinking that 
>>goes into creating the correct model to begin with.
>>
>>-david-
>>
>>Joshua Davis wrote:
>>
>>
>>>Sorry 'bout the head banging! :(  If there's anything I can 
>>
>>do to help, 
>>
>>>let me know.
>>>
>>>You are absolutely, positively 100% correct about 'getting a 
>>
>>grip' on 
>>
>>>Hibernate.
>>>
>>>It's actually more fundamental than that: You need to have a good 
>>>understanding of ORM in general in order to use Hibernate (or EJB 
>>>Entities, or TOPLink, etc.) effectively.  For me, 
>>
>>understanding ORM was 
>>
>>>a 'leap' that was similar to when I went from structured 
>>
>>programming to OOP.
>>
>>>joshua@hibernate.org
>>>
>>> 
>>>
>>>
>>>>-----Original Message-----
>>>>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
>>>>Sent: Thursday, September 01, 2005 3:56 AM
>>>>To: users@myfaces.apache.org
>>>>Subject: Re: JSF + Spring + Hibernate
>>>>
>>>>One of the reasons why I am not that much a friend of Hibernate 
>>>>anymore.
>>>>I did 4 projects with it, and the problems always were the same...
>>>>Overkill in mapping details, Session handling and choking 
>>
>>on pojos in 
>>
>>>>which made things more complicated than they should be, failurs in 
>>>>dependency resolution on write over more complicated data 
>>
>>structures, 
>>
>>>>which then had to be resolved manually...
>>>>
>>>>Constant banging the heads on small stuff, like having a clean and 
>>>>proper way to resolve m:n issues. Sometimes there are errors where 
>>>>Hibernate simply does nothing but does not even throw errors.
>>>>
>>>>Dont get me wrong, Hibernate is an excellent tool, and 
>>
>>basically has 
>>
>>>>solved most of not all issues you constantly run into with Object 
>>>>Relational mappins and OODBs, but it is options overkill and 
>>>>definitely not easy to handle.
>>>>I am not sure which is more complicated the EJB approach or the 
>>>>options overkill in Hibernate, which does not force you 
>>
>>into anything, 
>>
>>>>but often simply fails with leaving you standing in the rain.
>>>>
>>>>My opinion is, there must be some kind of middle way, to give you 
>>>>enough flexibility but does not push you into such a huge complex 
>>>>layer, Hibernate has evolved into, also 90% of the main problem you 
>>>>constantly have with hibernate is the complicated way the session 
>>>>handles the pojos... Dump the wrong pojo into the session 
>>
>>and you get 
>>
>>>>a object has been used failure.... Run out of the session hibernate 
>>>>chokes on lazy access instead of trying to resolve the problem by 
>>>>opening another one and trying to load the rest automatically...
>>>>
>>>>I would say, Hibernate is the worst/best working solution 
>>
>>you can get 
>>
>>>>from OSS in regards to ORM mapping, but one thing is for 
>>
>>sure, it made 
>>
>>>>things definitely not easier, although if you have a grip 
>>
>>on it, you 
>>
>>>>can save a lot of time, but aquiring the grip is a hard task, even 
>>>>with the excellent docs.
>>>>
>>>>
>>>>   
>>>>
>>>
>>>
>>>
>>> 
>>>
>>
>>
> 
> 


Re: JSF + Spring + Hibernate

Posted by David Haynes <da...@sympatico.ca>.
Sounds helpful. I would certainly be interested in reading about what 
you have discovered. I took some of Rob Decker's advice and re-read big 
chunks of Will Iverson's "Hibernate: A J2EE Developer's Guide". While it 
covers Hibernate 2, most of his advice is applicable to Hibernate 3 as 
well. The only thing I found odd was that he would present the hbm.xml 
file and *then* show the associated UML some pages later. Maybe its just 
me, but I would have probably put them the other way around.

I am now at the stage where I have a JSP/Hibernate solution with the 
backing beans working the way I would expect them to. The next stage is 
to replace the JSP with JSF and see how that goes. I am starting to 
build a methodology for development that seems to work for me. It starts 
with making changes to the UML model, then moving those changes into the 
hibernate hbm.xml (adding to the hibernate.cfg if required), then 
working up the bean (I know I could do this via a hibernate tool but I 
want to work with the beans directly for a while), and then, finally, 
encorporating the bean into the web pages. JSF, as I understand it, will 
allow me to remove the useBean references since it automatically invokes 
the creation of the bean upon first access.

All good stuff and certainly a learning exercise for me. After I get all 
this sorted out, I plan to introduce Spring into the mix (baby steps, 
baby steps) to see how that affects everything.

-david-

Joshua Davis wrote:

>Well, If I can manage to learn JSF well enough I should be able to write
>something up about how to use the backing beans with Hibernate.   Maybe I
>will re-use Spring's Hibernate support eventually, but for now I'm just my
>own simplistic Hibnerate-JSF integration so I can concentrate on learning
>JSF.
>
>  
>
>>-----Original Message-----
>>From: David Haynes [mailto:david.haynes2@sympatico.ca] 
>>Sent: Thursday, September 01, 2005 9:00 AM
>>To: MyFaces Discussion
>>Subject: Re: JSF + Spring + Hibernate
>>
>>I'm going through that phase now waiting for the epiphany to strike...
>>
>>What I would really like is an article about thinking in ORM 
>>(ala Hibernate or EJB) that doesn't talk about how the APIs 
>>are put together but, instead, deals with concepts like: this 
>>is how to think about modeling in ORM, this is how to 
>>structure stuff in Hibernate for a data-backed bean, or this 
>>is how to set up your source area to make all this a little 
>>clearer. A diagrammatic modeling method would also be of 
>>great value. Heck, even a suggested naming practice would be 
>>nice! Is that XxxAction, XxxController, XxxBean, 
>>XxxBackingBean, XxxModel, XxxDAO, etc.?
>>
>>Maybe I'm being a little selfish, but it seems to me that the 
>>majority of postings about backing-store issues are from poor 
>>sods such as myself who are trying to simply create 
>>data-coupled web applications that won't fall apart with the 
>>first change. (i.e. that use well structured toolkits to 
>>assist). With all the options that are available, it is 
>>difficult to get one scenario working, let alone being able 
>>to compare solutions in some meaningful way. Every time an 
>>issue comes up, the answer seems to be to add another 
>>software layer, from another development group, with another 
>>model/philosophy for how the solution should be coded. Having 
>>reference implementations helps to some degree, but if you 
>>are missing the fundamental concepts, the reference 
>>implementations can end up being confusing since they tend to 
>>highlight the differences/features of the particular 
>>implementation over the competition. Even the books with 
>>implementations in them tend to dive directly into the code 
>>without addressing the modeling aspect and the thinking that 
>>goes into creating the correct model to begin with.
>>
>>-david-
>>
>>Joshua Davis wrote:
>>
>>    
>>
>>>Sorry 'bout the head banging! :(  If there's anything I can 
>>>      
>>>
>>do to help, 
>>    
>>
>>>let me know.
>>>
>>>You are absolutely, positively 100% correct about 'getting a 
>>>      
>>>
>>grip' on 
>>    
>>
>>>Hibernate.
>>>
>>>It's actually more fundamental than that: You need to have a good 
>>>understanding of ORM in general in order to use Hibernate (or EJB 
>>>Entities, or TOPLink, etc.) effectively.  For me, 
>>>      
>>>
>>understanding ORM was 
>>    
>>
>>>a 'leap' that was similar to when I went from structured 
>>>      
>>>
>>programming to OOP.
>>    
>>
>>>joshua@hibernate.org
>>>
>>> 
>>>
>>>      
>>>
>>>>-----Original Message-----
>>>>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
>>>>Sent: Thursday, September 01, 2005 3:56 AM
>>>>To: users@myfaces.apache.org
>>>>Subject: Re: JSF + Spring + Hibernate
>>>>
>>>>One of the reasons why I am not that much a friend of Hibernate 
>>>>anymore.
>>>>I did 4 projects with it, and the problems always were the same...
>>>>Overkill in mapping details, Session handling and choking 
>>>>        
>>>>
>>on pojos in 
>>    
>>
>>>>which made things more complicated than they should be, failurs in 
>>>>dependency resolution on write over more complicated data 
>>>>        
>>>>
>>structures, 
>>    
>>
>>>>which then had to be resolved manually...
>>>>
>>>>Constant banging the heads on small stuff, like having a clean and 
>>>>proper way to resolve m:n issues. Sometimes there are errors where 
>>>>Hibernate simply does nothing but does not even throw errors.
>>>>
>>>>Dont get me wrong, Hibernate is an excellent tool, and 
>>>>        
>>>>
>>basically has 
>>    
>>
>>>>solved most of not all issues you constantly run into with Object 
>>>>Relational mappins and OODBs, but it is options overkill and 
>>>>definitely not easy to handle.
>>>>I am not sure which is more complicated the EJB approach or the 
>>>>options overkill in Hibernate, which does not force you 
>>>>        
>>>>
>>into anything, 
>>    
>>
>>>>but often simply fails with leaving you standing in the rain.
>>>>
>>>>My opinion is, there must be some kind of middle way, to give you 
>>>>enough flexibility but does not push you into such a huge complex 
>>>>layer, Hibernate has evolved into, also 90% of the main problem you 
>>>>constantly have with hibernate is the complicated way the session 
>>>>handles the pojos... Dump the wrong pojo into the session 
>>>>        
>>>>
>>and you get 
>>    
>>
>>>>a object has been used failure.... Run out of the session hibernate 
>>>>chokes on lazy access instead of trying to resolve the problem by 
>>>>opening another one and trying to load the rest automatically...
>>>>
>>>>I would say, Hibernate is the worst/best working solution 
>>>>        
>>>>
>>you can get 
>>    
>>
>>>>from OSS in regards to ORM mapping, but one thing is for 
>>>      
>>>
>>sure, it made 
>>    
>>
>>>>things definitely not easier, although if you have a grip 
>>>>        
>>>>
>>on it, you 
>>    
>>
>>>>can save a lot of time, but aquiring the grip is a hard task, even 
>>>>with the excellent docs.
>>>>
>>>>
>>>>   
>>>>
>>>>        
>>>>
>>>
>>> 
>>>
>>>      
>>>
>>    
>>
>
>
>  
>



RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
Well, If I can manage to learn JSF well enough I should be able to write
something up about how to use the backing beans with Hibernate.   Maybe I
will re-use Spring's Hibernate support eventually, but for now I'm just my
own simplistic Hibnerate-JSF integration so I can concentrate on learning
JSF.

> -----Original Message-----
> From: David Haynes [mailto:david.haynes2@sympatico.ca] 
> Sent: Thursday, September 01, 2005 9:00 AM
> To: MyFaces Discussion
> Subject: Re: JSF + Spring + Hibernate
> 
> I'm going through that phase now waiting for the epiphany to strike...
> 
> What I would really like is an article about thinking in ORM 
> (ala Hibernate or EJB) that doesn't talk about how the APIs 
> are put together but, instead, deals with concepts like: this 
> is how to think about modeling in ORM, this is how to 
> structure stuff in Hibernate for a data-backed bean, or this 
> is how to set up your source area to make all this a little 
> clearer. A diagrammatic modeling method would also be of 
> great value. Heck, even a suggested naming practice would be 
> nice! Is that XxxAction, XxxController, XxxBean, 
> XxxBackingBean, XxxModel, XxxDAO, etc.?
> 
> Maybe I'm being a little selfish, but it seems to me that the 
> majority of postings about backing-store issues are from poor 
> sods such as myself who are trying to simply create 
> data-coupled web applications that won't fall apart with the 
> first change. (i.e. that use well structured toolkits to 
> assist). With all the options that are available, it is 
> difficult to get one scenario working, let alone being able 
> to compare solutions in some meaningful way. Every time an 
> issue comes up, the answer seems to be to add another 
> software layer, from another development group, with another 
> model/philosophy for how the solution should be coded. Having 
> reference implementations helps to some degree, but if you 
> are missing the fundamental concepts, the reference 
> implementations can end up being confusing since they tend to 
> highlight the differences/features of the particular 
> implementation over the competition. Even the books with 
> implementations in them tend to dive directly into the code 
> without addressing the modeling aspect and the thinking that 
> goes into creating the correct model to begin with.
> 
> -david-
> 
> Joshua Davis wrote:
> 
> >Sorry 'bout the head banging! :(  If there's anything I can 
> do to help, 
> >let me know.
> >
> >You are absolutely, positively 100% correct about 'getting a 
> grip' on 
> >Hibernate.
> >
> >It's actually more fundamental than that: You need to have a good 
> >understanding of ORM in general in order to use Hibernate (or EJB 
> >Entities, or TOPLink, etc.) effectively.  For me, 
> understanding ORM was 
> >a 'leap' that was similar to when I went from structured 
> programming to OOP.
> >
> >joshua@hibernate.org
> >
> >  
> >
> >>-----Original Message-----
> >>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
> >>Sent: Thursday, September 01, 2005 3:56 AM
> >>To: users@myfaces.apache.org
> >>Subject: Re: JSF + Spring + Hibernate
> >>
> >>One of the reasons why I am not that much a friend of Hibernate 
> >>anymore.
> >>I did 4 projects with it, and the problems always were the same...
> >>Overkill in mapping details, Session handling and choking 
> on pojos in 
> >>which made things more complicated than they should be, failurs in 
> >>dependency resolution on write over more complicated data 
> structures, 
> >>which then had to be resolved manually...
> >>
> >>Constant banging the heads on small stuff, like having a clean and 
> >>proper way to resolve m:n issues. Sometimes there are errors where 
> >>Hibernate simply does nothing but does not even throw errors.
> >>
> >>Dont get me wrong, Hibernate is an excellent tool, and 
> basically has 
> >>solved most of not all issues you constantly run into with Object 
> >>Relational mappins and OODBs, but it is options overkill and 
> >>definitely not easy to handle.
> >>I am not sure which is more complicated the EJB approach or the 
> >>options overkill in Hibernate, which does not force you 
> into anything, 
> >>but often simply fails with leaving you standing in the rain.
> >>
> >>My opinion is, there must be some kind of middle way, to give you 
> >>enough flexibility but does not push you into such a huge complex 
> >>layer, Hibernate has evolved into, also 90% of the main problem you 
> >>constantly have with hibernate is the complicated way the session 
> >>handles the pojos... Dump the wrong pojo into the session 
> and you get 
> >>a object has been used failure.... Run out of the session hibernate 
> >>chokes on lazy access instead of trying to resolve the problem by 
> >>opening another one and trying to load the rest automatically...
> >>
> >>I would say, Hibernate is the worst/best working solution 
> you can get 
> >>from OSS in regards to ORM mapping, but one thing is for 
> sure, it made 
> >>things definitely not easier, although if you have a grip 
> on it, you 
> >>can save a lot of time, but aquiring the grip is a hard task, even 
> >>with the excellent docs.
> >>
> >>
> >>    
> >>
> >
> >
> >
> >  
> >
> 
> 


Re: JSF + Spring + Hibernate

Posted by David Haynes <da...@sympatico.ca>.
I'm going through that phase now waiting for the epiphany to strike...

What I would really like is an article about thinking in ORM (ala 
Hibernate or EJB) that doesn't talk about how the APIs are put together 
but, instead, deals with concepts like: this is how to think about 
modeling in ORM, this is how to structure stuff in Hibernate for a 
data-backed bean, or this is how to set up your source area to make all 
this a little clearer. A diagrammatic modeling method would also be of 
great value. Heck, even a suggested naming practice would be nice! Is 
that XxxAction, XxxController, XxxBean, XxxBackingBean, XxxModel, 
XxxDAO, etc.?

Maybe I'm being a little selfish, but it seems to me that the majority 
of postings about backing-store issues are from poor sods such as myself 
who are trying to simply create data-coupled web applications that won't 
fall apart with the first change. (i.e. that use well structured 
toolkits to assist). With all the options that are available, it is 
difficult to get one scenario working, let alone being able to compare 
solutions in some meaningful way. Every time an issue comes up, the 
answer seems to be to add another software layer, from another 
development group, with another model/philosophy for how the solution 
should be coded. Having reference implementations helps to some degree, 
but if you are missing the fundamental concepts, the reference 
implementations can end up being confusing since they tend to highlight 
the differences/features of the particular implementation over the 
competition. Even the books with implementations in them tend to dive 
directly into the code without addressing the modeling aspect and the 
thinking that goes into creating the correct model to begin with.

-david-

Joshua Davis wrote:

>Sorry 'bout the head banging! :(  If there's anything I can do to help, let
>me know.
>
>You are absolutely, positively 100% correct about 'getting a grip' on
>Hibernate.
>
>It's actually more fundamental than that: You need to have a good
>understanding of ORM in general in order to use Hibernate (or EJB Entities,
>or TOPLink, etc.) effectively.  For me, understanding ORM was a 'leap' that
>was similar to when I went from structured programming to OOP.
>
>joshua@hibernate.org
>
>  
>
>>-----Original Message-----
>>From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
>>Sent: Thursday, September 01, 2005 3:56 AM
>>To: users@myfaces.apache.org
>>Subject: Re: JSF + Spring + Hibernate
>>
>>One of the reasons why I am not that much a friend of 
>>Hibernate anymore.
>>I did 4 projects with it, and the problems always were the same...
>>Overkill in mapping details, Session handling and choking on 
>>pojos in which made things more complicated than they should 
>>be, failurs in dependency resolution on write over more 
>>complicated data structures, which then had to be resolved manually...
>>
>>Constant banging the heads on small stuff, like having a 
>>clean and proper way to resolve m:n issues. Sometimes there 
>>are errors where Hibernate simply does nothing but does not 
>>even throw errors.
>>
>>Dont get me wrong, Hibernate is an excellent tool, and 
>>basically has solved most of not all issues you constantly 
>>run into with Object Relational mappins and OODBs, but it is 
>>options overkill and definitely not easy to handle.
>>I am not sure which is more complicated the EJB approach or 
>>the options overkill in Hibernate, which does not force you 
>>into anything, but often simply fails with leaving you 
>>standing in the rain.
>>
>>My opinion is, there must be some kind of middle way, to give 
>>you enough flexibility but does not push you into such a huge 
>>complex layer, Hibernate has evolved into, also 90% of the 
>>main problem you constantly have with hibernate is the 
>>complicated way the session handles the pojos... Dump the 
>>wrong pojo into the session and you get a object has been 
>>used failure.... Run out of the session hibernate chokes on 
>>lazy access instead of trying to resolve the problem by 
>>opening another one and trying to load the rest automatically...
>>
>>I would say, Hibernate is the worst/best working solution you 
>>can get from OSS in regards to ORM mapping, but one thing is 
>>for sure, it made things definitely not easier, although if 
>>you have a grip on it, you can save a lot of time, but 
>>aquiring the grip is a hard task, even with the excellent docs.
>>
>>
>>    
>>
>
>
>
>  
>



RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
Sorry 'bout the head banging! :(  If there's anything I can do to help, let
me know.

You are absolutely, positively 100% correct about 'getting a grip' on
Hibernate.

It's actually more fundamental than that: You need to have a good
understanding of ORM in general in order to use Hibernate (or EJB Entities,
or TOPLink, etc.) effectively.  For me, understanding ORM was a 'leap' that
was similar to when I went from structured programming to OOP.

joshua@hibernate.org

> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
> Sent: Thursday, September 01, 2005 3:56 AM
> To: users@myfaces.apache.org
> Subject: Re: JSF + Spring + Hibernate
> 
> One of the reasons why I am not that much a friend of 
> Hibernate anymore.
> I did 4 projects with it, and the problems always were the same...
> Overkill in mapping details, Session handling and choking on 
> pojos in which made things more complicated than they should 
> be, failurs in dependency resolution on write over more 
> complicated data structures, which then had to be resolved manually...
> 
> Constant banging the heads on small stuff, like having a 
> clean and proper way to resolve m:n issues. Sometimes there 
> are errors where Hibernate simply does nothing but does not 
> even throw errors.
>
> Dont get me wrong, Hibernate is an excellent tool, and 
> basically has solved most of not all issues you constantly 
> run into with Object Relational mappins and OODBs, but it is 
> options overkill and definitely not easy to handle.
> I am not sure which is more complicated the EJB approach or 
> the options overkill in Hibernate, which does not force you 
> into anything, but often simply fails with leaving you 
> standing in the rain.
> 
> My opinion is, there must be some kind of middle way, to give 
> you enough flexibility but does not push you into such a huge 
> complex layer, Hibernate has evolved into, also 90% of the 
> main problem you constantly have with hibernate is the 
> complicated way the session handles the pojos... Dump the 
> wrong pojo into the session and you get a object has been 
> used failure.... Run out of the session hibernate chokes on 
> lazy access instead of trying to resolve the problem by 
> opening another one and trying to load the rest automatically...
> 
> I would say, Hibernate is the worst/best working solution you 
> can get from OSS in regards to ORM mapping, but one thing is 
> for sure, it made things definitely not easier, although if 
> you have a grip on it, you can save a lot of time, but 
> aquiring the grip is a hard task, even with the excellent docs.
> 
> 



Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Richard Wallace wrote:
>
> I guess I'm just not seeing the reason to use this with Hibernate.  I 
> mean the whole point of Hibernate is to be able to persist you're POJO 
> and use them wherever you see fit and not have to worry about all the 
> complications that arise from EJBs.  That's the ideal at least.  The 
> reality is that you do have to worry about the Hibernate session and 
> loading objects and performing opertations within a session, but I'm 
> having a hard time buying into the idea of using transfer objects with 
> Hibernate.
> 
One of the reasons why I am not that much a friend of Hibernate anymore.
I did 4 projects with it, and the problems always were the same...
Overkill in mapping details, Session handling and choking on pojos in 
which made things more complicated than they should be, failurs in 
dependency resolution on write over more complicated data structures, 
which then had to be resolved manually...

Constant banging the heads on small stuff, like having a clean and 
proper way to resolve m:n issues. Sometimes there are errors
where Hibernate simply does nothing but does not even throw errors.

Dont get me wrong, Hibernate is an excellent tool, and basically has 
solved most of not all issues you constantly run into with Object 
Relational mappins and OODBs, but it is options overkill and definitely 
not easy to handle.
I am not sure which is more complicated the EJB approach or the options 
overkill in Hibernate, which does not force you into anything, but often 
simply fails with leaving you standing in the rain.

My opinion is, there must be some kind of middle way, to give you enough 
flexibility but does not push you into such a huge complex layer, 
Hibernate has evolved into, also 90% of the main problem you constantly 
have with hibernate is the complicated way the session handles the 
pojos... Dump the wrong pojo into the session and you get a object has 
been used failure.... Run out of the session hibernate chokes on lazy 
access instead of trying to resolve the problem by opening another one 
and trying to load the rest automatically...

I would say, Hibernate is the worst/best working solution you can get 
from OSS in regards to ORM mapping, but one thing is for sure, it made 
things definitely not easier, although if you have a grip on it, you can 
save a lot of time, but aquiring the grip is a hard task, even with the 
excellent docs.


Re: JSF + Spring + Hibernate

Posted by Richard Wallace <rw...@thewallacepack.net>.
Joshua Davis wrote:

>Transfer Object is a design pattern frequently used with EJB:
>http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html
>.
>Your managed beans could copy the Hibernate-mapped objects (I call them
>Persistent Domain Objects) into simple POJOs that aren't mapped.  Leave
>these in the session, stick them in a cache, store them in base64 encoded
>hidden input fields, or whatever.
>
>  
>
I guess I'm just not seeing the reason to use this with Hibernate.  I 
mean the whole point of Hibernate is to be able to persist you're POJO 
and use them wherever you see fit and not have to worry about all the 
complications that arise from EJBs.  That's the ideal at least.  The 
reality is that you do have to worry about the Hibernate session and 
loading objects and performing opertations within a session, but I'm 
having a hard time buying into the idea of using transfer objects with 
Hibernate. 

>>That's the 
>>first time I've ever heard anyone mention that.  The problem 
>>with telling Hibernate to initialize the object graph is 
>>that, in most cases I think, the use of Hibernate is 
>>abstracted away from the webapp layer.  So your backing beans 
>>don't really know they need to do that and even if they did 
>>they couldn't.
>>    
>>
>
>The DAO should do it.  The backing beans (business session pattern) can ask
>the DAO to do it in an abstract way.
>
>  
>
I'm guessing you're referring to something like having a secondary 
parameter so it looks something like myDao.get (oid, lazyLoad) or 
something like that.  To me that's still bad because you need to know 
something about the way objects are stored at a very high level.  In 
reality, the backing beans probably don't even access the DAOs directly, 
but do it via some middle tier service object.

>> And setting the lazy attribute to false is a 
>>workaround, but could lead to large graphs being loaded into 
>>many users HTTP sessions.  
>>    
>>
>
>This works for simple graphs only.  For complex graphs, your DAO (which is
>the only thing in your system that should import Hibernate) can pick and
>chose which objects to initialize.   What this is doing is essentially
>turning your PDOs into Transfer Objects.
>
>  
>
The problem with have the DAOs pick and choose which objects to 
initialize is that it assumes knowledge of the context in which they 
will be used.  I mean, how can you know apriori what you need to 
initialize in a get(oid) method?  You have no idea where it will be used. 

>>Reassociating the object with the session has a similar 
>>problem as trying to initialize the object from within the 
>>webapp layer before putting it in the session.  Your webapp 
>>simply does not know that you are using Hibernate.  And even 
>>if it did, it has no access to the actual Hibernate session.
>>I toyed around at one time with the idea of trying to create 
>>a servlet filter that would automatically reassociate 
>>anything in the HTTP session with the Hibernate session.  
>>There are a couple of problems with that tho.  First off, 
>>it's not always easy to determine what objects are Hibernate 
>>persisted objects and which aren't.  Second, if the actual 
>>Hibernate object is wrapped in a backing bean that is 
>>actually put in the HTTP session simply scanning objects in 
>>the HTTP session won't work.  Finally, what convinced me it 
>>was a bad idea is that the only ways to reassociate an object 
>>with a Hibernate session that I was able to find is to use 
>>merge(), update(), or lock().  The first two will update the 
>>database with the object you provide, and locking requires 
>>the underlying data in the db hasn't changed.  So you'd lose 
>>any changes that could have occured while the object was in 
>>the session.
>>    
>>
>
>Yikes! That sounds complicated.  ;)
>The only reason you would want to reassociate the objects is if you want to
>update them.  If you are just using the session as a cache, then these
>objects should not be mapped.   That will cause all kinds of headaches.
>
>  
>
But there is at least one situation I can think of where it makes sense 
and that is a users profile.  The situation that I was running into was 
that a users profile had the standard contact information, but then had 
links to other domain objects the user was responsible for.  What I 
would up having to do is separate all that out from the user profile and 
create a separate myDao.get(curerntUser) kind of thing, which is what I 
was getting at before.  Maybe this is the right way to do it, but it 
also seems to kind of make sense to be able to simply say 
currentUser.getMyStuff(), you know what I mean?

>>So, like I said, just refetching the Hibernate objects for 
>>each request is much easier and doesn't cause too much extra 
>>load on the database if your using the 2nd level cache.
>>    
>>
>
>Bingo!  You've got it there.  To me, it makes sense to use Transfer Objects,
>or at least make the integration layer (where the DAOs live) able to provide
>initialized sub-graphs - mapped objects turned into Transfer Objects.
>Which brings me back to JSF...  My current JSF application uses DAOs that
>provide the mapped objects to the business beans.   These beans create
>transfer objects that are accessed by the view.   When actions that require
>db modification occur, the DAO is used to look up the object again and the
>new values are set into the mapped object from the transfer object.  This is
>a little bit more programming if you have a separate class for the mapped
>object and the transfer object, but it's not much more work at all if you
>use the initialized subgraph concept.  The benefit is that there is no need
>for any fancy session reassociation or anything like that.   The
>presentation layer and the persistence (integration) layer are completely
>separated.
>  
>
Seems much more complicated than I thought using Hibernate was supposed 
to be.  I mean, like I said before, I thought the idea of Hibernate was 
to take any plain old java object and be able to make it persitent 
without all this extra overhead.  I'm also having a hard time 
envisioning what these transfer objects would look like, I mean are they 
just copies of the Hibernate objects?  If so, how is this all that 
different from just recursively doing initialize() on persitent objects?

Rich

P.S.  Sorry if I seem argumentative but I'm actually just getting done 
with my first project that uses JSF + Spring + Hibernate and the 
LazyInitializationException was something I ran into with my user 
profile objects that bothered me for days before I just said, "Ok, 
fine.  I'll do a myDao.getStuffForUser(currentUser)" method rather than 
being able to use something simpler like currentUser.getStuff()."  So 
this is something I'm keenly interested in finding how other people 
approach the problem.

RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
> >The scope of the Hibernate session must match the scope of 
> any lazily 
> >loaded objects or collections.  That's one of the rules of Hibernate 
> >(or any other ORM that I've used, for that matter).  Putting a proxy 
> >object in web session scope while the Hibernate session is 
> in request 
> >scope breaks that rule.  You need to either use a transfer 
> object, or 
> >cause Hibernate to initialize the proxy by either setting 
> the lazy attribute to false, or using
> >Hibernate.initialize().   You can also re-associate the 
> object with the
> >Hibernate session as was mentioned before.
> >
> >joshua@hibernate.org
> >
> >
> >  
> >
> I think you may have skipped the rest of my email.  I 
> detailed the ways I'm working around that.

Yep, I read it.

>  I understand it 
> breaks the Hibernate contract, I was merely mentioning it as 
> a possible issue because everyone had simply been talking 
> about problems within a single request.  I just wanted to 
> point out that that is not the only issue with lazily loaded 
> objects and you need to be careful about putting them in the 
> HTTP session.
> 
> What do you mean by "use a transfer object?" 

Transfer Object is a design pattern frequently used with EJB:
http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html
.
Your managed beans could copy the Hibernate-mapped objects (I call them
Persistent Domain Objects) into simple POJOs that aren't mapped.  Leave
these in the session, stick them in a cache, store them in base64 encoded
hidden input fields, or whatever.

> That's the 
> first time I've ever heard anyone mention that.  The problem 
> with telling Hibernate to initialize the object graph is 
> that, in most cases I think, the use of Hibernate is 
> abstracted away from the webapp layer.  So your backing beans 
> don't really know they need to do that and even if they did 
> they couldn't.

The DAO should do it.  The backing beans (business session pattern) can ask
the DAO to do it in an abstract way.

>  And setting the lazy attribute to false is a 
> workaround, but could lead to large graphs being loaded into 
> many users HTTP sessions.  

This works for simple graphs only.  For complex graphs, your DAO (which is
the only thing in your system that should import Hibernate) can pick and
chose which objects to initialize.   What this is doing is essentially
turning your PDOs into Transfer Objects.

> Reassociating the object with the session has a similar 
> problem as trying to initialize the object from within the 
> webapp layer before putting it in the session.  Your webapp 
> simply does not know that you are using Hibernate.  And even 
> if it did, it has no access to the actual Hibernate session.
> I toyed around at one time with the idea of trying to create 
> a servlet filter that would automatically reassociate 
> anything in the HTTP session with the Hibernate session.  
> There are a couple of problems with that tho.  First off, 
> it's not always easy to determine what objects are Hibernate 
> persisted objects and which aren't.  Second, if the actual 
> Hibernate object is wrapped in a backing bean that is 
> actually put in the HTTP session simply scanning objects in 
> the HTTP session won't work.  Finally, what convinced me it 
> was a bad idea is that the only ways to reassociate an object 
> with a Hibernate session that I was able to find is to use 
> merge(), update(), or lock().  The first two will update the 
> database with the object you provide, and locking requires 
> the underlying data in the db hasn't changed.  So you'd lose 
> any changes that could have occured while the object was in 
> the session.

Yikes! That sounds complicated.  ;)
The only reason you would want to reassociate the objects is if you want to
update them.  If you are just using the session as a cache, then these
objects should not be mapped.   That will cause all kinds of headaches.

> So, like I said, just refetching the Hibernate objects for 
> each request is much easier and doesn't cause too much extra 
> load on the database if your using the 2nd level cache.

Bingo!  You've got it there.  To me, it makes sense to use Transfer Objects,
or at least make the integration layer (where the DAOs live) able to provide
initialized sub-graphs - mapped objects turned into Transfer Objects.
Which brings me back to JSF...  My current JSF application uses DAOs that
provide the mapped objects to the business beans.   These beans create
transfer objects that are accessed by the view.   When actions that require
db modification occur, the DAO is used to look up the object again and the
new values are set into the mapped object from the transfer object.  This is
a little bit more programming if you have a separate class for the mapped
object and the transfer object, but it's not much more work at all if you
use the initialized subgraph concept.  The benefit is that there is no need
for any fancy session reassociation or anything like that.   The
presentation layer and the persistence (integration) layer are completely
separated.


HTH

joshua@hibernate.org



Re: JSF + Spring + Hibernate

Posted by Richard Wallace <rw...@thewallacepack.net>.
Joshua Davis wrote:

>>-----Original Message-----
>>From: Richard Wallace [mailto:rwallace@thewallacepack.net] 
>>Sent: Wednesday, August 31, 2005 2:38 PM
>>To: MyFaces Discussion
>>Subject: Re: JSF + Spring + Hibernate
>>
>>I do use OpenSessionInView for lazily loading objects in the 
>>same request.  The problem that I've been running into is 
>>when objects loaded from Hibernate have lazily loaded 
>>collections and are put into the session before the 
>>collection gets used.  Then on a future request, Hibernate 
>>tries to lazily load the objects and can't because the 
>>session used to retrieved them has been closed. 
>>    
>>
>
>The scope of the Hibernate session must match the scope of any lazily loaded
>objects or collections.  That's one of the rules of Hibernate (or any other
>ORM that I've used, for that matter).  Putting a proxy object in web session
>scope while the Hibernate session is in request scope breaks that rule.  You
>need to either use a transfer object, or cause Hibernate to initialize the
>proxy by either setting the lazy attribute to false, or using
>Hibernate.initialize().   You can also re-associate the object with the
>Hibernate session as was mentioned before.
>
>joshua@hibernate.org
>
>
>  
>
I think you may have skipped the rest of my email.  I detailed the ways 
I'm working around that.  I understand it breaks the Hibernate contract, 
I was merely mentioning it as a possible issue because everyone had 
simply been talking about problems within a single request.  I just 
wanted to point out that that is not the only issue with lazily loaded 
objects and you need to be careful about putting them in the HTTP session.

What do you mean by "use a transfer object?"  That's the first time I've 
ever heard anyone mention that.  The problem with telling Hibernate to 
initialize the object graph is that, in most cases I think, the use of 
Hibernate is abstracted away from the webapp layer.  So your backing 
beans don't really know they need to do that and even if they did they 
couldn't.  And setting the lazy attribute to false is a workaround, but 
could lead to large graphs being loaded into many users HTTP sessions.  
Reassociating the object with the session has a similar problem as 
trying to initialize the object from within the webapp layer before 
putting it in the session.  Your webapp simply does not know that you 
are using Hibernate.  And even if it did, it has no access to the actual 
Hibernate session.

I toyed around at one time with the idea of trying to create a servlet 
filter that would automatically reassociate anything in the HTTP session 
with the Hibernate session.  There are a couple of problems with that 
tho.  First off, it's not always easy to determine what objects are 
Hibernate persisted objects and which aren't.  Second, if the actual 
Hibernate object is wrapped in a backing bean that is actually put in 
the HTTP session simply scanning objects in the HTTP session won't 
work.  Finally, what convinced me it was a bad idea is that the only 
ways to reassociate an object with a Hibernate session that I was able 
to find is to use merge(), update(), or lock().  The first two will 
update the database with the object you provide, and locking requires 
the underlying data in the db hasn't changed.  So you'd lose any changes 
that could have occured while the object was in the session.

So, like I said, just refetching the Hibernate objects for each request 
is much easier and doesn't cause too much extra load on the database if 
your using the 2nd level cache.

Rich

RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
> -----Original Message-----
> From: Richard Wallace [mailto:rwallace@thewallacepack.net] 
> Sent: Wednesday, August 31, 2005 2:38 PM
> To: MyFaces Discussion
> Subject: Re: JSF + Spring + Hibernate
> 
> I do use OpenSessionInView for lazily loading objects in the 
> same request.  The problem that I've been running into is 
> when objects loaded from Hibernate have lazily loaded 
> collections and are put into the session before the 
> collection gets used.  Then on a future request, Hibernate 
> tries to lazily load the objects and can't because the 
> session used to retrieved them has been closed. 

The scope of the Hibernate session must match the scope of any lazily loaded
objects or collections.  That's one of the rules of Hibernate (or any other
ORM that I've used, for that matter).  Putting a proxy object in web session
scope while the Hibernate session is in request scope breaks that rule.  You
need to either use a transfer object, or cause Hibernate to initialize the
proxy by either setting the lazy attribute to false, or using
Hibernate.initialize().   You can also re-associate the object with the
Hibernate session as was mentioned before.

joshua@hibernate.org




Re: JSF + Spring + Hibernate

Posted by Richard Wallace <rw...@thewallacepack.net>.
I do use OpenSessionInView for lazily loading objects in the same 
request.  The problem that I've been running into is when objects loaded 
from Hibernate have lazily loaded collections and are put into the 
session before the collection gets used.  Then on a future request, 
Hibernate tries to lazily load the objects and can't because the session 
used to retrieved them has been closed. 

So, I've been shying away from allowing Hibernate to lazily load things 
and have been using something similar to your 
CompanyDao.getEmployees(Company company) method.  I can see both good 
and bad in this approach.  I figure this is probably ok because it lets 
the web developer know that there is an extra request going to the 
backend to get that list, whereas lazily loading with 
Company.getEmployees() is a little too transparent and could easily be 
misused.  But on the other hand, being able to have easy access to that 
data is very seductive.

The best solution I've found is to have all my backing beans that 
retrieve data be request scoped so that a) I always get the most recent 
data and b) I don't have to worry about any lazy loading issues like 
this.  So, in this situation the only thing I really put into the 
session is the users profile and authetication information and some 
basic state information.  Of course this does generate more hits on the 
database, but I'm willing to live with to a certain extent.

Ken Weiner wrote:

> I have a question about designing a webapp to use a DAO layer, lazily 
> loaded objects, Hibernate, and the OpenSessionInView technique.
>
> Doesn't this strategy make it very difficult to reimplement the DAO 
> layer sometime in the future?  If you switched a DAO implementation 
> from Hibernate to let's say, Spring JDBC, then how would all the lazy 
> loading work?  There would be no equivalent OpenSessionInView 
> technique for Spring JDBC.  For this reason, I have been shying away 
> from designing my domain objects such that the rest of the app expects 
> them to lazily load data.
>
> So, instead of a Company class having a getEmployees() method, I would 
> choose, instead, to have a CompanyDao.getEmployees(Company company) 
> method that must be called at the point my webapp needs all the 
> Employees for a Company.
>
> Have any of you had the same concerns?  Or am I missing how a webapp 
> that relies on lazy-loaded object graphs can change DAO 
> implementations easily?
>
> -Ken



RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
> Sent: Wednesday, August 31, 2005 2:46 PM
> To: users@myfaces.apache.org
> Subject: Re: JSF + Spring + Hibernate
>
> I still do not see the problem of the opensessioninview filter...
> the method is totally transparent, and if you are in need for 
> a different dao layer, then simply turn it off on the pages 
> where you already have replaced the layer.
> The filter itself, just simplifies the handling of lazy 
> loaded objects in a transparent way to the programmer, so 
> that he in most cases does not have to care anymore if the 
> object is lazily bound or not.

I agree completely.

I didn't mean to imply that I think there is a problem with
OpenSesisonInView or OpenSessionInView or anything like it (I made something
similar using PhaseListener).  There is some chance that a programmer might
get into some problems with improper (according to Hibernate) use of
sessions and proxies (lazy loaded objects), but as long as you make sure
that the objects that are loaded by Hibernate have the same scope as the
Hibernate session everything works very nicely.

joshua@hibernate.org



Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Joshua Davis wrote:
> You can also use transfer objects with your DAOs, or turn lazy loading off
> for certain classes or collections that you are using as transfer objects.
> Either approach will eliminate the need for OpenSessionInView-like things
> and enable you to switch DAO implemenations.   The right choice depends on
> how much work you are willing to do in order to be able to switch DAO
> implementations.
> 
> 
I still do not see the problem of the opensessioninview filter...
the method is totally transparent, and if you are in need
for a different dao layer, then simply turn it off on the pages
where you already have replaced the layer.
The filter itself, just simplifies the handling of lazy loaded
objects in a transparent way to the programmer, so that he in most cases
does not have to care anymore if the object is lazily bound or not.

Werner


Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Ken Weiner wrote:
> The issue I was getting at was that knowing that your app has this lazy 
> loading capability, you may make different design decisions on what 
> methods go into your domain objects and what your domain object graph 
> looks like. I prefer to design the domain object graphs, keeping in mind 
> that the DAO layer would be responsible for completely loading the 
> graphs.  So if there are many Employees for a Company and you don't 
> always want to load the Employees when you load a Company, then I 
> probably wouldn't put a getEmployees() method on the Company class.  I 
> guess you could argue that it is okay to add the getEmployees() method 
> and document it so that sometimes it returns null and sometimes it 
> doesn't, but that seems undesireable to me.  I'd rather leave off the 
> method and add an extra method to a DAO that can fetch the employees for 
> a Company whenever I need them.
> 
I agree you can run into the problem, but on the other hand, the 
OpenSessionInView filter like it is implemented in Spring enforces
explicit transactions (which then can be bound via AOP) which is a plus...

But I agree, if you have the lazy loading constantly in mind you weave 
your design decisions around it, therefore I prefer to shut off my mind 
in that area....

But the problem is not really that big, because if you have to shift 
objects from one page to the next you run into the lazy issues again 
anyway, like the original poster did. I see lazy loading mainly as a big 
helper for things like master pages which have to display a table which 
goes over 3-4 objects per row and for a timesaver because you spend less 
time on the mapping scheme adjusting it to some stuff lazy and some 
stuff non lazy.

For the really hard parts the opensessioninview filter does not help at 
all anyway.
In the end, given my experience, I assume it is not too different if you 
use a lazyloading approach with an opensessioninview filter or if you 
weave your designs around an explicitely loaded object tree.

The must thing however always is, use DAOs, and if possible business 
objects with transactions woven around the accessor methods.
(A pattern which Springs OpenSessionInView filter enforces, due to the 
flush mode it sets)



Re: JSF + Spring + Hibernate

Posted by Ken Weiner <kw...@gmail.com>.
The issue I was getting at was that knowing that your app has this lazy 
loading capability, you may make different design decisions on what methods 
go into your domain objects and what your domain object graph looks like. I 
prefer to design the domain object graphs, keeping in mind that the DAO 
layer would be responsible for completely loading the graphs. So if there 
are many Employees for a Company and you don't always want to load the 
Employees when you load a Company, then I probably wouldn't put a 
getEmployees() method on the Company class. I guess you could argue that it 
is okay to add the getEmployees() method and document it so that sometimes 
it returns null and sometimes it doesn't, but that seems undesireable to me. 
I'd rather leave off the method and add an extra method to a DAO that can 
fetch the employees for a Company whenever I need them.

-Ken

On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> 
> well OpenSessionInView... is one of those rare circumstances where it
> actually makes sense, because it eases the portability and 
> implementation...
> 
> I would not say it reall is dependend on the view layer, more on the
> control layer of the server...
> It is one of those border cases...
> 
> 
> Larry Meadors wrote:
> > Heheh, are you suggesting that making your DAO layer depend upon your
> > view layer is a bad idea?
> >
> > I would have to agree....
> >
> > Larry
> >
> >
> > On 8/31/05, Ken Weiner <kw...@gmail.com> wrote:
> >
> >>I have a question about designing a webapp to use a DAO layer, lazily 
> loaded
> >>objects, Hibernate, and the OpenSessionInView technique.
> >>
> >> Doesn't this strategy make it very difficult to reimplement the DAO 
> layer
> >>sometime in the future? If you switched a DAO implementation from 
> Hibernate
> >>to let's say, Spring JDBC, then how would all the lazy loading work? 
> There
> >>would be no equivalent OpenSessionInView technique for Spring JDBC. For
> >>this reason, I have been shying away from designing my domain objects 
> such
> >>that the rest of the app expects them to lazily load data.
> >>
> >> So, instead of a Company class having a getEmployees() method, I would
> >>choose, instead, to have a CompanyDao.getEmployees(Company company) 
> method
> >>that must be called at the point my webapp needs all the Employees for a
> >>Company.
> >>
> >> Have any of you had the same concerns? Or am I missing how a webapp 
> that
> >>relies on lazy-loaded object graphs can change DAO implementations 
> easily?
> >>
> >> -Ken
> >>
> >
> >
> 
>

RE: JSF + Spring + Hibernate

Posted by Joshua Davis <pg...@yahoo.com>.
You can also use transfer objects with your DAOs, or turn lazy loading off
for certain classes or collections that you are using as transfer objects.
Either approach will eliminate the need for OpenSessionInView-like things
and enable you to switch DAO implemenations.   The right choice depends on
how much work you are willing to do in order to be able to switch DAO
implementations.

> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Werner Punz
> Sent: Wednesday, August 31, 2005 1:52 PM
> To: users@myfaces.apache.org
> Subject: Re: JSF + Spring + Hibernate
> 
> well OpenSessionInView... is one of those rare circumstances 
> where it actually makes sense, because it eases the 
> portability and implementation...
> 
> I would not say it reall is dependend on the view layer, more 
> on the control layer of the server...
> It is one of those border cases...
> 
> 
> Larry Meadors wrote:
> > Heheh, are you suggesting that making your DAO layer depend 
> upon your
> > view layer is a bad idea?
> > 
> > I would have to agree....
> > 
> > Larry
> > 
> > 
> > On 8/31/05, Ken Weiner <kw...@gmail.com> wrote:
> > 
> >>I have a question about designing a webapp to use a DAO 
> layer, lazily loaded
> >>objects, Hibernate, and the OpenSessionInView technique.
> >> 
> >> Doesn't this strategy make it very difficult to 
> reimplement the DAO layer
> >>sometime in the future?  If you switched a DAO 
> implementation from Hibernate
> >>to let's say, Spring JDBC, then how would all the lazy 
> loading work?  There
> >>would be no equivalent OpenSessionInView technique for 
> Spring JDBC.  For
> >>this reason, I have been shying away from designing my 
> domain objects such
> >>that the rest of the app expects them to lazily load data.
> >> 
> >> So, instead of a Company class having a getEmployees() 
> method, I would
> >>choose, instead, to have a CompanyDao.getEmployees(Company 
> company) method
> >>that must be called at the point my webapp needs all the 
> Employees for a
> >>Company.
> >> 
> >> Have any of you had the same concerns?  Or am I missing 
> how a webapp that
> >>relies on lazy-loaded object graphs can change DAO 
> implementations easily?
> >> 
> >> -Ken
> >>
> > 
> > 
> 
> 



Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
well OpenSessionInView... is one of those rare circumstances where it 
actually makes sense, because it eases the portability and implementation...

I would not say it reall is dependend on the view layer, more on the 
control layer of the server...
It is one of those border cases...


Larry Meadors wrote:
> Heheh, are you suggesting that making your DAO layer depend upon your
> view layer is a bad idea?
> 
> I would have to agree....
> 
> Larry
> 
> 
> On 8/31/05, Ken Weiner <kw...@gmail.com> wrote:
> 
>>I have a question about designing a webapp to use a DAO layer, lazily loaded
>>objects, Hibernate, and the OpenSessionInView technique.
>> 
>> Doesn't this strategy make it very difficult to reimplement the DAO layer
>>sometime in the future?  If you switched a DAO implementation from Hibernate
>>to let's say, Spring JDBC, then how would all the lazy loading work?  There
>>would be no equivalent OpenSessionInView technique for Spring JDBC.  For
>>this reason, I have been shying away from designing my domain objects such
>>that the rest of the app expects them to lazily load data.
>> 
>> So, instead of a Company class having a getEmployees() method, I would
>>choose, instead, to have a CompanyDao.getEmployees(Company company) method
>>that must be called at the point my webapp needs all the Employees for a
>>Company.
>> 
>> Have any of you had the same concerns?  Or am I missing how a webapp that
>>relies on lazy-loaded object graphs can change DAO implementations easily?
>> 
>> -Ken
>>
> 
> 


Re: JSF + Spring + Hibernate

Posted by Larry Meadors <la...@gmail.com>.
Heheh, are you suggesting that making your DAO layer depend upon your
view layer is a bad idea?

I would have to agree....

Larry


On 8/31/05, Ken Weiner <kw...@gmail.com> wrote:
> I have a question about designing a webapp to use a DAO layer, lazily loaded
> objects, Hibernate, and the OpenSessionInView technique.
>  
>  Doesn't this strategy make it very difficult to reimplement the DAO layer
> sometime in the future?  If you switched a DAO implementation from Hibernate
> to let's say, Spring JDBC, then how would all the lazy loading work?  There
> would be no equivalent OpenSessionInView technique for Spring JDBC.  For
> this reason, I have been shying away from designing my domain objects such
> that the rest of the app expects them to lazily load data.
>  
>  So, instead of a Company class having a getEmployees() method, I would
> choose, instead, to have a CompanyDao.getEmployees(Company company) method
> that must be called at the point my webapp needs all the Employees for a
> Company.
>  
>  Have any of you had the same concerns?  Or am I missing how a webapp that
> relies on lazy-loaded object graphs can change DAO implementations easily?
>  
>  -Ken
>

Re: JSF + Spring + Hibernate

Posted by Ken Weiner <kw...@gmail.com>.
I have a question about designing a webapp to use a DAO layer, lazily loaded 
objects, Hibernate, and the OpenSessionInView technique.

Doesn't this strategy make it very difficult to reimplement the DAO layer 
sometime in the future? If you switched a DAO implementation from Hibernate 
to let's say, Spring JDBC, then how would all the lazy loading work? There 
would be no equivalent OpenSessionInView technique for Spring JDBC. For this 
reason, I have been shying away from designing my domain objects such that 
the rest of the app expects them to lazily load data.

So, instead of a Company class having a getEmployees() method, I would 
choose, instead, to have a CompanyDao.getEmployees(Company company) method 
that must be called at the point my webapp needs all the Employees for a 
Company.

Have any of you had the same concerns? Or am I missing how a webapp that 
relies on lazy-loaded object graphs can change DAO implementations easily?

-Ken

Re: JSF + Spring + Hibernate

Posted by Rick Gruber-Riemer <ri...@vanosten.net>.
Hej everybody

Thank you very much for your responses. I have got a lot of reading stuff from 
you all (including Hibernate chapter 20 to do, and maybe I should buy a book 
on Hibernate).

I solved the problem by setting lazy="false" like Enrique (see below if you 
are a beginner like me).
OpenSessionInViewFilter did not work, but probably I made a mistake in the 
url-pattern although I changed it to *.faces (and use the hibernate3 
package). The challenge is that I have mixed code in my current project, 
where some of the data is fetched using JDBC and the newest tiny part with 
Hibernate. If a jsf-page is hit, which does not need data from Hibernate, 
then the filter casts an exception due to a missing Hibernate session. But 
this is just a configuration issue in web.xml ;-)

Regards ... Rick

<hibernate-mapping>
	<class 				
name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink"
		table="DANAFILE.SCANJOUR_LINK"
		lazy="false">
		<id name="id" type="long" column="ROW_ID">
			<meta attribute="scope-set">protected</meta>
			<generator class="sequence">
                <param name="sequence">DANAFILE.SEQNUMBER</param>
        	</generator>
        </id>
		<version column="REVISION" name="revision" />
		<property name="objId" type="string" not-null="true"/>
...
</class>
</hibernate-mapping>

Onsdag 31 august 2005 15:13 skrev Werner Punz:
> The opensessioninview filter comes with spring, somebody posted already
> a semi correct configuration (that one was for struts, you have to
> adjust the filter patterns for jsf)
>
> it is probably the easiest way you can get, to deal with lazy binding,
> it at least has solved many problems regarding the lazy flag in my
> current struts project and works perfectly.
>
> werner
>
> Rick Gruber-Riemer wrote:
> > You are right, I access the variable just in the same table in the next
> > column.
> > It seems to me, that I just have to get rid of all this lazy-stuff. Right
> > now I do not care whether this gives me some resourceproblems.
> >
> > How and where can I specify, that I want a session per database request?

Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
The opensessioninview filter comes with spring, somebody posted already 
a semi correct configuration (that one was for struts, you have to 
adjust the filter patterns for jsf)

it is probably the easiest way you can get, to deal with lazy binding,
it at least has solved many problems regarding the lazy flag in my 
current struts project and works perfectly.

werner


Rick Gruber-Riemer wrote:
> You are right, I access the variable just in the same table in the next 
> column. 
> It seems to me, that I just have to get rid of all this lazy-stuff. Right now 
> I do not care whether this gives me some resourceproblems.
> 
> How and where can I specify, that I want a session per database request?
> 


Re: JSF + Spring + Hibernate

Posted by Enrique Medina <e....@gmail.com>.
Hi again,

The OpenSessionInViewFilter from Spring already creates a new sesion per 
request, so that stuff is done automatically for you.

On the other side, just settting lazy=false where before there was lazy=true 
solves your problem, but IMHO you are getting rid of one of the most 
interesting issues of Hibernate (and an ORM tool in general). Maybe you can 
try OJB, from Apache, which does not have the concept of session and a new 
connection is created on every request ;-)

2005/8/31, Rick Gruber-Riemer <ri...@vanosten.net>:
> 
> You are right, I access the variable just in the same table in the next
> column.
> It seems to me, that I just have to get rid of all this lazy-stuff. Right 
> now
> I do not care whether this gives me some resourceproblems.
> 
> How and where can I specify, that I want a session per database request?
> 
> Regards ... Rick
> 
> 
> <t:dataTable
> id="scanJourLinksTable"
> styleClass="standardTable"
> columnClasses="list-column-left"
> headerClass="list-header-left"
> rowClasses="list-row-even, list-row-odd"
> value="#{DanafileResultPage.scanJourLinks}"
> var="links"
> >
> <h:column>
> <f:facet name="header">
> <h:outputText value=""/>
> </f:facet>
> <h:commandLink action="edit_link" immediate="true">
> <h:outputText value="#{msg.edit}" />
> <t:updateActionListener property="#{DanafileScanJourModifyPage.idLink}"
> value="#{links.id <http://links.id>}" />
> </h:commandLink>
> </h:column>
> <h:column>
> <f:facet name="header">
> <h:outputText value="#{msg.scanJourNumberLabel}"/>
> </f:facet>
> <h:outputText value="#{links.scanJourNumber}"/>
> </h:column>
> <h:column>
> <f:facet name="header">
> <h:outputText value="#{msg.notesLabel}"/>
> </f:facet>
> <t:popup styleClass="popup"
> closePopupOnExitingElement="true" closePopupOnExitingPopup="true"
> displayAtDistanceX="10" displayAtDistanceY="10" >
> <h:outputText value="#{links.notes}" />
> <f:facet name="popup">
> <h:panelGroup>
> <h:panelGrid columns="1" >
> <h:outputText value="#{links.notes}"/>
> </h:panelGrid>
> </h:panelGroup>
> </f:facet>
> </t:popup>
> </h:column>
> </t:dataTable>
> <h:form>
> <t:commandButton
> id="saveBtn"
> tabindex="4"
> value="#{msg.buttonAdd}"
> action="add_link"
> forceId="true"
> styleClass="button"
> immediate="true">
> <t:updateActionListener
> property="#{DanafileScanJourModifyPage.objIdLink}"
> value="#{DanafileResultPage.caseDocument.objId}" />
> </t:commandButton>
> </h:form>
> 
> 
> Onsdag 31 august 2005 14:38 skrev Enrique Medina:
> > I don't see it in your fragment of the JSP code, but I guess you have an 
> EL
> > accessing your lazy loaded variable inside your "links" object, haven't
> > you?
> >
> > That is the precise moment where the error should appear, as all the 
> list
> > has been created using a different Hibernate session from the one you 
> are
> > now in this request ;-)
> >
> > 2005/8/31, Rick Gruber-Riemer <ri...@vanosten.net>:
> > > Hej Martin
> > >
> > > The thing is, that this object does not even exist. At least not if I
> > > understand the meaning of a "request" the right way.
> > >
> > > What I do is:
> > > # A DAO extending HibernateDaoSupport finds all records or a record 
> with
> > > a specifc id (ScanJourLinkHbmDAO)
> > > # The Page-objects get records or a record by means of a (shared)
> > > manager-class, which has a pointer to the DAO
> > > # Then in danafileResultPage.jsf I have a table, which shows all 
> records
> > > based
> > > on DanafileResultPage.java getting the records from the database via
> > > manager
> > > and DAO
> > > # Each row in the table contains links to edit a record in a new page
> > > (danafileScanJourModifyPage.jsf). The Page object for the new page
> > > (DanafileScanJourModifyPage.java) has a property (idLink) which I 
> access
> > > via
> > > a MyFaces <t:updateActionListener> tag. Then in setIdLink(String anId) 
> I
> > > try
> > > to get the record from the database by means of the manager, which 
> then
> > > calls
> > > the DAO ...
> > > => I have no pointer to the object in either the Page, manager or DAO
> > > class.
> > > So I cannot call session.update(object) :-( And I guess that the call 
> to
> > > a new page is a new request.
> > >
> > > Am I doing something wrong?
> > >
> > > Regards ... Rick
> > >
> > > <t:dataTable
> > > id="scanJourLinksTable"
> > > styleClass="standardTable"
> > > columnClasses="list-column-left"
> > > headerClass="list-header-left"
> > > rowClasses="list-row-even, list-row-odd"
> > > value="#{DanafileResultPage.scanJourLinks}"
> > > var="links"
> > >
> > > <h:column>
> > > <f:facet name="header">
> > > <h:outputText value=""/>
> > > </f:facet>
> > > <h:commandLink action="edit_link" immediate="true">
> > > <h:outputText value="#{msg.edit}" />
> > > <t:updateActionListener property="#{DanafileScanJourModifyPage.idLink
> }"
> > > value="#{links.id <http://links.id> <http://links.id>}" />
> > > </h:commandLink>
> > > </h:column>
> > >
> > > public class DanafileScanJourModifyPage extends Page {
> > > public void setIdLink(String anId) {
> > > if (logger.isDebugEnabled()) {
> > > logger.debug("getting link with id= " + anId);
> > > }
> > > link = danafileManager.findScanJourLink(Long.valueOf(anId));
> > > setUpdating(true);
> > > } //public void setId(String)
> > >
> > > public class DanafileManager {
> > > public ScanJourLink findScanJourLink(Long id) {
> > > return scanJourLinkDAO.findScanJourLink(id);
> > > } //END public ScanJourLink findScanJourLink(Long)
> > >
> > > public class ScanJourLinkHbmDAO extends HibernateDaoSupport implements
> > > IScanJourLinkDAO {
> > > //implements IScanJourLinkDAO
> > > public ScanJourLink findScanJourLink(Long id) {
> > > ScanJourLink link = (ScanJourLink)
> > > getHibernateTemplate().load(ScanJourLink.class, id);
> > > if (null == link) {
> > > throw new ObjectRetrievalFailureException(ScanJourLink.class, id);
> > > }
> > > return link;
> > > }
> > >
> > > Onsdag 31 august 2005 12:26 skrev Martin Marinschek:
> > > > A very short hint from my side:
> > > >
> > > > that exception means this object is not in the session anymore. You
> > > > can easily reapply it to the session by calling
> > > >
> > > > session.update(object)
> > > >
> > > > If you are sure that your object has not changed since it was last 
> in
> > > > the session, you can call:
> > > >
> > > > session.lock(object, LockMode.NONE);
> > > >
> > > > regards,
> > > >
> > > > Martin
> > > >
> > > > On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> > > > > I think before giving a short answer... I will give you a detailed
> > > > > explanation via a links:
> > >
> > > 
> http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate
> > >
> > > > >%29
> > > > >
> > > > > This small article describes exactly the problems you run into and
> > > > > how to solve them...
> > > > >
> > > > > Werner
> > > > >
> > > > > Rick Gruber-Riemer wrote:
> > > > > > Hej
> > > > > >
> > > > > > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my
> > > > > > webapplication. When I get a list of records from the database 
> in a
> > > > > > table or make a new record using a form everything works fine.
> > >
> > > However
> > >
> > > > > > when I try to edit a record in a form, I get a
> > > > > > org.hibernate.LazyInitializationException error on opening the
> > > > > > editform. I understand this has something to do with the 
> Hibernate
> > > > > > sessions. And it has nothing to do with MyFaces in particular. 
> And
> > > > > > I have found some hints by googeling like Spring's
> > > > > > OpenSessionInViewFilter. However I do not have a clue what to
> > > > > > change where in the configuration.
> > > > > >
> > > > > > => Has somebody used JSF+Spring+Hibernate successfully?
> > > > > > => Downloadable sample code?
> > > > > > => Do I need the jsf-spring integration library?
> > > > > >
> > > > > > Any hint would be much appreciated ... Rick
> > > > > >
> > > > > > <hibernate-mapping>
> > > > > > <class
> > > > > > name="
> > >
> > > dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJo
> > >
> > > > > >urLink" table="DANAFILE.SCANJOUR_LINK">
> > > > > > <id name="id" type="long" column="ROW_ID">
> > > > > > <meta attribute="scope-set">protected</meta>
> > > > > > <generator class="sequence">
> > > > > > <param name="sequence">DANAFILE.SEQNUMBER</param>
> > > > > > </generator>
> > > > > > </id>
> > > > > > <version column="REVISION" name="revision" />
> > > > > > <property name="objId" type="string" not-null="true"/>
> > > > > > <property name="scanJourNumber" type="int"
> > > > > > column="SCANJOUR_NUMBER" not-null="true"/> <property 
> name="notes"
> > > > > > type="string" column="NOTES" not-null="false"/> <property
> > >
> > > name="active"
> > >
> > > > > > type="yes_no" column="ACTIVE" not-null="true" /> <property
> > > > > > name="createdBy" type="string" column="CREATED_BY"
> > > > > > not-null="true"/> <property name="lastUpdatedBy" type="string"
> > > > > > column="LAST_UPD_BY" not-null="true"/> <property 
> name="createdDate"
> > > > > > type="timestamp" column="CREATED_DT" not-null="true"/> <property
> > >
> > > name="lastUpdatedDate"
> > >
> > > > > > type="timestamp" column="LAST_UPD_DT" not-null="true"/> </class>
> > > > > > </hibernate-mapping>
> > > > > >
> > > > > > <beans>
> > > > > > <bean id="danafileHbmDS"
> > > > > > class="oracle.jdbc.pool.OracleDataSource"> <property
> > > > > > name="driverType"><value>oracle.jdbc.OracleDriver
> </value></property
> > > > > >> <property
> > > > > > name="URL"><value>jdbc:oracle:thin:@10.0.0.3
> > > :
> > > :1521:dhdvl</value></proper
> > > :
> > > > > >ty> <property name="user"><value>danafile_web</value></property>
> > > > > > <property name="password"><value>styr3ls3n</value></property>
> > >
> > > </bean>
> > >
> > > > > > <!-- Hibernate SessionFactories -->
> > > > > > <bean id="danafileHbmSF"
> > > > > > class="
> org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> > > > > > <property name="dataSource"><ref 
> local="danafileHbmDS"/></property>
> > > > > > <property name="mappingResources">
> > > > > > <list>
> > >
> > > 
> <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJ
> > >
> > > > > >ourLink.hbm.xml</value> </list>
> > > > > > </property>
> > > > > > <property name="hibernateProperties">
> > > > > > <props>
> > > > > > <prop
> > > > > > key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect
> </prop>
> > > > > > <prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
> > >
> > > <prop
> > >
> > > > > > key="hibernate.show_sql">true</prop> </props>
> > > > > > </property>
> > > > > > </bean>
> > > > > >
> > > > > > <!-- Transaction manager for a single Hibernate SessionFactory
> > > > > > (alternative to JTA) --> <bean id="transactionManager"
> > > > > > class="
> > >
> > > org.springframework.orm.hibernate3.HibernateTransactionManager">
> > >
> > > > > > <property name="sessionFactory"><ref
> > >
> > > local="danafileHbmSF"/></property>
> > >
> > > > > > </bean>
> > > > > >
> > > > > > <bean id="scanJourLinkDAO"
> > > > > > class="
> > >
> > > dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJ
> > >
> > > > > >ourLinkHbmDAO"> <property name="sessionFactory"><ref
> > > > > > local="danafileHbmSF"/></property> </bean>
> > > > > > </beans>
> > > > > >
> > > > > >
> > > > > > ERROR - LazyInitializationException.<init>(19) | could not
> > >
> > > initialize
> > >
> > > > > > proxy - the owning Session was closed
> > > > > > org.hibernate.LazyInitializationException: could not initialize
> > >
> > > proxy -
> > >
> > > > > > the owning Session was closed at
> > > > > > org.hibernate.proxy.AbstractLazyInitializer.initialize
> > >
> > > (AbstractLazyInit
> > >
> > > > > >ializer.java:53) at
> > > > > > org.hibernate.proxy.AbstractLazyInitializer.getImplementation
> > >
> > > (AbstractL
> > >
> > > > > >azyInitializer.java:84) at
> > > > > > org.hibernate.proxy.CGLIBLazyInitializer.intercept
> > >
> > > (CGLIBLazyInitializer
> > >
> > > > > >.java:134) at
> > >
> > > 
> dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink
> > >
> > > > > >$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>) at
> > > > > > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> > > > > > sun.reflect.NativeMethodAccessorImpl.invoke(
> > >
> > > NativeMethodAccessorImpl.ja
> > >
> > > > > >va:39) at
> > > > > > sun.reflect.DelegatingMethodAccessorImpl.invoke
> > >
> > > (DelegatingMethodAccesso
> > >
> > > > > >rImpl.java:25) at java.lang.reflect.Method.invoke(Method.java
> :585)
> > > > > > at
> > > > > > org.apache.myfaces.el.PropertyResolverImpl.getProperty
> > >
> > > (PropertyResolver
> > >
> > > > > >Impl.java:419) at
> > > > > > org.apache.myfaces.el.PropertyResolverImpl.getValue
> > >
> > > (PropertyResolverImp
> > >
> > > > > >l.java:104) at
> > > > > > org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate
> > >
> > > (ELParser
> > >
> > > > > >Helper.java:555) at
> > > > > > org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java
> :145)
> > >
> > > at
> > >
> > > > > > org.apache.myfaces.el.ValueBindingImpl.getValue(
> > >
> > > ValueBindingImpl.java:4
> > >
> > > > > >41)
>

Re: JSF + Spring + Hibernate

Posted by Rick Gruber-Riemer <ri...@vanosten.net>.
You are right, I access the variable just in the same table in the next 
column. 
It seems to me, that I just have to get rid of all this lazy-stuff. Right now 
I do not care whether this gives me some resourceproblems.

How and where can I specify, that I want a session per database request?

Regards ... Rick


			<t:dataTable
				id="scanJourLinksTable"
				styleClass="standardTable"
				columnClasses="list-column-left"
				headerClass="list-header-left"
				rowClasses="list-row-even, list-row-odd"
				value="#{DanafileResultPage.scanJourLinks}"
				var="links"
			>   
				<h:column>
					<f:facet name="header">
						<h:outputText value=""/>
					</f:facet>
					<h:commandLink action="edit_link" immediate="true">
						<h:outputText value="#{msg.edit}" /> 
						<t:updateActionListener property="#{DanafileScanJourModifyPage.idLink}" 
value="#{links.id}" />
					</h:commandLink>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText  value="#{msg.scanJourNumberLabel}"/>
					</f:facet>
					<h:outputText value="#{links.scanJourNumber}"/>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText  value="#{msg.notesLabel}"/>
					</f:facet>
                    <t:popup styleClass="popup" 
closePopupOnExitingElement="true" closePopupOnExitingPopup="true" 
displayAtDistanceX="10" displayAtDistanceY="10" >
                        <h:outputText value="#{links.notes}" />	
                        <f:facet name="popup">
                            <h:panelGroup>
                                <h:panelGrid columns="1" >
                                	<h:outputText value="#{links.notes}"/>
                                </h:panelGrid>
                            </h:panelGroup>
                        </f:facet>
                    </t:popup>		
				</h:column>
			</t:dataTable>
			<h:form>
				<t:commandButton
					id="saveBtn" 
					tabindex="4" 
					value="#{msg.buttonAdd}"
					action="add_link"
					forceId="true"
					styleClass="button"
					immediate="true"> 
					<t:updateActionListener
						property="#{DanafileScanJourModifyPage.objIdLink}"
						value="#{DanafileResultPage.caseDocument.objId}" />
				</t:commandButton>
			</h:form>		


Onsdag 31 august 2005 14:38 skrev Enrique Medina:
> I don't see it in your fragment of the JSP code, but I guess you have an EL
> accessing your lazy loaded variable inside your "links" object, haven't
> you?
>
> That is the precise moment where the error should appear, as all the list
> has been created using a different Hibernate session from the one you are
> now in this request ;-)
>
> 2005/8/31, Rick Gruber-Riemer <ri...@vanosten.net>:
> > Hej Martin
> >
> > The thing is, that this object does not even exist. At least not if I
> > understand the meaning of a "request" the right way.
> >
> > What I do is:
> > # A DAO extending HibernateDaoSupport finds all records or a record with
> > a specifc id (ScanJourLinkHbmDAO)
> > # The Page-objects get records or a record by means of a (shared)
> > manager-class, which has a pointer to the DAO
> > # Then in danafileResultPage.jsf I have a table, which shows all records
> > based
> > on DanafileResultPage.java getting the records from the database via
> > manager
> > and DAO
> > # Each row in the table contains links to edit a record in a new page
> > (danafileScanJourModifyPage.jsf). The Page object for the new page
> > (DanafileScanJourModifyPage.java) has a property (idLink) which I access
> > via
> > a MyFaces <t:updateActionListener> tag. Then in setIdLink(String anId) I
> > try
> > to get the record from the database by means of the manager, which then
> > calls
> > the DAO ...
> > => I have no pointer to the object in either the Page, manager or DAO
> > class.
> > So I cannot call session.update(object) :-( And I guess that the call to
> > a new page is a new request.
> >
> > Am I doing something wrong?
> >
> > Regards ... Rick
> >
> > <t:dataTable
> > id="scanJourLinksTable"
> > styleClass="standardTable"
> > columnClasses="list-column-left"
> > headerClass="list-header-left"
> > rowClasses="list-row-even, list-row-odd"
> > value="#{DanafileResultPage.scanJourLinks}"
> > var="links"
> >
> > <h:column>
> > <f:facet name="header">
> > <h:outputText value=""/>
> > </f:facet>
> > <h:commandLink action="edit_link" immediate="true">
> > <h:outputText value="#{msg.edit}" />
> > <t:updateActionListener property="#{DanafileScanJourModifyPage.idLink}"
> > value="#{links.id <http://links.id>}" />
> > </h:commandLink>
> > </h:column>
> >
> > public class DanafileScanJourModifyPage extends Page {
> > public void setIdLink(String anId) {
> > if (logger.isDebugEnabled()) {
> > logger.debug("getting link with id= " + anId);
> > }
> > link = danafileManager.findScanJourLink(Long.valueOf(anId));
> > setUpdating(true);
> > } //public void setId(String)
> >
> > public class DanafileManager {
> > public ScanJourLink findScanJourLink(Long id) {
> > return scanJourLinkDAO.findScanJourLink(id);
> > } //END public ScanJourLink findScanJourLink(Long)
> >
> > public class ScanJourLinkHbmDAO extends HibernateDaoSupport implements
> > IScanJourLinkDAO {
> > //implements IScanJourLinkDAO
> > public ScanJourLink findScanJourLink(Long id) {
> > ScanJourLink link = (ScanJourLink)
> > getHibernateTemplate().load(ScanJourLink.class, id);
> > if (null == link) {
> > throw new ObjectRetrievalFailureException(ScanJourLink.class, id);
> > }
> > return link;
> > }
> >
> > Onsdag 31 august 2005 12:26 skrev Martin Marinschek:
> > > A very short hint from my side:
> > >
> > > that exception means this object is not in the session anymore. You
> > > can easily reapply it to the session by calling
> > >
> > > session.update(object)
> > >
> > > If you are sure that your object has not changed since it was last in
> > > the session, you can call:
> > >
> > > session.lock(object, LockMode.NONE);
> > >
> > > regards,
> > >
> > > Martin
> > >
> > > On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> > > > I think before giving a short answer... I will give you a detailed
> > > > explanation via a links:
> >
> > http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate
> >
> > > >%29
> > > >
> > > > This small article describes exactly the problems you run into and
> > > > how to solve them...
> > > >
> > > > Werner
> > > >
> > > > Rick Gruber-Riemer wrote:
> > > > > Hej
> > > > >
> > > > > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my
> > > > > webapplication. When I get a list of records from the database in a
> > > > > table or make a new record using a form everything works fine.
> >
> > However
> >
> > > > > when I try to edit a record in a form, I get a
> > > > > org.hibernate.LazyInitializationException error on opening the
> > > > > editform. I understand this has something to do with the Hibernate
> > > > > sessions. And it has nothing to do with MyFaces in particular. And
> > > > > I have found some hints by googeling like Spring's
> > > > > OpenSessionInViewFilter. However I do not have a clue what to
> > > > > change where in the configuration.
> > > > >
> > > > > => Has somebody used JSF+Spring+Hibernate successfully?
> > > > > => Downloadable sample code?
> > > > > => Do I need the jsf-spring integration library?
> > > > >
> > > > > Any hint would be much appreciated ... Rick
> > > > >
> > > > > <hibernate-mapping>
> > > > > <class
> > > > > name="
> >
> > dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJo
> >
> > > > >urLink" table="DANAFILE.SCANJOUR_LINK">
> > > > > <id name="id" type="long" column="ROW_ID">
> > > > > <meta attribute="scope-set">protected</meta>
> > > > > <generator class="sequence">
> > > > > <param name="sequence">DANAFILE.SEQNUMBER</param>
> > > > > </generator>
> > > > > </id>
> > > > > <version column="REVISION" name="revision" />
> > > > > <property name="objId" type="string" not-null="true"/>
> > > > > <property name="scanJourNumber" type="int"
> > > > > column="SCANJOUR_NUMBER" not-null="true"/> <property name="notes"
> > > > > type="string" column="NOTES" not-null="false"/> <property
> >
> > name="active"
> >
> > > > > type="yes_no" column="ACTIVE" not-null="true" /> <property
> > > > > name="createdBy" type="string" column="CREATED_BY"
> > > > > not-null="true"/> <property name="lastUpdatedBy" type="string"
> > > > > column="LAST_UPD_BY" not-null="true"/> <property name="createdDate"
> > > > > type="timestamp" column="CREATED_DT" not-null="true"/> <property
> >
> > name="lastUpdatedDate"
> >
> > > > > type="timestamp" column="LAST_UPD_DT" not-null="true"/> </class>
> > > > > </hibernate-mapping>
> > > > >
> > > > > <beans>
> > > > > <bean id="danafileHbmDS"
> > > > > class="oracle.jdbc.pool.OracleDataSource"> <property
> > > > > name="driverType"><value>oracle.jdbc.OracleDriver</value></property
> > > > >> <property
> > > > > name="URL"><value>jdbc:oracle:thin:@10.0.0.3
> > :
> > :1521:dhdvl</value></proper
> > :
> > > > >ty> <property name="user"><value>danafile_web</value></property>
> > > > > <property name="password"><value>styr3ls3n</value></property>
> >
> > </bean>
> >
> > > > > <!-- Hibernate SessionFactories -->
> > > > > <bean id="danafileHbmSF"
> > > > > class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> > > > > <property name="dataSource"><ref local="danafileHbmDS"/></property>
> > > > > <property name="mappingResources">
> > > > > <list>
> >
> > <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJ
> >
> > > > >ourLink.hbm.xml</value> </list>
> > > > > </property>
> > > > > <property name="hibernateProperties">
> > > > > <props>
> > > > > <prop
> > > > > key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
> > > > > <prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
> >
> > <prop
> >
> > > > > key="hibernate.show_sql">true</prop> </props>
> > > > > </property>
> > > > > </bean>
> > > > >
> > > > > <!-- Transaction manager for a single Hibernate SessionFactory
> > > > > (alternative to JTA) --> <bean id="transactionManager"
> > > > > class="
> >
> > org.springframework.orm.hibernate3.HibernateTransactionManager">
> >
> > > > > <property name="sessionFactory"><ref
> >
> > local="danafileHbmSF"/></property>
> >
> > > > > </bean>
> > > > >
> > > > > <bean id="scanJourLinkDAO"
> > > > > class="
> >
> > dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJ
> >
> > > > >ourLinkHbmDAO"> <property name="sessionFactory"><ref
> > > > > local="danafileHbmSF"/></property> </bean>
> > > > > </beans>
> > > > >
> > > > >
> > > > > ERROR - LazyInitializationException.<init>(19) | could not
> >
> > initialize
> >
> > > > > proxy - the owning Session was closed
> > > > > org.hibernate.LazyInitializationException: could not initialize
> >
> > proxy -
> >
> > > > > the owning Session was closed at
> > > > > org.hibernate.proxy.AbstractLazyInitializer.initialize
> >
> > (AbstractLazyInit
> >
> > > > >ializer.java:53) at
> > > > > org.hibernate.proxy.AbstractLazyInitializer.getImplementation
> >
> > (AbstractL
> >
> > > > >azyInitializer.java:84) at
> > > > > org.hibernate.proxy.CGLIBLazyInitializer.intercept
> >
> > (CGLIBLazyInitializer
> >
> > > > >.java:134) at
> >
> > dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink
> >
> > > > >$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>) at
> > > > > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> > > > > sun.reflect.NativeMethodAccessorImpl.invoke(
> >
> > NativeMethodAccessorImpl.ja
> >
> > > > >va:39) at
> > > > > sun.reflect.DelegatingMethodAccessorImpl.invoke
> >
> > (DelegatingMethodAccesso
> >
> > > > >rImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585)
> > > > > at
> > > > > org.apache.myfaces.el.PropertyResolverImpl.getProperty
> >
> > (PropertyResolver
> >
> > > > >Impl.java:419) at
> > > > > org.apache.myfaces.el.PropertyResolverImpl.getValue
> >
> > (PropertyResolverImp
> >
> > > > >l.java:104) at
> > > > > org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate
> >
> > (ELParser
> >
> > > > >Helper.java:555) at
> > > > > org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
> >
> > at
> >
> > > > > org.apache.myfaces.el.ValueBindingImpl.getValue(
> >
> > ValueBindingImpl.java:4
> >
> > > > >41)

Re: JSF + Spring + Hibernate

Posted by Enrique Medina <e....@gmail.com>.
I don't see it in your fragment of the JSP code, but I guess you have an EL 
accessing your lazy loaded variable inside your "links" object, haven't you?

That is the precise moment where the error should appear, as all the list 
has been created using a different Hibernate session from the one you are 
now in this request ;-)

2005/8/31, Rick Gruber-Riemer <ri...@vanosten.net>:
> 
> Hej Martin
> 
> The thing is, that this object does not even exist. At least not if I
> understand the meaning of a "request" the right way.
> 
> What I do is:
> # A DAO extending HibernateDaoSupport finds all records or a record with a
> specifc id (ScanJourLinkHbmDAO)
> # The Page-objects get records or a record by means of a (shared)
> manager-class, which has a pointer to the DAO
> # Then in danafileResultPage.jsf I have a table, which shows all records 
> based
> on DanafileResultPage.java getting the records from the database via 
> manager
> and DAO
> # Each row in the table contains links to edit a record in a new page
> (danafileScanJourModifyPage.jsf). The Page object for the new page
> (DanafileScanJourModifyPage.java) has a property (idLink) which I access 
> via
> a MyFaces <t:updateActionListener> tag. Then in setIdLink(String anId) I 
> try
> to get the record from the database by means of the manager, which then 
> calls
> the DAO ...
> => I have no pointer to the object in either the Page, manager or DAO 
> class.
> So I cannot call session.update(object) :-( And I guess that the call to a
> new page is a new request.
> 
> Am I doing something wrong?
> 
> Regards ... Rick
> 
> <t:dataTable
> id="scanJourLinksTable"
> styleClass="standardTable"
> columnClasses="list-column-left"
> headerClass="list-header-left"
> rowClasses="list-row-even, list-row-odd"
> value="#{DanafileResultPage.scanJourLinks}"
> var="links"
> >
> <h:column>
> <f:facet name="header">
> <h:outputText value=""/>
> </f:facet>
> <h:commandLink action="edit_link" immediate="true">
> <h:outputText value="#{msg.edit}" />
> <t:updateActionListener property="#{DanafileScanJourModifyPage.idLink}"
> value="#{links.id <http://links.id>}" />
> </h:commandLink>
> </h:column>
> 
> public class DanafileScanJourModifyPage extends Page {
> public void setIdLink(String anId) {
> if (logger.isDebugEnabled()) {
> logger.debug("getting link with id= " + anId);
> }
> link = danafileManager.findScanJourLink(Long.valueOf(anId));
> setUpdating(true);
> } //public void setId(String)
> 
> public class DanafileManager {
> public ScanJourLink findScanJourLink(Long id) {
> return scanJourLinkDAO.findScanJourLink(id);
> } //END public ScanJourLink findScanJourLink(Long)
> 
> public class ScanJourLinkHbmDAO extends HibernateDaoSupport implements
> IScanJourLinkDAO {
> //implements IScanJourLinkDAO
> public ScanJourLink findScanJourLink(Long id) {
> ScanJourLink link = (ScanJourLink)
> getHibernateTemplate().load(ScanJourLink.class, id);
> if (null == link) {
> throw new ObjectRetrievalFailureException(ScanJourLink.class, id);
> }
> return link;
> }
> 
> 
> Onsdag 31 august 2005 12:26 skrev Martin Marinschek:
> 
> > A very short hint from my side:
> >
> > that exception means this object is not in the session anymore. You
> > can easily reapply it to the session by calling
> >
> > session.update(object)
> >
> > If you are sure that your object has not changed since it was last in
> > the session, you can call:
> >
> > session.lock(object, LockMode.NONE);
> >
> > regards,
> >
> > Martin
> >
> > On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> > > I think before giving a short answer... I will give you a detailed
> > > explanation via a links:
> > >
> > > 
> http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate
> > >%29
> > >
> > > This small article describes exactly the problems you run into and how
> > > to solve them...
> > >
> > > Werner
> > >
> > > Rick Gruber-Riemer wrote:
> > > > Hej
> > > >
> > > > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my
> > > > webapplication. When I get a list of records from the database in a
> > > > table or make a new record using a form everything works fine. 
> However
> > > > when I try to edit a record in a form, I get a
> > > > org.hibernate.LazyInitializationException error on opening the
> > > > editform. I understand this has something to do with the Hibernate
> > > > sessions. And it has nothing to do with MyFaces in particular. And I
> > > > have found some hints by googeling like Spring's
> > > > OpenSessionInViewFilter. However I do not have a clue what to change
> > > > where in the configuration.
> > > >
> > > > => Has somebody used JSF+Spring+Hibernate successfully?
> > > > => Downloadable sample code?
> > > > => Do I need the jsf-spring integration library?
> > > >
> > > > Any hint would be much appreciated ... Rick
> > > >
> > > > <hibernate-mapping>
> > > > <class
> > > > name="
> dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJo
> > > >urLink" table="DANAFILE.SCANJOUR_LINK">
> > > > <id name="id" type="long" column="ROW_ID">
> > > > <meta attribute="scope-set">protected</meta>
> > > > <generator class="sequence">
> > > > <param name="sequence">DANAFILE.SEQNUMBER</param>
> > > > </generator>
> > > > </id>
> > > > <version column="REVISION" name="revision" />
> > > > <property name="objId" type="string" not-null="true"/>
> > > > <property name="scanJourNumber" type="int"
> > > > column="SCANJOUR_NUMBER" not-null="true"/> <property name="notes"
> > > > type="string" column="NOTES" not-null="false"/> <property 
> name="active"
> > > > type="yes_no" column="ACTIVE" not-null="true" /> <property
> > > > name="createdBy" type="string" column="CREATED_BY" not-null="true"/>
> > > > <property name="lastUpdatedBy" type="string" column="LAST_UPD_BY"
> > > > not-null="true"/> <property name="createdDate" type="timestamp"
> > > > column="CREATED_DT" not-null="true"/> <property 
> name="lastUpdatedDate"
> > > > type="timestamp" column="LAST_UPD_DT" not-null="true"/> </class>
> > > > </hibernate-mapping>
> > > >
> > > > <beans>
> > > > <bean id="danafileHbmDS"
> > > > class="oracle.jdbc.pool.OracleDataSource"> <property
> > > > name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
> > > > <property
> > > > name="URL"><value>jdbc:oracle:thin:@10.0.0.3
> :1521:dhdvl</value></proper
> > > >ty> <property name="user"><value>danafile_web</value></property>
> > > > <property name="password"><value>styr3ls3n</value></property> 
> </bean>
> > > >
> > > > <!-- Hibernate SessionFactories -->
> > > > <bean id="danafileHbmSF"
> > > > class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> > > > <property name="dataSource"><ref local="danafileHbmDS"/></property>
> > > > <property name="mappingResources">
> > > > <list>
> > > >
> > > > 
> <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJ
> > > >ourLink.hbm.xml</value> </list>
> > > > </property>
> > > > <property name="hibernateProperties">
> > > > <props>
> > > > <prop
> > > > key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
> > > > <prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop> 
> <prop
> > > > key="hibernate.show_sql">true</prop> </props>
> > > > </property>
> > > > </bean>
> > > >
> > > > <!-- Transaction manager for a single Hibernate SessionFactory
> > > > (alternative to JTA) --> <bean id="transactionManager"
> > > > class="
> org.springframework.orm.hibernate3.HibernateTransactionManager">
> > > > <property name="sessionFactory"><ref 
> local="danafileHbmSF"/></property>
> > > > </bean>
> > > >
> > > > <bean id="scanJourLinkDAO"
> > > > class="
> dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJ
> > > >ourLinkHbmDAO"> <property name="sessionFactory"><ref
> > > > local="danafileHbmSF"/></property> </bean>
> > > > </beans>
> > > >
> > > >
> > > > ERROR - LazyInitializationException.<init>(19) | could not 
> initialize
> > > > proxy - the owning Session was closed
> > > > org.hibernate.LazyInitializationException: could not initialize 
> proxy -
> > > > the owning Session was closed at
> > > > org.hibernate.proxy.AbstractLazyInitializer.initialize
> (AbstractLazyInit
> > > >ializer.java:53) at
> > > > org.hibernate.proxy.AbstractLazyInitializer.getImplementation
> (AbstractL
> > > >azyInitializer.java:84) at
> > > > org.hibernate.proxy.CGLIBLazyInitializer.intercept
> (CGLIBLazyInitializer
> > > >.java:134) at
> > > > 
> dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink
> > > >$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>) at
> > > > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> > > > sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.ja
> > > >va:39) at
> > > > sun.reflect.DelegatingMethodAccessorImpl.invoke
> (DelegatingMethodAccesso
> > > >rImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585)
> > > > at
> > > > org.apache.myfaces.el.PropertyResolverImpl.getProperty
> (PropertyResolver
> > > >Impl.java:419) at
> > > > org.apache.myfaces.el.PropertyResolverImpl.getValue
> (PropertyResolverImp
> > > >l.java:104) at
> > > > org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate
> (ELParser
> > > >Helper.java:555) at
> > > > org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145) 
> at
> > > > org.apache.myfaces.el.ValueBindingImpl.getValue(
> ValueBindingImpl.java:4
> > > >41)
>

Re: JSF + Spring + Hibernate

Posted by Rick Gruber-Riemer <ri...@vanosten.net>.
Hej Martin

The thing is, that this object does not even exist. At least not if I 
understand the meaning of a "request" the right way.

What I do is:
# A DAO extending HibernateDaoSupport finds all records or a record with a 
specifc id (ScanJourLinkHbmDAO)
# The Page-objects get records or a record by means of a (shared) 
manager-class, which has a pointer to the DAO
# Then in danafileResultPage.jsf I have a table, which shows all records based 
on DanafileResultPage.java getting the records from the database via manager 
and DAO
# Each row in the table contains links to edit a record in a new page 
(danafileScanJourModifyPage.jsf). The Page object for the new page 
(DanafileScanJourModifyPage.java) has a property (idLink) which I access via 
a MyFaces <t:updateActionListener> tag. Then in setIdLink(String anId) I try 
to get the record from the database by means of the manager, which then calls 
the DAO ...
=> I have no pointer to the object in either the Page, manager or DAO class. 
So I cannot call session.update(object) :-( And I guess that the call to a 
new page is a new request.

Am I doing something wrong?

Regards ... Rick

<t:dataTable
	id="scanJourLinksTable"
	styleClass="standardTable"
	columnClasses="list-column-left"
	headerClass="list-header-left"
	rowClasses="list-row-even, list-row-odd"
	value="#{DanafileResultPage.scanJourLinks}"
	var="links"
>   
	<h:column>
		<f:facet name="header">
			<h:outputText value=""/>
		</f:facet>
		<h:commandLink action="edit_link" immediate="true">
			<h:outputText value="#{msg.edit}" /> 
			<t:updateActionListener property="#{DanafileScanJourModifyPage.idLink}" 
value="#{links.id}" />
		</h:commandLink>
	</h:column>

public class DanafileScanJourModifyPage extends Page {
	public void setIdLink(String anId) {
		if (logger.isDebugEnabled()) {
			logger.debug("getting link with id= " + anId);
		}
		link = danafileManager.findScanJourLink(Long.valueOf(anId));
		setUpdating(true);
	} //public void setId(String)

public class DanafileManager {	
	public ScanJourLink findScanJourLink(Long id) {
		return scanJourLinkDAO.findScanJourLink(id);
	} //END public ScanJourLink findScanJourLink(Long)

public class ScanJourLinkHbmDAO extends HibernateDaoSupport implements 
IScanJourLinkDAO {
	//implements IScanJourLinkDAO
	public ScanJourLink findScanJourLink(Long id) {
		ScanJourLink link = (ScanJourLink) 
getHibernateTemplate().load(ScanJourLink.class, id);
		if (null == link) {
			throw new ObjectRetrievalFailureException(ScanJourLink.class, id);
		}
		return link;
	}


Onsdag 31 august 2005 12:26 skrev Martin Marinschek:

> A very short hint from my side:
>
> that exception means this object is not in the session anymore. You
> can easily reapply it to the session by calling
>
> session.update(object)
>
> If you are sure that your object has not changed since it was last in
> the session, you can call:
>
> session.lock(object, LockMode.NONE);
>
> regards,
>
> Martin
>
> On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> > I think before giving a short answer... I will give you a detailed
> > explanation via a links:
> >
> > http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate
> >%29
> >
> > This small article describes exactly the problems you run into and how
> > to solve them...
> >
> > Werner
> >
> > Rick Gruber-Riemer wrote:
> > > Hej
> > >
> > > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my
> > > webapplication. When I get a list of records from the database in a
> > > table or make a new record using a form everything works fine. However
> > > when I try to edit a record in a form, I get a
> > > org.hibernate.LazyInitializationException error on opening the
> > > editform. I understand this has something to do with the Hibernate
> > > sessions. And it has nothing to do with MyFaces in particular. And I
> > > have found some hints by googeling like Spring's
> > > OpenSessionInViewFilter. However I do not have a clue what to change
> > > where in the configuration.
> > >
> > > => Has somebody used JSF+Spring+Hibernate successfully?
> > > => Downloadable sample code?
> > > => Do I need the jsf-spring integration library?
> > >
> > > Any hint would be much appreciated ... Rick
> > >
> > > <hibernate-mapping>
> > >       <class
> > > name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJo
> > >urLink" table="DANAFILE.SCANJOUR_LINK">
> > >               <id name="id" type="long" column="ROW_ID">
> > >                       <meta attribute="scope-set">protected</meta>
> > >                       <generator class="sequence">
> > >                 <param name="sequence">DANAFILE.SEQNUMBER</param>
> > >               </generator>
> > >         </id>
> > >               <version column="REVISION" name="revision" />
> > >               <property name="objId" type="string" not-null="true"/>
> > >               <property name="scanJourNumber" type="int"
> > > column="SCANJOUR_NUMBER" not-null="true"/> <property name="notes"
> > > type="string" column="NOTES" not-null="false"/> <property name="active"
> > > type="yes_no" column="ACTIVE" not-null="true" /> <property
> > > name="createdBy" type="string" column="CREATED_BY" not-null="true"/>
> > > <property name="lastUpdatedBy" type="string" column="LAST_UPD_BY"
> > > not-null="true"/> <property name="createdDate" type="timestamp"
> > > column="CREATED_DT" not-null="true"/> <property name="lastUpdatedDate"
> > > type="timestamp" column="LAST_UPD_DT" not-null="true"/> </class>
> > > </hibernate-mapping>
> > >
> > > <beans>
> > >       <bean id="danafileHbmDS"
> > > class="oracle.jdbc.pool.OracleDataSource"> <property
> > > name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
> > > <property
> > > name="URL"><value>jdbc:oracle:thin:@10.0.0.3:1521:dhdvl</value></proper
> > >ty> <property name="user"><value>danafile_web</value></property>
> > > <property name="password"><value>styr3ls3n</value></property> </bean>
> > >
> > >       <!-- Hibernate SessionFactories -->
> > >       <bean id="danafileHbmSF"
> > > class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> > > <property name="dataSource"><ref local="danafileHbmDS"/></property>
> > > <property name="mappingResources">
> > >                       <list>
> > >                              
> > > <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJ
> > >ourLink.hbm.xml</value> </list>
> > >               </property>
> > >               <property name="hibernateProperties">
> > >                       <props>
> > >                               <prop
> > > key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
> > > <prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop> <prop
> > > key="hibernate.show_sql">true</prop> </props>
> > >               </property>
> > >       </bean>
> > >
> > >       <!-- Transaction manager for a single Hibernate SessionFactory
> > > (alternative to JTA) --> <bean id="transactionManager"
> > > class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> > > <property name="sessionFactory"><ref local="danafileHbmSF"/></property>
> > > </bean>
> > >
> > >       <bean id="scanJourLinkDAO"
> > > class="dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJ
> > >ourLinkHbmDAO"> <property name="sessionFactory"><ref
> > > local="danafileHbmSF"/></property> </bean>
> > > </beans>
> > >
> > >
> > > ERROR - LazyInitializationException.<init>(19) | could not initialize
> > > proxy - the owning Session was closed
> > > org.hibernate.LazyInitializationException: could not initialize proxy -
> > > the owning Session was closed at
> > > org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInit
> > >ializer.java:53) at
> > > org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractL
> > >azyInitializer.java:84) at
> > > org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer
> > >.java:134) at
> > > dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink
> > >$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>) at
> > > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
> > >va:39) at
> > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
> > >rImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585)
> > >         at
> > > org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolver
> > >Impl.java:419) at
> > > org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImp
> > >l.java:104) at
> > > org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParser
> > >Helper.java:555) at
> > > org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145) at
> > > org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:4
> > >41)

Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
Martin Marinschek wrote:
> A very short hint from my side:
> 
> that exception means this object is not in the session anymore. You
> can easily reapply it to the session by calling
> 
> session.update(object)
>

update is sort of problematic unless you really want to write
unless you do transactioning...
the better option would be to prefetch the affected parts
so that you do not run into lazy loading issues
over session boundaries.

To my experience, the OpenSessionInViewFilter, covers most problems in 
these areas anyway because usually you only need the data you show or at 
least reference in one form, in the next one, and fore the few
cases you do not need, a lazy false or object reload or bind does it.

the spring OpenSessionInViewFilterfilter has another nice sideeffect it 
forces you to use dedicated transactions if you want to write, otherwise 
it refuses to write.





Re: JSF + Spring + Hibernate

Posted by Martin Marinschek <ma...@gmail.com>.
A very short hint from my side:

that exception means this object is not in the session anymore. You
can easily reapply it to the session by calling

session.update(object)

If you are sure that your object has not changed since it was last in
the session, you can call:

session.lock(object, LockMode.NONE);

regards,

Martin

On 8/31/05, Werner Punz <we...@gmx.at> wrote:
> I think before giving a short answer... I will give you a detailed
> explanation via a links:
> 
> http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate%29
> 
> This small article describes exactly the problems you run into and how
> to solve them...
> 
> Werner
> 
> 
> 
> Rick Gruber-Riemer wrote:
> > Hej
> >
> > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my webapplication. When I get a list of records from the database in a table or make a new record using a form everything works fine. However when I try to edit a record in a form, I get a org.hibernate.LazyInitializationException error on opening the editform.
> > I understand this has something to do with the Hibernate sessions. And it has nothing to do with MyFaces in particular. And I have found some hints by googeling like Spring's OpenSessionInViewFilter. However I do not have a clue what to change where in the configuration.
> >
> > => Has somebody used JSF+Spring+Hibernate successfully?
> > => Downloadable sample code?
> > => Do I need the jsf-spring integration library?
> >
> > Any hint would be much appreciated ... Rick
> >
> > <hibernate-mapping>
> >       <class name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink"
> >               table="DANAFILE.SCANJOUR_LINK">
> >               <id name="id" type="long" column="ROW_ID">
> >                       <meta attribute="scope-set">protected</meta>
> >                       <generator class="sequence">
> >                 <param name="sequence">DANAFILE.SEQNUMBER</param>
> >               </generator>
> >         </id>
> >               <version column="REVISION" name="revision" />
> >               <property name="objId" type="string" not-null="true"/>
> >               <property name="scanJourNumber" type="int" column="SCANJOUR_NUMBER" not-null="true"/>
> >               <property name="notes" type="string" column="NOTES" not-null="false"/>
> >               <property name="active" type="yes_no" column="ACTIVE" not-null="true" />
> >               <property name="createdBy" type="string" column="CREATED_BY" not-null="true"/>
> >               <property name="lastUpdatedBy" type="string" column="LAST_UPD_BY" not-null="true"/>
> >               <property name="createdDate" type="timestamp" column="CREATED_DT" not-null="true"/>
> >               <property name="lastUpdatedDate" type="timestamp" column="LAST_UPD_DT" not-null="true"/>
> >       </class>
> > </hibernate-mapping>
> >
> > <beans>
> >       <bean id="danafileHbmDS" class="oracle.jdbc.pool.OracleDataSource">
> >               <property name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
> >               <property name="URL"><value>jdbc:oracle:thin:@10.0.0.3:1521:dhdvl</value></property>
> >               <property name="user"><value>danafile_web</value></property>
> >               <property name="password"><value>styr3ls3n</value></property>
> >       </bean>
> >
> >       <!-- Hibernate SessionFactories -->
> >       <bean id="danafileHbmSF" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> >               <property name="dataSource"><ref local="danafileHbmDS"/></property>
> >               <property name="mappingResources">
> >                       <list>
> >                               <value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLink.hbm.xml</value>
> >                       </list>
> >               </property>
> >               <property name="hibernateProperties">
> >                       <props>
> >                               <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
> >                               <prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
> >                               <prop key="hibernate.show_sql">true</prop>
> >                       </props>
> >               </property>
> >       </bean>
> >
> >       <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
> >       <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> >               <property name="sessionFactory"><ref local="danafileHbmSF"/></property>
> >       </bean>
> >
> >       <bean id="scanJourLinkDAO" class="dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLinkHbmDAO">
> >               <property name="sessionFactory"><ref local="danafileHbmSF"/></property>
> >       </bean>
> > </beans>
> >
> >
> > ERROR - LazyInitializationException.<init>(19) | could not initialize proxy - the owning Session was closed
> > org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
> >         at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
> >         at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
> >         at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
> >         at dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>)
> >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >         at java.lang.reflect.Method.invoke(Method.java:585)
> >         at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:419)
> >         at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:104)
> >         at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:555)
> >         at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
> >         at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:441)
> >
> >
> 
> 


-- 

http://www.irian.at
Your JSF powerhouse - 
JSF Trainings in English and German

Re: JSF + Spring + Hibernate

Posted by Werner Punz <we...@gmx.at>.
I think before giving a short answer... I will give you a detailed 
explanation via a links:

http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate%29

This small article describes exactly the problems you run into and how 
to solve them...

Werner



Rick Gruber-Riemer wrote:
> Hej
> 
> I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my webapplication. When I get a list of records from the database in a table or make a new record using a form everything works fine. However when I try to edit a record in a form, I get a org.hibernate.LazyInitializationException error on opening the editform.
> I understand this has something to do with the Hibernate sessions. And it has nothing to do with MyFaces in particular. And I have found some hints by googeling like Spring's OpenSessionInViewFilter. However I do not have a clue what to change where in the configuration.
> 
> => Has somebody used JSF+Spring+Hibernate successfully?
> => Downloadable sample code?
> => Do I need the jsf-spring integration library?
> 
> Any hint would be much appreciated ... Rick
> 
> <hibernate-mapping>
> 	<class name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink"
> 		table="DANAFILE.SCANJOUR_LINK">
> 		<id name="id" type="long" column="ROW_ID">
> 			<meta attribute="scope-set">protected</meta>
> 			<generator class="sequence">
>                 <param name="sequence">DANAFILE.SEQNUMBER</param>
>         	</generator>
>         </id>
> 		<version column="REVISION" name="revision" />
> 		<property name="objId" type="string" not-null="true"/>
> 		<property name="scanJourNumber" type="int" column="SCANJOUR_NUMBER" not-null="true"/>
> 		<property name="notes" type="string" column="NOTES" not-null="false"/>
> 		<property name="active" type="yes_no" column="ACTIVE" not-null="true" />
> 		<property name="createdBy" type="string" column="CREATED_BY" not-null="true"/>
> 		<property name="lastUpdatedBy" type="string" column="LAST_UPD_BY" not-null="true"/>
> 		<property name="createdDate" type="timestamp" column="CREATED_DT" not-null="true"/>
> 		<property name="lastUpdatedDate" type="timestamp" column="LAST_UPD_DT" not-null="true"/>		
> 	</class>
> </hibernate-mapping>
> 
> <beans>
> 	<bean id="danafileHbmDS" class="oracle.jdbc.pool.OracleDataSource">
> 		<property name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
> 		<property name="URL"><value>jdbc:oracle:thin:@10.0.0.3:1521:dhdvl</value></property>
> 		<property name="user"><value>danafile_web</value></property>
> 		<property name="password"><value>styr3ls3n</value></property>
> 	</bean>
> 	
> 	<!-- Hibernate SessionFactories -->
> 	<bean id="danafileHbmSF" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> 		<property name="dataSource"><ref local="danafileHbmDS"/></property>
> 		<property name="mappingResources">
> 			<list>
> 				<value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLink.hbm.xml</value>
> 			</list>
> 		</property>
> 		<property name="hibernateProperties">
> 			<props>
> 				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
> 				<prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
> 				<prop key="hibernate.show_sql">true</prop>
> 			</props>
> 		</property>
> 	</bean>
> 
> 	<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
> 	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> 		<property name="sessionFactory"><ref local="danafileHbmSF"/></property>
> 	</bean>
> 		
> 	<bean id="scanJourLinkDAO" class="dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLinkHbmDAO">
> 		<property name="sessionFactory"><ref local="danafileHbmSF"/></property>
> 	</bean>
> </beans>
> 
> 
> ERROR - LazyInitializationException.<init>(19) | could not initialize proxy - the owning Session was closed
> org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
>         at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
>         at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
>         at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
>         at dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:419)
>         at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:104)
>         at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:555)
>         at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
>         at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:441)
>   
> 


Re: JSF + Spring + Hibernate

Posted by Enrique Medina <e....@gmail.com>.
But Dave, you are not using lazy loading, are you?

The big problems appear when using lazy loading and objects are not 
initialized in the same Hibernate session...

2005/8/31, Dave Brondsema <da...@brondsema.net>:
> 
> Rick Gruber-Riemer wrote:
> > Hej
> >
> > I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my 
> webapplication. When I get a list of records from the database in a table or 
> make a new record using a form everything works fine. However when I try to 
> edit a record in a form, I get a org.hibernate.LazyInitializationExceptionerror on opening the editform.
> > I understand this has something to do with the Hibernate sessions. And 
> it has nothing to do with MyFaces in particular. And I have found some hints 
> by googeling like Spring's OpenSessionInViewFilter. However I do not have a 
> clue what to change where in the configuration.
> >
> > => Has somebody used JSF+Spring+Hibernate successfully?
> > => Downloadable sample code?
> > => Do I need the jsf-spring integration library?
> >
> > Any hint would be much appreciated ... Rick
> >
> 
> I'm using Hibernate 3.1 annotations, but I'm sure you can do this
> without annotation syntax. The code that follows is a "Menu" object
> with a unique key by date.
> 
> My DTO object is annotated like this:
> @Table(name = "tblFoodServiceMenu")
> @org.hibernate.annotations.Proxy(lazy = false)
> public class Menu implements Serializable {
> ...
> 
> 
> I don't use OpenSessionInViewFilter
> 
> 
> The DTOs are loaded with this DAO class:
> public class MenuDAO extends HibernateDaoSupport {
> private final Log log = LogFactory.getLog(getClass().getName());
> 
> public Menu getMenu(Date date) {
> log.trace("creating object for key: " + date);
> try {
> return (Menu) getHibernateTemplate().load(Menu.class, date);
> } catch (DataAccessException e) {
> log.debug("detected that no object found");
> return null;
> }
> }
> 
> public void saveMenu(Menu menu) {
> log.trace("saving object with key: " + menu.date);
> getHibernateTemplate().saveOrUpdate(menu);
> }
> }
> 
> 
> 
> applicationContext.xml has:
> <bean id="dataSource" ...
> </bean>
> 
> <!-- Hibernate SessionFactory Definition -->
> <bean id="sessionFactory"
> class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> <property name="configLocation">
> <value>/WEB-INF/classes/hibernate.cfg.xml</value>
> </property>
> <property name="configurationClass">
> <value>org.hibernate.cfg.AnnotationConfiguration</value>
> </property>
> <property name="dataSource">
> <ref bean="dataSource"/>
> </property>
> </bean>
> 
> <!-- Spring Data Access Exception Translator Defintion -->
> <bean id="jdbcExceptionTranslator"
> class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
> ">
> 
> <property name="dataSource"><ref bean="dataSource"/></property>
> </bean>
> 
> <!-- Hibernate Template Defintion -->
> <bean id="hibernateTemplate"
> class="org.springframework.orm.hibernate3.HibernateTemplate">
> <property name="sessionFactory"><ref bean="sessionFactory"/></property>
> <property name="jdbcExceptionTranslator"><ref
> bean="jdbcExceptionTranslator"/></property>
> </bean>
> 
> <!-- User DAO object: Hibernate implementation -->
> <bean id="menuDao" class="my.package.model.MenuDAO">
> <property name="hibernateTemplate"><ref
> bean="hibernateTemplate"/></property>
> </bean>
> 
> 
> 
> And the Menu backing bean has a managed property which points to a
> service locator class (that class connects to the spring container, but
> I intend to switch to the jsf-spring library soon). Then in the
> backing bean it has this method which loads a Menu:
> public void setDate(Date date) {
> if (date != null) {
> this.date = date;
> menu = menuDao.getMenu(date);
> if (menu == null) {
> menu = new Menu();
> menu.setDate(date);
> }
> } else {
> log.debug("ignoring setDate(null)");
> }
> }
> 
> Hope that helps! Took me a while to figure out
> 
> --
> Dave Brondsema
> Software Developer
> Cornerstone University
> 
> 
>

Re: JSF + Spring + Hibernate

Posted by Dave Brondsema <da...@brondsema.net>.
Rick Gruber-Riemer wrote:
> Hej
> 
> I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my webapplication. When I get a list of records from the database in a table or make a new record using a form everything works fine. However when I try to edit a record in a form, I get a org.hibernate.LazyInitializationException error on opening the editform.
> I understand this has something to do with the Hibernate sessions. And it has nothing to do with MyFaces in particular. And I have found some hints by googeling like Spring's OpenSessionInViewFilter. However I do not have a clue what to change where in the configuration.
> 
> => Has somebody used JSF+Spring+Hibernate successfully?
> => Downloadable sample code?
> => Do I need the jsf-spring integration library?
> 
> Any hint would be much appreciated ... Rick
> 

I'm using Hibernate 3.1 annotations, but I'm sure you can do this
without annotation syntax.  The code that follows is a "Menu" object
with a unique key by date.

My DTO object is annotated like this:
@Table(name = "tblFoodServiceMenu")
@org.hibernate.annotations.Proxy(lazy = false)
public class Menu implements Serializable {
...


I don't use OpenSessionInViewFilter


The DTOs are loaded with this DAO class:
public class MenuDAO extends HibernateDaoSupport {
	private final Log log = LogFactory.getLog(getClass().getName());
	
	public Menu getMenu(Date date) {
		log.trace("creating object for key: " + date);
		try {
			return (Menu) getHibernateTemplate().load(Menu.class, date);
		} catch (DataAccessException e) {
			log.debug("detected that no object found");
			return null;
		}
	}

	public void saveMenu(Menu menu) {
		log.trace("saving object with key: " + menu.date);
		getHibernateTemplate().saveOrUpdate(menu);
	}
}



applicationContext.xml has:
<bean id="dataSource" ...
</bean>

<!-- Hibernate SessionFactory Definition -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation">
        <value>/WEB-INF/classes/hibernate.cfg.xml</value>
    </property>
    <property name="configurationClass">
        <value>org.hibernate.cfg.AnnotationConfiguration</value>
    </property>
    <property name="dataSource">
        <ref bean="dataSource"/>
    </property>
</bean>

<!-- Spring Data Access Exception Translator Defintion -->
<bean id="jdbcExceptionTranslator"
class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">

    <property name="dataSource"><ref bean="dataSource"/></property>
</bean>

<!-- Hibernate Template Defintion -->
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    <property name="jdbcExceptionTranslator"><ref
bean="jdbcExceptionTranslator"/></property>
</bean>

<!-- User DAO object: Hibernate implementation -->
<bean id="menuDao" class="my.package.model.MenuDAO">
    <property name="hibernateTemplate"><ref
bean="hibernateTemplate"/></property>
</bean>



And the Menu backing bean has a managed property which points to a
service locator class (that class connects to the spring container, but
I intend to switch to the jsf-spring library soon).   Then in the
backing bean it has this method which loads a Menu:
	public void setDate(Date date) {
		if (date != null) {
			this.date = date;
			menu = menuDao.getMenu(date);
			if (menu == null) {
				menu = new Menu();
				menu.setDate(date);
			}
		} else {
			log.debug("ignoring setDate(null)");
		}
	}

Hope that helps!  Took me a while to figure out

-- 
Dave Brondsema
Software Developer
Cornerstone University

AW: JSF + Spring + Hibernate

Posted by Rene Guenther <re...@innflow.com>.
=> Downloadable sample code?

Just want to mention: 
http://raibledesigns.com/wiki/Wiki.jsp?page=AppFuse

It’s the base of the application I am currently developing.

René


-----Ursprüngliche Nachricht-----
Von: Rick Gruber-Riemer [mailto:rick@vanosten.net] 
Gesendet: Mittwoch, 31. August 2005 12:12
An: users@myfaces.apache.org
Betreff: JSF + Spring + Hibernate

Hej

I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my
webapplication. When I get a list of records from the database in a table or
make a new record using a form everything works fine. However when I try to
edit a record in a form, I get a org.hibernate.LazyInitializationException
error on opening the editform.
I understand this has something to do with the Hibernate sessions. And it
has nothing to do with MyFaces in particular. And I have found some hints by
googeling like Spring's OpenSessionInViewFilter. However I do not have a
clue what to change where in the configuration.

=> Has somebody used JSF+Spring+Hibernate successfully?
=> Downloadable sample code?
=> Do I need the jsf-spring integration library?