-->
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: hibernate 2.1 + spring 1.2 on tomcat 5.5
PostPosted: Mon Aug 01, 2005 2:44 pm 
Newbie

Joined: Mon Aug 01, 2005 1:21 pm
Posts: 2
hello, i am as new as new gets to webapp development. i am trying to put together a simple application using the spring framework and hibernate 2.1 for persistance. i got the app up and running on my tomcat server using the framework. I then tried to integrate hibernate into it and now it won't work. outside of the server when i run some test on my hibernate methods they work just like i want them to work( or as they should according the book i am reading -hibernate , a developers notebook-). however when i deploy it to the server i get a net.sf.hibernate.exception.SQLGrammarException: Could not execute query ...error. below is the code that i think pertains to this problem. please help.


springapp-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<!--
- Application context definition for "springapp" DispatcherServlet.
-->

<beans>

<!-- Controller for the initial "Hello" page -->
<bean id="springappController" class="web.SpringappController"/>


<!-- Validator and Form Controller for the "Price Increase" page -->
<bean id="priceIncreaseValidator" class="bus.PriceIncreaseValidator"/>
<bean id="priceIncreaseForm" class="web.PriceIncreaseFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>priceIncrease</value></property>
<property name="commandClass"><value>bus.PriceIncrease</value></property>
<property name="validator"><ref bean="priceIncreaseValidator"/></property>
<property name="formView"><value>priceincrease</value></property>
<property name="successView"><value>hello.htm</value></property>


</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property>
<property name="url">
<value>jdbc:hsqldb:/projects/springapp_idea/springapp/db/my_db</value>
</property>
<property name="username"><value>sa</value></property>
<property name="password"><value></value></property>
</bean>


<bean id="prodManager" class="bus.ProductManager"/>

<bean id="pst" class="hh.persistance"/>

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename"><value>messages</value></property>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/hello.htm">springappController</prop>
<prop key="/priceincrease.htm">priceIncreaseForm</prop>
</props>
</property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix"><value>/WEB-INF/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>
</beans>


persistance.java

package hh;

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.Configuration;

import java.util.*;

import bus.product;



public class persistance
{
private Transaction tx = null;
private Session session;
private SessionFactory sessionFactory;
private Configuration config;


private void set_up() throws Exception
{
config = new Configuration();
config.addClass(product.class);
sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
}

public List all_products() throws HibernateException ,Exception
{
set_up();
return session.find("from product");
// Query query = session.getNamedQuery("all_data");
//return query.list();
}



public void close_session() throws Exception
{
session.close();
}



public void write_products(List L) throws Exception
{
System.out.println("GOT INTO WRITE_PRODUCTS");
set_up();
try
{
for (ListIterator iter = L.listIterator();iter.hasNext() ; )
{
System.out.println("GOT INTO WRITE_PRODUCTS for loop");
tx = session.beginTransaction();

product pr = (product)iter.next();
System.out.println("saving "+pr.getDescription()+" with price "+pr.getPrice()+" to database");
session.update(pr);
}
// We're done; make our changes permanent
tx.commit();
}
catch (Exception e)
{
if (tx != null)
{
// Something went wrong; discard all partial changes
tx.rollback();
}
}
}


ProductManager.java
package bus;

import java.io.Serializable;
import java.util.ListIterator;
import java.util.*;
import java.sql.Types;

import hh.*;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.*;



public class ProductManager implements Serializable
{
private List products;
private persistance persist = new persistance();


// Create a configuration based on the properties file we've put
// in the standard place.
// Tell it about the classes we want mapped, taking advantage of
// the way we've named their mapping documents.
// Get the session factory we can use for persistence




public List get_products()throws Exception
{
products = persist.all_products();
persist.close_session();
return products;
}




public void increase_price(int pct) throws Exception
{
List li = persist.all_products();
System.out.println("i am about to increase the price by "+pct+"%");
for (ListIterator iter = li.listIterator();iter.hasNext() ; )
{
product p = (product)iter.next();
double X = p.getPrice();
double inc = (((double)pct)/100)* p.getPrice() + p.getPrice();
p.setPrice(inc);
System.out.println(p.getDescription()+" went from $" + X +" to $"+p.getPrice());
}
persist.write_products(li);
persist.close_session();
}



}


the full error as seen on page

type Exception report

message

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

exception

javax.servlet.ServletException: Could not execute query
org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:402)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

net.sf.hibernate.exception.SQLGrammarException: Could not execute query
net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:69)
net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)
net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)
net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1523)
hh.persistance.all_products(persistance.java:31)
bus.ProductManager.get_products(ProductManager.java:31)
web.SpringappController.handleRequest(SpringappController.java:39)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
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.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.