facebook

[Closed] Could not save object

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #237551 Reply

    chinafeng
    Member

    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

    #237556 Reply

    chinafeng
    Member

    Also I can load the object,but i can not save it,and i don;t know why?
    Could anybody help me.

    #237564 Reply

    Riyad Kalla
    Member

    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).

    #237575 Reply

    chinafeng
    Member

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

    #237577 Reply

    chinafeng
    Member

    This message has not been recovered.

    #238913 Reply

    crajkumar
    Member

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

    change The aboue statement into

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

    #238915 Reply

    crajkumar
    Member

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

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

    #241347 Reply

    The problems is the attribute “incremente”. This option doesn’t works with MySQL.

    Try “hilo” attribute, and it will work fine.

    Luiz

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: [Closed] Could not save object

You must be logged in to post in the forum log in