-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: session factory over riden
PostPosted: Tue Mar 06, 2007 6:05 am 
Beginner
Beginner

Joined: Mon Feb 05, 2007 2:33 am
Posts: 32
Hibernate version:[/3.0]

[b]Mapping documents:

Struts-config.xml

<plug-in className="progasus.crm.plugin.CrmPlugIn">
<set-property property="configFilePath1" value="/crm.cfg.xml" />
</plug-in>

<plug-in className="roseindia.net.plugin.HibernatePlugIn">
<set-property property="configFilePath" value="/b2c.cfg.xml" />
</plug-in>

[b]Code between sessionFactory.openSession() and session.close():

[b]Crmplugin.java file


package progasus.crm.plugin;

import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.HibernateException;


public class CrmPlugIn implements PlugIn {
private String _configFilePath = "/crm.cfg.xml";

/**
* the key under which the <code>SessionFactory</code> instance is stored
* in the <code>ServletContext</code>.
*/
public static final String SESSION_FACTORY_KEY
= SessionFactory.class.getName();

private SessionFactory _factory = null;

public void destroy() {
try{
_factory.close();
}catch(HibernateException e){
System.out.println("Unable to close Hibernate Session Factory: " + e.getMessage());
}

}

public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
System.out.println("*************************************");
System.out.println("**** Initilizing CRM CrmPlugIn **********");
Configuration configuration = null;
URL configFileURL = null;
ServletContext context = null;

try{
configFileURL = CrmPlugIn.class.getResource(_configFilePath);
context = servlet.getServletContext();
configuration = (new Configuration()).configure(configFileURL);
_factory = configuration.buildSessionFactory();
//Set the factory into session
context.setAttribute(SESSION_FACTORY_KEY, _factory);

}catch(HibernateException e){
System.out.println("Error while initializing hibernate: " + e.getMessage());
}
System.out.println("*************************************");

}

/**
* Setter for property configFilePath.
* @param configFilePath New value of property configFilePath.
*/
public void setConfigFilePath(String configFilePath) {
if ((configFilePath == null) || (configFilePath.trim().length() == 0)) {
throw new IllegalArgumentException(
"configFilePath cannot be blank or null.");
}

System.out.println("Setting 'configFilePath' to '" + configFilePath + "'...");
_configFilePath = configFilePath;
}


/*(SessionFactory) servletContext.getAttribute
(CrmPlugIn.SESSION_FACTORY_KEY);
*/

}

hibernateplugin.java

package roseindia.net.plugin;

import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.HibernateException;


public class HibernatePlugIn implements PlugIn {
private String _configFilePath = "/tutorial.cfg.xml";

/**
* the key under which the <code>SessionFactory</code> instance is stored
* in the <code>ServletContext</code>.
*/
public static final String SESSION_FACTORY_B2C
= SessionFactory.class.getName();

private SessionFactory _factory = null;

public void destroy() {
try{
_factory.close();
}catch(HibernateException e){
System.out.println("Unable to close Hibernate Session Factory: " + e.getMessage());
}

}

public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
System.out.println("*************************************");
System.out.println("**** Initilizing HibernatePlugIn **********");
System.out.println("tutorial1");
Configuration configuration = null;
URL configFileURL = null;
ServletContext context = null;

try{
configFileURL = HibernatePlugIn.class.getResource(_configFilePath);


context = servlet.getServletContext();

configuration = (new Configuration()).configure(configFileURL);
System.out.println("tutorial2");
_factory = configuration.buildSessionFactory();
//Set the factory into session
context.setAttribute(SESSION_FACTORY_B2C, _factory);

}catch(HibernateException e){
System.out.println("Error while initializing hibernate: " + e.getMessage());
}
System.out.println("*************************************");

}

/**
* Setter for property configFilePath.
* @param configFilePath New value of property configFilePath.
*/
public void setConfigFilePath(String configFilePath) {
if ((configFilePath == null) || (configFilePath.trim().length() == 0)) {
throw new IllegalArgumentException(
"configFilePath cannot be blank or null.");
}

System.out.println("Setting 'configFilePath' to '" + configFilePath + "'...");
_configFilePath = configFilePath;
}


/*(SessionFactory) servletContext.getAttribute
(HibernatePlugIn.SESSION_FACTORY_KEY);
*/

}


Full stack trace of any exception that occurs:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: could not execute query
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

org.hibernate.exception.SQLGrammarException: could not execute query
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.loader.Loader.doList(Loader.java:2153)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
org.hibernate.loader.Loader.list(Loader.java:2024)
org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:117)
org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1672)
org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:147)
org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169)
progasus.crm.core.model.ModelValues.values(ModelValues.java:43)
org.apache.jsp.pages.model.model_jsp._jspService(org.apache.jsp.pages.model.model_jsp:352)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.9



Name and version of the database you are using: mysql

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


While i initialize the project the both plugin files are executed and the session factory is created.

but when i am trying to access the session factory of the first one then it throughs the exception



if only one session factory is created the query is working fine

whats the problem i am unable to identify please help me


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.