Hibernate が "Überweisung Bank" (銀行振込を意味する) という名前のテーブル列でウムラウトに問題がある理由を理解しようとしました。
ODBC接続(mdbファイル)とJava 1.6にリンクされたデータベースであるHibernateを使用する必要があります。
これは私の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();
列名などを変更せずにこれを実行する必要があります。