0

我试图弄清楚为什么 Hibernate 在名为“Überweisung Bank”(什么意思是银行转账)的表列中的变音符号有问题。

我必须使用 Hibernate,这是一个与 ODBC 连接(mdb 文件)和 Java 1.6 链接的数据库。

所以这是我的persistance.xml

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">        
    <persistence-unit name="BUEROWARE" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.connection.driver_class" value="sun.jdbc.odbc.JdbcOdbcDriver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
            <property name="hibernate.connection.url" value="jdbc:odbc:BueroWARE;useUnicode=true;connectionCollation=utf8_general_ci;characterSetResults=utf8;characterEncoding=utf8"/>
            <property name="hibernate.connection.username" value=""/>
            <property name="hibernate.connection.password" value=""/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.comment" value="false"/>
            <property name="hibernate.use_sql_comments" value="false"/>
            <property name="hibernate.logging.level" value="ERROR"/>
        </properties>
    </persistence-unit>
    <persistence-unit name="BUEROWAREMYSQL" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
    </persistence-unit>
</persistence>



那是我的实体类的一部分

...
    @Entity
    @Table(name = "adressstamm")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Adressstamm.findAll", query = "SELECT a FROM Adressstamm a")
    })
...
        @Column(name = "[Überweisung Bank]")
            private String ueberweisungBank;
...

这就是输出

Hibernate: 
    select
        adressstam0_.[Überweisung Bank] as Überwei24_3_
    from
        adressstamm adressstam0_
[ERROR] JDBCExceptionReporter - [Microsoft][ODBC Microsoft Access Driver] 1 Parameter wurden erwartet, aber es wurden zu wenig Parameter ?bergeben.
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)
    at de.itout.jpatest.JPATest.main(JPATest.java:29)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2223)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
    ... 1 more
Caused by: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 1 Parameter wurden erwartet, aber es wurden zu wenig Parameter ?bergeben.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3149)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:216)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(JdbcOdbcPreparedStatement.java:91)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    at org.hibernate.loader.Loader.doQuery(Loader.java:674)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2220)
    ... 9 more
Java Result: 1



这是电话

ArrayList<Adressstamm> adressstamm = (ArrayList<Adressstamm>) em.createNamedQuery("Adressstamm.findAll").getResultList();

我必须在不更改列名或修复的情况下完成此操作!

4

1 回答 1

0

您有德语的错误消息,但如果谷歌翻译准确,这与您的列名无关。您正在使用参数化查询,但未设置参数(名为bergeben?)。确保您的所有 JQPL 参数都已设置;如果您认为是,请发布查询文本和构建查询的代码。

于 2013-10-14T15:18:42.940 回答