Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
chinafeng
Post subject: [Closed] Could not save object  PostPosted: Sep 17, 2005 - 06:26 AM



Joined: Sep 17, 2005
Posts: 5

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:6
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:567)
at net.sf.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:6
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
 
 View user's profile Send private message  
Reply with quote Back to top
chinafeng
Post subject: Also I can load the object,but i can not save it,and i don;t  PostPosted: Sep 17, 2005 - 01:16 PM



Joined: Sep 17, 2005
Posts: 5

Also I can load the object,but i can not save it,and i don;t know why?
Could anybody help me.
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Sep 17, 2005 - 07:07 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23855

I think the problem is that "member" may be a key word in MySQL so when Hibernate generates the SQL to execute, it bombs out, Try renaming your class to:
MemberTemp and see if everything magically works (you will need to update corresponding hibernate resources).

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
chinafeng
Post subject: stil show the same error message  PostPosted: Sep 18, 2005 - 04:04 AM



Joined: Sep 17, 2005
Posts: 5

all the member i have change as customers ,but it stil show the same message
 
 View user's profile Send private message  
Reply with quote Back to top
chinafeng
Post subject: Re: stil show the same error message  PostPosted: Sep 18, 2005 - 08:58 AM



Joined: Sep 17, 2005
Posts: 5

chinafeng wrote:
all the member i have change as customers ,but it stil show the same message

That is OK,because in the mapping file the tldthat i use is 3.0,but jar file i import is hibernate2.jar.thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
crajkumar
Post subject:   PostPosted: Oct 07, 2005 - 10:05 AM



Joined: Oct 07, 2005
Posts: 4

hibernate.connection.url=jdbc:mysql://localhost:3306/address

change The aboue statement into

hibernate.connection.url=jdbc:mysql://localhost/address
 
 View user's profile Send private message  
Reply with quote Back to top
crajkumar
21 Post subject: cnahge  PostPosted: Oct 07, 2005 - 10:08 AM



Joined: Oct 07, 2005
Posts: 4

change This statement
"hibernate.connection.url=jdbc:mysql://localhost:3306/address " into

hibernate.connection.url=jdbc:mysql://localhost/address
 
 View user's profile Send private message  
Reply with quote Back to top
luizclaudiosn
Post subject:   PostPosted: Nov 12, 2005 - 07:09 PM
Registered Member
Registered Member


Joined: Apr 27, 2005
Posts: 2

The problems is the attribute "incremente". This option doesn't works with MySQL.

Try "hilo" attribute, and it will work fine.

Luiz
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits