You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anoop <an...@gmail.com> on 2008/10/15 05:04:48 UTC
Hibernate and Struts
Hi,
We are looking forward to integrating struts with hibernate in our web
application project. Could you guide us on how to to integrate them. I
tried the hibernate plugin as recommended on the hibernate website,
however that throws a null pointer exception(when i try to instantiate
a session) when i test it in tomcat.
Relevant piece of code
in struts-config.xml
<plug-in
className="de.laliluna.hibernate.plugin.HibernatePlugIn">
<set-property
property="configFilePath"
value="/hibernate.cfg.xml" />
<set-property
property="storeInServletContext"
value="true" />
In struts action
try{ServletContext context = request.getSession().getServletContext();
SessionFactory _factory = (SessionFactory)
context.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);
Session ses = _factory.openSession(); <---this line throws exception
--
Anoop Dhanvijay
DA-IICT
"Most of man's failures were when they didn't realize how close they
were to success, when they finally gave up!"
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Hibernate and Struts
Posted by Hardik Shah <ha...@yahoo.com>.
hope this help to you http://hardik4u.wordpress.com
Anoop-9 wrote:
>
> Hi,
> We are looking forward to integrating struts with hibernate in our web
> application project. Could you guide us on how to to integrate them. I
> tried the hibernate plugin as recommended on the hibernate website,
> however that throws a null pointer exception(when i try to instantiate
> a session) when i test it in tomcat.
>
> Relevant piece of code
> in struts-config.xml
> <plug-in
> className="de.laliluna.hibernate.plugin.HibernatePlugIn">
> <set-property
> property="configFilePath"
> value="/hibernate.cfg.xml" />
> <set-property
> property="storeInServletContext"
> value="true" />
>
> In struts action
> try{ServletContext context = request.getSession().getServletContext();
> SessionFactory _factory = (SessionFactory)
> context.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);
> Session ses = _factory.openSession(); <---this line throws exception
> --
> Anoop Dhanvijay
> DA-IICT
>
> "Most of man's failures were when they didn't realize how close they
> were to success, when they finally gave up!"
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Hibernate-and-Struts-tp19985981p20009546.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Hibernate and Struts
Posted by Mead Lai <la...@gmail.com>.
haven't use this plug before.
but I think Spring-plug-in, would be better!
It's less config!
On Wed, Oct 15, 2008 at 11:04 AM, Anoop <an...@gmail.com> wrote:
> Hi,
> We are looking forward to integrating struts with hibernate in our web
> application project. Could you guide us on how to to integrate them. I
> tried the hibernate plugin as recommended on the hibernate website,
> however that throws a null pointer exception(when i try to instantiate
> a session) when i test it in tomcat.
>
> Relevant piece of code
> in struts-config.xml
> <plug-in
>
> className="de.laliluna.hibernate.plugin.HibernatePlugIn">
> <set-property
> property="configFilePath"
> value="/hibernate.cfg.xml" />
> <set-property
> property="storeInServletContext"
> value="true" />
>
> In struts action
> try{ServletContext context = request.getSession().getServletContext();
> SessionFactory _factory = (SessionFactory)
>
> context.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);
> Session ses = _factory.openSession(); <---this line
> throws exception
> --
> Anoop Dhanvijay
> DA-IICT
>
> "Most of man's failures were when they didn't realize how close they
> were to success, when they finally gave up!"
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
BestRegards,
Mead
http://yayisoft.com
Helen Hayes - "Age is not important unless you're a cheese."
Re: Hibernate and Struts
Posted by Anoop <an...@gmail.com>.
I did try this as you told but I am still getting the exception.
Anyways to get a solution to that. I think this is a widespread
problem(having gone through the forums), is there any other way. I am
also looking to test this finally on Webshpere so are there some
issues there?
On 10/17/08, jygnash <jy...@aol.com> wrote:
>
> Hi Anoop,
>
> YOu can use the JNDI context to get the Hibernate's SessionFactory.
> 1)
> in hibernate-cfg.xml give the jndi name as below
> <hibernate-configuration>
> <session-factory name="HibernateSessionFactory">
> 2)
> in one of your startup servlet or first class handling the request for
> session factory creation (we had a start up servlet) , you can have the
> session factory created and made avialable
> try {
> //Create the SessionFactory from hibernate.cfg.xml
> sessionFactory = new Configuration().configure().buildSessionFactory();
>
> } catch (Throwable ex) {
> // Make sure you log the exception, as it might be swallowed
> System.err.println("Initial SessionFactory creation failed." + ex);
> throw new ExceptionInInitializerError(ex);
> }
>
> 3)
> //in rest of classes which needs the hibernate session factory can get it
> from JNDI
>
> InitialContext ctx = new InitialContext();
> SessionFactory sessionFactory = (SessionFactory)
> ctx.lookup("HibernateSessionFactory");
> session = sessionFactory.openSession(); //.getCurrentSession();
>
>
> hope that helps
>
> --
> View this message in context:
> http://www.nabble.com/Hibernate-and-Struts-tp19985981p20016169.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Anoop Dhanvijay
DA-IICT
"Most of man's failures were when they didn't realize how close they
were to success, when they finally gave up!"
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Hibernate and Struts
Posted by jygnash <jy...@aol.com>.
Hi Anoop,
YOu can use the JNDI context to get the Hibernate's SessionFactory.
1)
in hibernate-cfg.xml give the jndi name as below
<hibernate-configuration>
<session-factory name="HibernateSessionFactory">
2)
in one of your startup servlet or first class handling the request for
session factory creation (we had a start up servlet) , you can have the
session factory created and made avialable
try {
//Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
3)
//in rest of classes which needs the hibernate session factory can get it
from JNDI
InitialContext ctx = new InitialContext();
SessionFactory sessionFactory = (SessionFactory)
ctx.lookup("HibernateSessionFactory");
session = sessionFactory.openSession(); //.getCurrentSession();
hope that helps
--
View this message in context: http://www.nabble.com/Hibernate-and-Struts-tp19985981p20016169.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org