-->
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: Could not save object
PostPosted: Sat Sep 17, 2005 1:38 am 
Newbie

Joined: Tue Aug 30, 2005 12:28 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.5

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hi!
I try to save object but i got an error
this is the error message:
Sergey Smirnov wrote:
net.sf.hibernate.exception.SQLGrammarException: Could not save object
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4110)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:792)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
at site.bean.MemberBean.saveMember(MemberBean.java:24)
at site.action.Register.execute(Register.java:64)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
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:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Syntax error or access violation, message from server: "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 '"member"' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1109)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2030)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1563)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeQuery(FilterPreparedStatement.java:68)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:567)
at net.sf.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:68)
at net.sf.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:42)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:774)
... 23 more


this is the hibernate.properties
Sergey Smirnov wrote:
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/address
hibernate.connection.username=address
hibernate.connection.password=6696397
hibernate.show_sql=true
hibernate.c3p0.max_size=2
hibernate.c3p0.min_size=2
hibernate.c3p0.timeout=5000
hibernate.c3p0.max_statements=100
hibernate.c3p0.idle_test_period=3000
hibernate.c3p0.acquire_increment=2
hibernate.c3p0.validate=false

this is the mapping file
Sergey Smirnov wrote:
<hibernate-mapping>
<class name="site.bean.Member" table="member">
<id name="id" column="id" type="long">
<generator class="increment"/>
</id>
<property name="userName" column="userName" type="string" not-null="true" />
<property name="password" column="password" type="string" not-null="true" />
<property name="email" column="email" type="string" not-null="true"/>
<property name="question" column="question" type="string" />
<property name="answer" column="answer" type="string" />
<property name="passport" column="passport" type="string"/>
</class>
</hibernate-mapping>

And the java file
Sergey Smirnov wrote:
public class MemberBean {
public static SessionFactory sessionFactory;
static {
try {
Configuration config = new Configuration();
config.addClass(Member.class);
sessionFactory = config.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
public String saveMember(Member m) throws Exception {
String s=null;
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.save(m);
tx.commit();
s="success";
} catch (Exception e) {

e.printStackTrace();
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
session.close();
}
return s;
}


Can somebody help me


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 17, 2005 6:15 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Enable logging to show the generated SQL, also check the list of reserved words in MySQL to make sure you're not using any of them.


Top
 Profile  
 
 Post subject: Also I can load the object,but i can not save it.
PostPosted: Sat Sep 17, 2005 8:29 am 
Newbie

Joined: Tue Aug 30, 2005 12:28 pm
Posts: 3
jamie_dainton wrote:
Enable logging to show the generated SQL, also check the list of reserved words in MySQL to make sure you're not using any of them.

Also I can load the object,but i can not save it,and i don;t know why?

on MySQL Comand Line Client,i can insert into the table,
this is the SQL:
insert into member values(1,'123456789','123456789',
'123456789@163.com','123456789','
123456789','123456789');
when run the tomcat and i try to insert the same data it also show the error message.
This is the Scherma:
create table member{
id int not null primary key,
userName varchar(20) ,
password varchar(20) ,
email varchar(20) ,
question varchar(20) ,
answer varchar(20) ,
passport varchar(20) );

Please help me.


Top
 Profile  
 
 Post subject: Re: Also I can load the object,but i can not save it.
PostPosted: Sun Sep 18, 2005 3:59 am 
Newbie

Joined: Tue Aug 30, 2005 12:28 pm
Posts: 3
That is OK,because in the mapping file the tldthat i use is 3.0,but jar file i import is hibernate2.jar.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.