-->
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.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.exception.SQLGrammarException
PostPosted: Sat Aug 25, 2007 2:26 pm 
Beginner
Beginner

Joined: Wed Jul 18, 2007 7:38 am
Posts: 23
i am new to hibernate so please clear my exception when i try to use jsf with hibernate i am getting this exception.

Exception:



HTTP Status 500 -

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

type Exception report

message

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

exception

javax.servlet.ServletException: #{login.addManager}: javax.faces.el.EvaluationException: org.hibernate.exception.SQLGrammarException: Cannot open connection
javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)


root cause

javax.faces.FacesException: #{login.addManager}: javax.faces.el.EvaluationException: org.hibernate.exception.SQLGrammarException: Cannot open connection
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)


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


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

Apache Tomcat/5.5.17




Login.jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title></title>
</head>
<body>
<f:view>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="UserName" />
<h:inputText value="#{login1.id}" />
<h:outputText value="Password"/>
<h:inputText value="#{login1.passwd}" />
<h:commandButton action="#{login1.addManager}" value="Submit" />
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>


LoginManager.java


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class LoginManager
{
public LoginManager(int id,String Password)
{
Session session = null;

try
{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record1");
Login contact = new Login();
System.out.println("Inserting");

//contact.setFirstName("shiva");
contact.setId(id);
contact.setPasswd(Password);
session.save(contact);

System.out.println("Done2");
}
catch(Exception e)
{
System.out.println("Error"+e);
}
finally
{
// Actual contact insertion will happen at this step
session.beginTransaction().commit();
session.flush();
session.close();

}

}


public static void main(String[] args)
{
new LoginManager(1,"ss");
}
}


Top
 Profile  
 
 Post subject: try Transaction tx = null;
PostPosted: Sun Aug 26, 2007 7:58 am 
Newbie

Joined: Mon Aug 20, 2007 5:18 am
Posts: 8
you can try to deifne Transaction tx = null;
tx = session.beginTransaction();

your sql


tx.commit();

rather than using session.commit()....


you can also check hibernate.cfg.xml path. it should be correct....


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

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.