Hi guys am getting an error like wot i'd posted on the Subject field
I'll include my hibernate.cfg.xml file here
=====================================
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.url">jdbc:mysql://192.168.1.141:3306/test</property>
<property name="connection.username">slim</property>
<property name="connection.password">slim123</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="UserLogin.hbm.xml"/>
</session-factory>
</hibernate-configuration>
=====================================================
the mapping file is also included here which is UserLogin.hbm.xml
=====================================================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--Introduction to Hibernate
Hibernate 3.0.3 10 -->
<class name="com.mec.app.modules.actions.Login" table="User_Login">
<id name="userId" column="USER_ID">
<generator class="uuid"/>
</id>
<property name="userName" type="string" column="USER_NAME" unique="true"/>
<property name="password" type="string" column="USER_PASSWORD"/>
</class>
</hibernate-mapping>
===================================================================
the POJO is correct and i'll include my main code here
===================================================================
package com.mec.app.modules.actions;
import java.util.*;
import org.apache.turbine.modules.actions.VelocityAction;
import org.apache.turbine.services.intake.IntakeTool;
import org.apache.turbine.services.intake.model.*;
import org.apache.turbine.util.RunData;
import org.apache.velocity.context.Context;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class UserLogin extends VelocityAction
{
public void doLogin( RunData data, Context context ) throws Exception
{
try{
System.out.println("hello this is doLogin");
//stuff something into the Velocity Context
//Get intake group
IntakeTool intake = (IntakeTool)context.get("intake");
System.out.println("Got intake group");
// Notice how this gets the group named "Login" as defined in
// the intake.xml file, and gets it using the default key
// IntakeTool.DEFAULT_KEY (which is "_0").
System.out.println("intake " + intake);
System.out.println("intake key " + IntakeTool.DEFAULT_KEY);
Group group = intake.get("Login",IntakeTool.DEFAULT_KEY);
System.out.println("group object created" +group);
// Check if group fields are valid and if they are not, then return.
// Intake will handle the validation error and display the
// corresponding error messages to the user but if you use the setPage()
// mechanism to get the "next template" then you must now set the
// template to be the same one as the user was filling out. Otherwise
// the user will just see the next template. See the "important note"
// in step 1.
if (!group.isAllValid()){
setTemplate(data,"UserLogin.vm");
context.put("Message", "Enter a correct UserName");
System.out.println("Group elements INVALID");
log.debug("Group elements INVALID");
}
else{
// If all is validated then you can set the next template and/or
//continue processing...it's up to you. You can also use
// setPage() in the template file to set the next template to show
// on successful validation.
System.out.println("Group elements VALID");
// This gets the value of the "Username" field from the group object
//try{
//}
//catch(Exception e){
// System.out.println("caught" );
//e.printStackTrace();
//}
String username = group.get("UserName").getValue().toString();
System.out.println("User Name: "+username);
String password = (String)group.get("Password").getValue();
System.out.println("Password: "+password);
System.out.println("Context: "+context.toString());
context.put("username",username);
// Now you will be able to use the username and password variable in
// the rest of the Turbine Action.
//*************hibernate code starts here******************
createAndStoreData(username, password);
HibernateUtil.sessionFactory.close();
}
}catch(Exception e){
e.getStackTrace();
}
}
public void doDisplay(RunData data,Context context){
try{
System.out.println("this is doDisplay");
UserLogin uLogin=new UserLogin();
List result=uLogin.getData();
for(int i=0;i<result.size();i++){
Login theLogin=(Login)result.get(i);
System.out.println("User ID: "+theLogin.getUserId());
System.out.println("User Name : "+theLogin.getUserName());
System.out.println("Password : "+theLogin.getPassword());
}
context.put("User_Login", result);
}catch(Exception e){
e.printStackTrace();
}
}
public void doPerform( RunData data, Context context ) throws Exception
{ System.out.println("DoPerform");
// stuff something into the Velocity Context
System.out.println("hello this is doPerform");
}
public void createAndStoreData(String userName,String password){
//For inserting the data elements into the table
try{
System.out.println("Inside createAndStoreData: "+userName+" , "+password);
Session session=HibernateUtil.currentSession();
System.out.println("Current Session :"+ session);
Transaction tx=session.beginTransaction();
System.out.println("Current Transaction :"+ tx);
Login theLogin=new Login();
theLogin.setUserName(userName);
theLogin.setPassword(password);
session.save(theLogin);
tx.commit();
HibernateUtil.closeSession();
}catch(Exception e){
e.printStackTrace();
}
}
public List getData(){
//For retreiving the data elements from the table
List result=null;
try{
Session session=HibernateUtil.currentSession();
System.out.println("Current Session :"+ session);
Transaction tx=session.beginTransaction();
System.out.println("Current Transaction :"+ tx);
result=session.createQuery("from Login").list();
tx.commit();
session.close();
}catch(Exception e){
e.printStackTrace();
}
return result;
}
}
================================================================
Problem Description
When i Start Tomcat and execute this program it runs successfully but when i try to enter the values once again it encounters a problem. and the error is attached here with as stack trace. Plz do refer that too
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.mec.app.modules.actions.UserLogin.createAndStoreData(UserLogin.java:124)
at com.mec.app.modules.actions.UserLogin.doLogin(UserLogin.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.turbine.util.velocity.VelocityActionEvent.executeEvents(VelocityActionEvent.java:136)
at org.apache.turbine.util.velocity.VelocityActionEvent.perform(VelocityActionEvent.java:78)
at org.apache.turbine.modules.actions.VelocityAction.perform(VelocityAction.java:72)
at org.apache.turbine.modules.ActionLoader.exec(ActionLoader.java:96)
at org.apache.turbine.modules.pages.DefaultPage.doBuild(DefaultPage.java:113)
at org.apache.turbine.modules.Page.build(Page.java:53)
at org.apache.turbine.modules.PageLoader.exec(PageLoader.java:98)
at org.apache.turbine.Turbine.doGet(Turbine.java:751)
at org.apache.turbine.Turbine.doPost(Turbine.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.BatchUpdateException: null, message from server: "Duplicate entry '40288046146e835b0114' for key 1"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1404)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 50 more
================================================================
Plz do verify this and get back to me.......ASAP
thanks and regards
Abhi