0

I'm developing a Tomcat-based webapp I'm trying to get to talk to an existing AS400 data store. I've copied most of the settings from an existing web app which works, but when I run my new app I get this:

2013-08-08 13:50:11,988 ERROR [RMI TCP Connection(3)-127.0.0.1] org.hibernate.tool.hbm2ddl.SchemaValidator - could not get database metadata
java.sql.SQLException: [SQL5016] Qualified object name SYSSEQUENCES not valid.
    at com.ibm.as400.access.JDError.throwSQLException(JDError.java:646)
    at com.ibm.as400.access.JDError.throwSQLException(JDError.java:617)
    at com.ibm.as400.access.AS400JDBCStatement.commonPrepare(AS400JDBCStatement.java:1578)
    at com.ibm.as400.access.AS400JDBCStatement.executeQuery(AS400JDBCStatement.java:2138)
    at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
    at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
    at org.hibernate.tool.hbm2ddl.DatabaseMetadata.initSequences(DatabaseMetadata.java:151)
    at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init>(DatabaseMetadata.java:69)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:132)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:378)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
[SNIP]

Seems like it's failing looking for the SYSSEQUENCES object (presumably a table) but there's no such table in my schema, or anywhere that I'm aware of. Why is it doing this and how can I correct it?

Here's the SERVER.XML resource that I'm using to connect:

    <Resource 
        name="jdbc/myresource" 
        auth="Container" 
        driverClassName="com.ibm.as400.access.AS400JDBCDriver" 
        maxActive="20" 
        maxIdle="10" 
        maxWait="5000" 
        password="mypassword" 
        testOnBorrow="true" 
        type="javax.sql.DataSource" 
        url="jdbc:as400://mysystem.mycompany.com;libraries=LIB1 LIB2 LIB3;dateformat=iso;timeformat=iso;prompt=false;naming=system;transaction isolation=none" 
        username="myusername" 
        validationQuery="SELECT * from sysibm/sysdummy1"/>

Here's my PERSISTENCE.XML:

<persistence-unit name="myPersistenceUnit">
    <properties>
        <property name="hibernate.generate_statistics" value="true" />
        <property name="hibernate.cache.use_structured_entries" value="true" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.jdbc.batch_size" value="100" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
        <property name="hibernate.hbm2ddl.auto" value="validate"  />
    </properties>
</persistence-unit>
4

2 回答 2

2

检查问题开始于的堆栈跟踪org.hibernate.tool.hbm2ddl.DatabaseMetadata.initSequences

initSequences方法检查方言是否支持序列:

数据库元数据.initSequences

private void initSequences(Connection connection, Dialect dialect) throws SQLException {
    if ( dialect.supportsSequences() ) {
        String sql = dialect.getQuerySequencesString();

DB2400Dialect 报告它没有:

DB2400方言.java

public class DB2400Dialect extends DB2Dialect {
    @Override
    public boolean supportsSequences() {
        return false;
    }

作为参考,基本 DB2Dialect 确实支持序列和参考sysibm.syssequences

DB2Dialect.java  

@Override
public boolean supportsSequences() {
    return true;
}

@Override
public String getQuerySequencesString() {
    return "select seqname from sysibm.syssequences";
}

似乎您的方言没有正确设置,或者您的 DB2400Dialect 版本报告它确实支持序列。

于 2013-08-08T22:30:55.883 回答
0

尝试使用以下内容:

public class DB2AS400Dialect extends DB2400Dialect {
    @Override
    public String getQuerySequencesString() {
        return null;
    }
}

由于方言类执行以下操作:

public SequenceInformationExtractor getSequenceInformationExtractor() {
    if ( getQuerySequencesString() == null ) {
        return SequenceInformationExtractorNoOpImpl.INSTANCE;
    }
    else {
        return SequenceInformationExtractorLegacyImpl.INSTANCE;
    }
}

如果方言支持序列,而不是查询布尔值。

于 2016-02-17T19:02:39.260 回答