wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate " Watch "hibernate " New topic
Author

hibernate

jyothi babu
Greenhorn

Joined: Mar 26, 2013
Posts: 2
Hi I m new to hibernate..im writing a program to show the details of the employee stored in the database.but im getting this error...

ERROR:

SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 8 in the generated java file
Only a type can be imported. org.hibernate.cfg.Configuration resolves to a package

An error occurred at line: 9 in the generated java file
Only a type can be imported. org.hibernate.SessionFactory resolves to a package

An error occurred at line: 10 in the generated java file
Only a type can be imported. org.hibernate.Session resolves to a package

An error occurred at line: 11 in the generated java file
Only a type can be imported. org.hibernate.Query resolves to a package

An error occurred at line: 13 in the jsp file: /Show.jsp
Session cannot be resolved to a type
10: <%!int id;
11: double sal;
12: String name;
13: Session session1 = null;%>
14: <body>
15: <table width="220" border="1">
16: <tr>


An error occurred at line: 22 in the jsp file: /Show.jsp
Configuration cannot be resolved to a type
19: <th>SALARY</th>
20: </tr>
21: <%
22: Configuration cf = new Configuration();
23: cf.configure();
24: SessionFactory sf = cf.buildSessionFactory();
25: session1 = sf.openSession();


An error occurred at line: 22 in the jsp file: /Show.jsp
Configuration cannot be resolved to a type
19: <th>SALARY</th>
20: </tr>
21: <%
22: Configuration cf = new Configuration();
23: cf.configure();
24: SessionFactory sf = cf.buildSessionFactory();
25: session1 = sf.openSession();


An error occurred at line: 24 in the jsp file: /Show.jsp
SessionFactory cannot be resolved to a type
21: <%
22: Configuration cf = new Configuration();
23: cf.configure();
24: SessionFactory sf = cf.buildSessionFactory();
25: session1 = sf.openSession();
26: //Using from Clause
27: String SQL_QUERY = "from Emp";


An error occurred at line: 25 in the jsp file: /Show.jsp
session1 cannot be resolved to a variable
22: Configuration cf = new Configuration();
23: cf.configure();
24: SessionFactory sf = cf.buildSessionFactory();
25: session1 = sf.openSession();
26: //Using from Clause
27: String SQL_QUERY = "from Emp";
28: Query query = session1.createQuery(SQL_QUERY);


An error occurred at line: 28 in the jsp file: /Show.jsp
Query cannot be resolved to a type
25: session1 = sf.openSession();
26: //Using from Clause
27: String SQL_QUERY = "from Emp";
28: Query query = session1.createQuery(SQL_QUERY);
29: Iterator it = query.iterate();
30: while (it.hasNext()) {
31: Emp e = (Emp) it.next();


An error occurred at line: 28 in the jsp file: /Show.jsp
session1 cannot be resolved
25: session1 = sf.openSession();
26: //Using from Clause
27: String SQL_QUERY = "from Emp";
28: Query query = session1.createQuery(SQL_QUERY);
29: Iterator it = query.iterate();
30: while (it.hasNext()) {
31: Emp e = (Emp) it.next();


An error occurred at line: 43 in the jsp file: /Show.jsp
session1 cannot be resolved
40: </tr>
41: <%
42: }
43: session1.close();
44: %>
45: </table>
46: </body>


Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
at java.lang.Thread.run(Thread.java:722)

My code is :

Show.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>EmployeeDetails</title>
</head>
<%@ page import="java.util.*,org.employee.*,org.hibernate.cfg.Configuration,org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.Query"%>
<%!int id;
double sal;
String name;
Session session1 = null;%>
<body>
<table width="220" border="1">
<tr>
<th>NUMBER</th>
<th>NAME</th>
<th>SALARY</th>
</tr>
<%
Configuration cf = new Configuration();
cf.configure();
SessionFactory sf = cf.buildSessionFactory();
session1 = sf.openSession();
//Using from Clause
String SQL_QUERY = "from Emp";
Query query = session1.createQuery(SQL_QUERY);
Iterator it = query.iterate();
while (it.hasNext()) {
Emp e = (Emp) it.next();
id = e.getEmpno();
name = e.getEname();
sal = e.getSal();
%>
<tr>
<td><%=id%></td>
<td><%=name%></td>
<td><%=sal%></td>
</tr>
<%
}
session1.close();
%>
</table>
</body>
</html>

Please help me where im making the mistake.
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

Welcome to the Ranch !

There's a clue here. There's nothing hibernate here. The problem is with incorrect jsp. Avoid using scriptlet within JSP. Find out more details here - Disadvantages of scriptlets in JSP

Thanks,
Tushar (SCJP 1.5)
jyothi babu
Greenhorn

Joined: Mar 26, 2013
Posts: 2
hi,

may i knw wat mistake i did in JSP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Putting Java scriptlets in a JSP is a poor practice from over 12 years ago. 12 years! It's high time that you update your JSP knowledge with modern techniques; namely the JSTL and EL.

Please see this JspFaq entry.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: hibernate