-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem in inserting data into database using hibernate
PostPosted: Sat Mar 26, 2011 2:29 pm 
Newbie

Joined: Sat Mar 26, 2011 12:28 pm
Posts: 5
Hello everbody,

I have a problem in inserting data in database using hibernate,
Lets i explain total scenario of my problem,

I creates three tables in mysql database.

1) Category:
which has following fields.

-cid (int 6)(primary key,)
-cname (varchar 40) (NULL)
-description (varchar 100) (NULL)
-parentid (int 6) (NULL)

2)Test:
which has following fields.

-tid (bigint 15) (primary key,)
-cid (int 6) (references Category(cid)) (NULL)
-tname (varchar 40) (NULL)
-tdate (date) (NULL)
-duration (int 3) (NULL)
-totalmarks (int 3) (NULL)
-maxmarks (int 3) (NULL)
-uid (bigint 10) (NULL)
-criteria (varchar 100) (NULL)

3)Question:
which has following fields.

-id (bigint 15) (primary key,)
-qid (int 3) (NULL)
-tid (bigint 15) (references Test(tid)) (NULL)
-question (varchar 200) (NULL)
-option (varchar 300)
-answer (int 1)
-cid () (references Category(cid))


I am using NetBeans 6.8 IDE and tomacat server.
I ceates java web application with hibernate.
first i creates reverse engineering and then creates "Hibernate mapping files and POJOs from database"

please make one java package named as "pojos" and creates all pojos and hbm files in that package.


below is all pojo and hbm files..........

1)category.hbm :-

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 26, 2011 11:04:10 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="pojos.Category" table="category" catalog="pre">
<id name="cid" type="java.lang.Integer">
<column name="cid" />
<generator class="assigned" />
</id>
<property name="cname" type="string">
<column name="cname" length="40" />
</property>
<property name="description" type="string">
<column name="description" length="100" />
</property>
<property name="parentid" type="java.lang.Integer">
<column name="parentid" />
</property>
<set name="questions" inverse="true">
<key>
<column name="cid" />
</key>
<one-to-many class="pojos.Question" />
</set>
<set name="tests" inverse="true">
<key>
<column name="cid" />
</key>
<one-to-many class="pojos.Test" />
</set>
</class>
</hibernate-mapping>
-----------------------------------------------------------------------------------------

2) test.hbm:-

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 26, 2011 11:04:10 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="pojos.Test" table="test" catalog="pre">
<id name="tid" type="java.lang.Long">
<column name="tid" />
<generator class="assigned" />
</id>
<many-to-one name="category" class="pojos.Category" fetch="select">
<column name="cid" />
</many-to-one>
<property name="tname" type="string">
<column name="tname" length="40" />
</property>
<property name="tdate" type="date">
<column name="tdate" length="10" />
</property>
<property name="duration" type="java.lang.Integer">
<column name="duration" />
</property>
<property name="totalmarks" type="java.lang.Integer">
<column name="totalmarks" />
</property>
<property name="maxmarks" type="java.lang.Integer">
<column name="maxmarks" />
</property>
<property name="uid" type="java.lang.Long">
<column name="uid" />
</property>
<property name="criteria" type="string">
<column name="criteria" length="100" />
</property>
<set name="questions" inverse="true">
<key>
<column name="tid" />
</key>
<one-to-many class="pojos.Question" />
</set>
<set name="questions_1" inverse="true">
<key>
<column name="tid" />
</key>
<one-to-many class="pojos.Question" />
</set>
</class>
</hibernate-mapping>

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

3) question.hbm

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 26, 2011 11:04:10 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="pojos.Question" table="question" catalog="pre">
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="assigned" />
</id>
<many-to-one name="test" class="pojos.Test" fetch="select">
<column name="tid" />
</many-to-one>
<many-to-one name="category" class="pojos.Category" fetch="select">
<column name="cid" />
</many-to-one>
<property name="qid" type="java.lang.Integer">
<column name="qid" />
</property>
<property name="que" type="string">
<column name="que" length="200" />
</property>
<property name="option" type="string">
<column name="option" length="300" />
</property>
<property name="answer" type="java.lang.Integer">
<column name="answer" />
</property>
</class>
</hibernate-mapping>
------------------------------------------------------------------------------------------

below is all POJO files.....

1) Category.java :-

package pojos;

import java.util.HashSet;
import java.util.Set;

public class Category implements java.io.Serializable {


private Integer cid;
private String cname;
private String description;
private Integer parentid;
private Set<Question> questions = new HashSet<Question>(0);
private Set<Test> tests = new HashSet<Test>(0);

public Category() {
}

public Category(String cname, String description, Integer parentid, Set<Question> questions, Set<Test> tests) {
this.cname = cname;
this.description = description;
this.parentid = parentid;
this.questions = questions;
this.tests = tests;
}

public Integer getCid() {
return this.cid;
}

public void setCid(Integer cid) {
this.cid = cid;
}
public String getCname() {
return this.cname;
}

public void setCname(String cname) {
this.cname = cname;
}
public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}
public Integer getParentid() {
return this.parentid;
}

public void setParentid(Integer parentid) {
this.parentid = parentid;
}
public Set<Question> getQuestions() {
return this.questions;
}

public void setQuestions(Set<Question> questions) {
this.questions = questions;
}
public Set<Test> getTests() {
return this.tests;
}

public void setTests(Set<Test> tests) {
this.tests = tests;
}
}


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

2) Test.java :-

package pojos;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class Test implements java.io.Serializable {

private Long tid;
private Category category;
private String tname;
private Date tdate;
private Integer duration;
private Integer totalmarks;
private Integer maxmarks;
private Long uid;
private String criteria;
private Set<Question> questions = new HashSet<Question>(0);
private Set<Question> questions_1 = new HashSet<Question>(0);

public Test() {
}

public Test(Category category, String tname, Date tdate, Integer duration, Integer totalmarks, Integer maxmarks, Long uid, String criteria, Set<Question> questions, Set<Question> questions_1) {
this.category = category;
this.tname = tname;
this.tdate = tdate;
this.duration = duration;
this.totalmarks = totalmarks;
this.maxmarks = maxmarks;
this.uid = uid;
this.criteria = criteria;
this.questions = questions;
this.questions_1 = questions_1;
}

public Long getTid() {
return this.tid;
}

public void setTid(Long tid) {
this.tid = tid;
}
public Category getCategory() {
return this.category;
}

public void setCategory(Category category) {
this.category = category;
}
public String getTname() {
return this.tname;
}

public void setTname(String tname) {
this.tname = tname;
}
public Date getTdate() {
return this.tdate;
}

public void setTdate(Date tdate) {
this.tdate = tdate;
}
public Integer getDuration() {
return this.duration;
}

public void setDuration(Integer duration) {
this.duration = duration;
}
public Integer getTotalmarks() {
return this.totalmarks;
}

public void setTotalmarks(Integer totalmarks) {
this.totalmarks = totalmarks;
}
public Integer getMaxmarks() {
return this.maxmarks;
}

public void setMaxmarks(Integer maxmarks) {
this.maxmarks = maxmarks;
}
public Long getUid() {
return this.uid;
}

public void setUid(Long uid) {
this.uid = uid;
}
public String getCriteria() {
return this.criteria;
}

public void setCriteria(String criteria) {
this.criteria = criteria;
}
public Set<Question> getQuestions() {
return this.questions;
}

public void setQuestions(Set<Question> questions) {
this.questions = questions;
}
public Set<Question> getQuestions_1() {
return this.questions_1;
}

public void setQuestions_1(Set<Question> questions_1) {
this.questions_1 = questions_1;
}
}


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

3) Question.java :-

package pojos;

public class Question implements java.io.Serializable {

private Long id;
private Test test;
private Category category;
private Integer qid;
private String que;
private String option;
private Integer answer;

public Question() {
}

public Question(Test test, Category category, Integer qid, String que, String option, Integer answer) {
this.test = test;
this.category = category;
this.qid = qid;
this.que = que;
this.option = option;
this.answer = answer;
}

public Long getId() {
return this.id;
}

public void setId(Long id) {
this.id = id;
}
public Test getTest() {
return this.test;
}

public void setTest(Test test) {
this.test = test;
}
public Category getCategory() {
return this.category;
}

public void setCategory(Category category) {
this.category = category;
}
public Integer getQid() {
return this.qid;
}

public void setQid(Integer qid) {
this.qid = qid;
}
public String getQue() {
return this.que;
}

public void setQue(String que) {
this.que = que;
}
public String getOption() {
return this.option;
}

public void setOption(String option) {
this.option = option;
}
public Integer getAnswer() {
return this.answer;
}

public void setAnswer(Integer answer) {
this.answer = answer;
}
}


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



now I created one package named as "servlets" and make one servlet as "addQuestionData".

below is that servlet "addQuestionData.java"



package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import manager.DbManager;
import pojos.Category;
import pojos.Question;
import pojos.Test;


public class addQuestionData extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {

Date date = new Date();
DateFormat df= new SimpleDateFormat("yyyy-MM-dd");
df.format(date);

Category c = new Category();
c.setCid(9);
c.setCname("Gate-2010");
c.setDescription("Entrace exam for MTech");
c.setParentid(0);

Test t = new Test();
t.setTid((long)4);
t.setCategory(c);
t.setTname("Test1");
t.setTdate(date);
t.setDuration(300);
t.setTotalmarks(300);
t.setMaxmarks(0);
t.setUid((long)1);
t.setCriteria("300:1:1;");

Question q = new Question();
q.setQid(1);
q.setTest(t);
q.setQue("What is your name ?");
q.setOption("jayesh:patrix:priyanka:pruthika");
q.setAnswer(1);
q.setCategory(c);

if(DbManager.saveQuestionData(q))
{
out.print("<h1>Question added sucessfully</h1>");
}
else
{
out.print("<h1>Some error occurs</h1>");
}

}catch(Exception ex){
ex.printStackTrace();
}
finally {
out.close();
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}
------------------------------------------------------------------------------------------

then I creates one another package named as "manager" and make one class in it named as "DbManager.java"

below is that "DbManager.java"




package manager;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import pojos.Question;

public class DbManager {

public static boolean saveQuestionData(Question q)
{
Session s=null;
try{
SessionFactory sf= new Configuration().configure().buildSessionFactory();
s=sf.openSession();
Transaction tx=s.beginTransaction();

s.save(q);
tx.commit();

return true;

}catch(Exception ex){
ex.printStackTrace();
}
finally{
s.close();
return false;
}

}

}
-----------------------------------------------------------------------------------------




Now my problem is that after run the servlet , it cant insert the data in database.

so please help me any body to solve this problem,

thanks


Top
 Profile  
 
 Post subject: Re: Problem in inserting data into database using hibernate
PostPosted: Mon Mar 28, 2011 9:08 am 
Newbie

Joined: Mon Mar 28, 2011 8:38 am
Posts: 3
Location: Ahmedabad (India)
Please post error stack trace

_________________
Hardik Mishra
Java Developer
Ahmedabad - India


Top
 Profile  
 
 Post subject: Re: Problem in inserting data into database using hibernate
PostPosted: Mon Mar 28, 2011 10:57 am 
Newbie

Joined: Sat Mar 26, 2011 12:28 pm
Posts: 5
Mar 28, 2011 8:23:47 PM org.hibernate.cfg.Environment <clinit>
... 27 more
INFO: Hibernate 3.2.5
Mar 28, 2011 8:23:47 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Mar 28, 2011 8:23:47 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Mar 28, 2011 8:23:47 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Mar 28, 2011 8:23:47 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Mar 28, 2011 8:23:47 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Mar 28, 2011 8:23:47 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : pojos/Question.hbm.xml
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pojos.Question -> question
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : pojos/Test.hbm.xml
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pojos.Test -> test
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : pojos/Category.hbm.xml
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pojos.Category -> category
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: pojos.Test.questions -> question
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: pojos.Test.questions_1 -> question
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: pojos.Category.questions -> question
Mar 28, 2011 8:23:48 PM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: pojos.Category.tests -> test
Mar 28, 2011 8:23:48 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Mar 28, 2011 8:23:48 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Mar 28, 2011 8:23:48 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Mar 28, 2011 8:23:48 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/pre
Mar 28, 2011 8:23:48 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root}
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.51b-community-nt
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
Mar 28, 2011 8:23:49 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Mar 28, 2011 8:23:49 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Mar 28, 2011 8:23:49 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Mar 28, 2011 8:23:49 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Mar 28, 2011 8:23:49 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Mar 28, 2011 8:23:49 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Mar 28, 2011 8:23:50 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Mar 28, 2011 8:23:51 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1064, SQLState: 42000
Mar 28, 2011 8:23:51 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option, answer, cid, id) values (2, null, 'Whatname', 'jayesh:pratik', 4, null, ' at line 1
Mar 28, 2011 8:23:51 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at manager.DbManager.saveQuestionData(DbManager.java:21)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at servlets.addQuestionData.processRequest(addQuestionData.java:59)
at manager.DbManager.saveQuestionData(DbManager.java:21)
at servlets.addQuestionData.doGet(addQuestionData.java:87)
at servlets.addQuestionData.processRequest(addQuestionData.java:59)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at servlets.addQuestionData.doGet(addQuestionData.java:87)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at java.lang.Thread.run(Thread.java:619)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
Caused by: java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option, answer, cid, id) values (2, null, 'Whatname', 'jayesh:pratik', 4, null, ' at line 1
at java.lang.Thread.run(Thread.java:619)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
Caused by: java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option, answer, cid, id) values (2, null, 'Whatname', 'jayesh:pratik', 4, null, ' at line 1
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
... 27 more
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)


Top
 Profile  
 
 Post subject: Re: Problem in inserting data into database using hibernate
PostPosted: Mon Apr 11, 2011 12:25 am 
Newbie

Joined: Sat Mar 26, 2011 12:28 pm
Posts: 5
I got solution of my problem,

Here I am using option word as a field of table which is keyword of java,
thats why it gives error to insert data in database,

So many persons view my post but no body gives reply to my post.

any way thanks...............


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.