我试图弄清楚为什么 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();
我必须在不更改列名或修复的情况下完成此操作!