Edit1: 当 Hibernate 连接到 MS-SQL 时,所有的列和表都在扫描。日志
但是当 Hibernate 连接到 DB2 时,它会尝试再次识别(呈现)所有包含“i”字母的表和列。日志
扫描表格和列后,我意识到所有字母都很大。事实上,在 DB2 上每个字母都很大。Hibernate 使用小写字母进行查询,由于 DB2 对大写字母的敏感性,它不能识别列名。出于这个原因,它会在下面发出警报,
WARN SqlExceptionHelper: SQL Error: -99999, SQLState: 42703
15:15:22,025 ERROR SqlExceptionHelper: An undefined column name was detected.
我怎么解决这个问题?
我必须使用 jpa 从 db2 中的表中检索数据。当我尝试使用实体管理器执行查询时,我收到错误,不知道问题到底出在哪里。 我的代码在 MS-SQL 和 HSQL-DB 上运行...但我连接 DB2 时出现消息错误:*
查询 qry = em.createQuery("from Holding h where h.RDeleted=:arg1");-
13:26:38,135 DEBUG SQL:选择holding0_.HoldingId 作为HoldingId1_,holding0_.RDeleted 作为RDeleted1_,holding0_.InsertDate 作为InsertDate1_,holding0_.SavesUserId 作为SavesUse4_1_,holding0_.UpdateDate 作为UpdateDate1_,holding0_.Updater 作为Updater1_,holding0_.Description 作为Descript7_1_ ,holding0_.HoldingName as HoldingN8_1_ from Holding holding0_ where holding0_.RDeleted=? 休眠:选择holding0_.HoldingId 作为HoldingId1_,holding0_.RDeleted 作为RDeleted1_,holding0_.InsertDate 作为InsertDate1_,holding0_.SavesUserId 作为SavesUse4_1_,holding0_.UpdateDate 作为UpdateDate1_,holding0_.Updater 作为Updater1_,holding0_.Description 作为Descript7_1_,holding0_.HoldingName 作为HoldingN8_1_从控股holding0_ where holding0_.RDeleted=? 13:26:38,428 WARN SqlExceptionHelper:SQL 错误:-99999,SQLState:42703 13:26:38,428 错误 SqlExceptionHelper:
但它查询有效:
Select h.holdingId, h.holdingName, h.description from Holding h
我的数据源:
<bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSourceDB2_JT400" destroy-method="close">
<property value="com.ibm.as400.access.AS400JDBCDriver" name="driverClassName"/>
<property value="jdbc:as400://192.168.1.1/GULERP" name="url"/>
<property value="user" name="username"/>
<property value="PW" name="password"/>
<property value="5" name="initialSize"/>
</bean>
我的实体管理器:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="erp" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.DB2400Dialect" />
</bean>
</property>
<property name="dataSource" ref="dataSourceDB2_JT400"/>
</bean>
和我的域:
@Entity
@AccessType("field")
@Table(name = "Holding", uniqueConstraints = {@UniqueConstraint(columnNames={"HoldingName"})})
public class Holding extends BaseClass implements Serializable {
transient static final long serialVersionUID = 5473887143181971744L;
@Id
@Column(name = "HoldingId", nullable = false, length=36)
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
private String holdingId;
@Basic(optional = false)
@Column(name = "HoldingName", nullable = false, length = 100)
private String holdingName;
@Column(name = "Description", length = 210)
private String description;
@OneToMany(mappedBy = "holdingId", fetch = FetchType.LAZY)
private List<Company> companyList;