找不到JBoss Schema错误

时间:2018-06-22 21:07:15

标签: spring hibernate

我正在迁移到jBoss。这是我尝试在jBoss服务器上建立数据库连接的启动时间。我确定我在Spring / Hibernate配置中缺少某些内容,但是经过大量的搜索和调整后,我没有成功。我确实找到了为jBoss创建的快速入门示例。我的代码是根据here

上的spring-kitchensink-springmvctest项目建模的

这是我看到的错误。请记住,我正在尝试连接到Oracle数据库。我根本没有使用h2。

Caused by: org.h2.jdbc.JdbcSQLException: Schema "AMZR" not found; SQL statement:
select affiliate0_.affiliate_code as affiliate_code1_0_, affiliate0_.affiliate_abbr as affiliate_abbr2_0_, affiliate0_.cost_center as cost_center3_0_, affiliate0_.created_by as created_by4_0_, affiliate0_.created_dts as created_dts5_0_, affiliate0_.customer_support_number as customer_support_n6_0_, affiliate0_.affiliate_name as affiliate_name7_0_, affiliate0_.updated_by as updated_by8_0_, affiliate0_.updated_dts as updated_dts9_0_, affiliate0_.version as version10_0_ from AMZR.affiliate affiliate0_ where affiliate0_.affiliate_abbr=? [90079-193]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:179)
    at org.h2.message.DbException.get(DbException.java:155)
    at org.h2.command.Parser.getSchema(Parser.java:679)
    at org.h2.command.Parser.getSchema(Parser.java:685)
    at org.h2.command.Parser.readTableFilter(Parser.java:1215)
    at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1897)
    at org.h2.command.Parser.parseSelectSimple(Parser.java:2045)
    at org.h2.command.Parser.parseSelectSub(Parser.java:1891)
    at org.h2.command.Parser.parseSelectUnion(Parser.java:1709)
    at org.h2.command.Parser.parseSelect(Parser.java:1697)
    at org.h2.command.Parser.parsePrepared(Parser.java:445)
    at org.h2.command.Parser.parse(Parser.java:317)
    at org.h2.command.Parser.parse(Parser.java:289)
    at org.h2.command.Parser.prepareCommand(Parser.java:254)
    at org.h2.engine.Session.prepareLocal(Session.java:561)
    at org.h2.engine.Session.prepareCommand(Session.java:502)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1203)
    at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:73)
    at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:676)
    at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.doPrepareStatement(BaseWrapperManagedConnection.java:757)
    at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:743)
    at org.jboss.jca.adapters.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:454)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)

当我对数据库运行它时,生成的SQL语句确实起作用,您会注意到它确实包含模式。

这是在standalone.xml中看到的数据源

<datasource jta="true" jndi-name="java:/comp/env/jdbc/amzrDB" pool-name="AmzrDS" enabled="true" use-ccm="false">
    <connection-url>jdbc:oracle:thin:@server:port:sid</connection-url>
    <driver-class>oracle.jdbc.OracleDriver</driver-class>
    <driver>ojdbc8.jar</driver>
    <security>
        <user-name>user</user-name>
        <password>pass</password>
    </security>
    <validation>
        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
        <background-validation>true</background-validation>
        <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"/>
        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/>
    </validation>
</datasource>

这是web.xml的相关部分

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" >


    <!-- ======================================== -->
    <!-- SPRING WEB APPlICATION CONTEXT CONTAINER -->
    <!-- ======================================== -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>     
        <param-name>contextConfigLocation</param-name>      
        <param-value>classpath:/spring/amzrAppContext.xml</param-value>
    </context-param>


    <!-- ====================================================== -->
    <!-- SPRING SERVLET CONTEXT CONTAINER                       -->
    <!-- CONTEXT CONTAINER #2 (SCOPE THIS DISPATCHER SERVLET)   -->
    <!-- ====================================================== -->
    <servlet>
        <servlet-name>SpringConfig</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- ========================= -->
    <!-- DISPATCH SERVLET MAPPINGS -->
    <!-- ========================= -->
    <servlet-mapping>
       <servlet-name>SpringConfig</servlet-name>
       <url-pattern>/adm/*</url-pattern>
    </servlet-mapping> 


    <!-- ========================= -->
    <!-- DATASOURCE JNDI REFERENCE -->
    <!-- ========================= -->
    <resource-ref>
        <description>amzr database reference</description>
        <res-ref-name>jdbc/amzrDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

    ...

</web-app>

这是amzrAppContext.xml的相关部分

<beans 
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/jee       http://www.springframework.org/schema/jee/spring-jee.xsd
    http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx        http://www.springframework.org/schema/tx/spring-tx.xsd">


    <!-- SCAN FOR ALL @Entity, @Repository, @Service Classes -->
    <context:component-scan base-package="com.zbc.amzr.common.model, com.zbc.amzr.common.dao, com.zbc.amzr.common.service" />

    <!-- WIRE UP @Transactional ANNOTATIONS -->
    <tx:annotation-driven />


    <!-- JDNI name for EntityManagerFactory is defined in src/main/resources/META-INF/persistence.xml -->
    <jee:jndi-lookup 
        jndi-name="java:/amzrEntityManagerFactory" 
        id="entityManagerFactory"
        expected-type="javax.persistence.EntityManagerFactory" />

    <bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <jee:jndi-lookup jndi-name="java:comp/env/jdbc/amzrDB" id="dataSource" expected-type="javax.sql.DataSource" />

    <tx:jta-transaction-manager />

    ...

</beans>

这是persistence.xml

<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
                        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <persistence-unit name="amzrPersistenceUnit">
        <jta-data-source>java:comp/env/jdbc/amzrDB</jta-data-source>
            <properties>
                <property name="jboss.entity.manager.factory.jndi.name" value="java:/amzrEntityManagerFactory" />
                <property name="hibernate.dialect"                      value="org.hibernate.dialect.Oracle10gDialect"/>
                <property name="hibernate.id.new_generator_mappings"    value="true"/>
                <property name="hibernate.show_sql"                     value="true"/>
                <property name="hibernate.format_sql"                   value="true"/>          
            </properties>
    </persistence-unit>
</persistence>

服务类如下

@Service("adminToolService")
@Transactional(readOnly=true, propagation=Propagation.REQUIRED, isolation=Isolation.DEFAULT)
public class AdminToolServiceImpl implements AdminToolService
{
@Autowired
protected AffiliateDAO          affiliateDao;


public Affiliate getAffiliateByAbbreviation(String abbr) throws ARException
{
    Affiliate aff = null;

    try
    {
        aff = affiliateDao.findByAbbreviation(abbr);
    }
    catch(Exception ex)
    {
        this.logger.error("",ex);
        throw new ARException("ERROR - Affiliate not found!", -2);
    }

    return aff;
}
...

AffiliateDAO类的注释如下

@Repository("affiliateDAO")
public class AffiliateDAOHibernateImpl extends GenericDAOHibernateImpl<Affiliate, String> implements AffiliateDAO 
{

    @Autowired
    protected EntityManager entityManager;

    public Affiliate findByAbbreviation( String abbr )
    {
        Affiliate aff = null;

        StringBuffer sql = new StringBuffer();
        sql.append("SELECT ");
        sql.append("    affiliate ");
        sql.append("FROM ");
        sql.append("    Affiliate as affiliate ");
        sql.append("WHERE ");
        sql.append("    affiliate.abbreviation = :ABBR");


        Query q = entityManager.createQuery(sql.toString());
        q.setParameter("ABBR", abbr);
        aff = getSingleResultOrNull(q);

        return aff;
    }
...

会员实体类的注释如下:

@Entity
@Table(name="affiliate", schema="amazing_rewards")
public class Affiliate implements Auditable, java.io.Serializable {

    private static final long serialVersionUID = -2433319955364479791L;

    @Id
    @Column(name="affiliate_code", length=4, nullable=false, unique=true)
    private String code;

    @Column(name="version")
    private Integer version;

    @Column(name="affiliate_abbr", length=10, nullable=false, unique=true)
    private String abbreviation;

    @Column(name="affiliate_name", length=100, nullable=false, unique=true)
    private String name;
...

任何关于我可能会缺少的想法的想法将不胜感激。此外,如果有人可以帮助我了解在尝试连接Oracle时h2是如何出现的,那就太好了。

非常感谢您!

0 个答案:

没有答案