SQL 语法错误?

发布于 2024-11-05 23:30:51 字数 2370 浏览 0 评论 0原文

我在我的java程序中使用hibernate,但使用它时遇到了一些麻烦.. 这是我的 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>

这是我的 java 类:

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;
}

然后它只是 getters 和 setters,在我的 main 中,我只想显示它:

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();

在我的控制台中,它说我有一个 SQL 错误..

10:20:54,626 警告 JDBCExceptionReporter:233 - SQL 错误:1064,SQLState:42000 10:20:54,628 错误 JDBCExceptionReporter:234 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“.testNetwork this_”附近使用的正确语法 线程“main”中的异常org.hibernate.exception.SQLGrammarException:无法执行查询 在org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92) 在 org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 在 org.hibernate.loader.Loader.doList(Loader.java:2536)

希望 s.one 可以提供帮助。谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

标点 2024-11-12 23:30:51

mysql 要求您在访问表名时使用反引号 ``列,请在定义时打勾,

例如..

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

这应该可以解决您的问题..Anantha

  • Sharma

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文