Palsajicoco
Palsajicoco

Reputation: 1

Error SQL syntax?

I am using hibernate in my java program and I got some troubles using it .. Here is my xml:

<hibernate-mapping>
<class name="revEngMapping.TestNetwork" table="testNetwork">
    <id name="id" type="java.lang.Integer">
        <column name="id" />
        <generator class="identity" />
    </id>
    <property name="networkElementId" type="string">
        <column name="networkElement_id" length="45" />
    </property>
    <property name="date" type="string">
        <column name="Date" length="45" />
    </property>
    <property name="oid" type="string">
        <column name="Oid" length="150" />
    </property>
    <property name="value" type="string">
        <column name="Value" length="200" />
    </property>
</class>

here is my java class:

public class TestNetwork implements java.io.Serializable {

private Integer id;
private String networkElementId;
private String date;
private String oid;
private String value;

public TestNetwork() {
}

public TestNetwork(String networkElementId, String date, String oid,
        String value) {
    this.networkElementId = networkElementId;
    this.date = date;
    this.oid = oid;
    this.value = value;
}

Then its just getters and setters, and in my main, I just want to display it:

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();


    Criteria crit = session.createCriteria(TestNetwork.class);

    List resultList=crit.list();

    for(int i=0;i<resultList.size();i++)
      System.out.println(((TestNetwork)resultList.get(i)).getId()+"  "+((TestNetwork)resultList.get(i)).getDate());


    session.getTransaction().commit();

In my console it says that I have an SQL error ..

10:20:54,626 WARN JDBCExceptionReporter:233 - SQL Error: 1064, SQLState: 42000 10:20:54,628 ERROR JDBCExceptionReporter:234 - 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 '.testNetwork this_' at line 1 Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2536)

Hope s.one can help. thanks

Upvotes: 0

Views: 1333

Answers (1)

Anantha Sharma
Anantha Sharma

Reputation: 10098

mysql requires you to use backticks `` when accessing table names & columns, please back ticks while defining

eg..

<property name="someProperty" column="`dbColumnName`"/>

this should solve your problem..

  • Anantha Sharma

Upvotes: 0

Related Questions