2012-03-02 11 views
1

を開始したときに/更新ビューを作成し、JPAは、Hibernate(3.5.1)、PostgreSQLの8.4春JPA/Hibernateは、アプリケーションが私たちのアプリケーションは、スプリングに基づいて

私達は私達の顧客に新しい.warファイルをお届けします

が、私たちはいくつかのレポートを実行する前に、作成する必要のあるDBのかなり新しいビューを持っています。

私はsrcフォルダの下にimport.sqlファイルを入れてみましたが、この のように私にpersistence.xmlに構成:

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="1.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_1_0.xsd"> 
    <persistence-unit name="myApp"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <class>....</class> 

     <properties> 
      <property name="hibernate.hbm2ddl.auto" value="update" /> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> 
      <property name="hibernate.show_sql" value="true" /> 
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" /> 
     </properties>  
    </persistence-unit> 
</persistence> 

と、このように私のデータ・アクセスのcontext.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" 
    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/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"> 


    <bean id="dataSource" 
      class="org.springframework.jndi.JndiObjectFactoryBean"> 
      <property name="jndiName" 
         value="java:comp/env/jdbc/mydb"/> 
      <property name="resourceRef" 
         value="true" /> 
    </bean> 

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
      <property name="dataSource" ref="dataSource" /> 
      <property name="persistenceUnitName" value="myApp" /> 
      <property name="jpaVendorAdapter"> 
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
          <property name="generateDdl" value="true" /> 
          <property name="showSql" value="true" /> 
          <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" /> 
        </bean> 
      </property> 
    </bean> 

    <tx:annotation-driven/> 

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
     <property name="entityManagerFactory" ref="entityManagerFactory"/> 
    </bean> 

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 

    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> 

    <context:component-scan base-package="com.pb.redline.dao" />  


</beans> 

新しいビューを作成できません。 前もって感謝します。

答えて

1

これは本当にあなたの質問に対する答えではありませんが、おそらく貴重な解決策です。データベース移行フレームワークの使用はどうですか?私はflywayあなたのデータベースに完全にアクセスすることをお勧めしますお勧めします。

アプリケーション開始時(postを参照)、マイグレーションはflyway java apiを使用してトリガーできます。

Properties properties = new Properties(); 
properties.setProperty("flyway.user", "postgres"); 
properties.setProperty("flyway.password", "secret"); 
properties.setProperty("flyway.url", "jdbc:postgresql://localhost/database-name"); 
properties.setProperty("flyway.driver", "org.postgresql.Driver"); 

flyway = new Flyway(); 
flyway.configure(properties); 
flyway.clean(); 
flyway.migrate(); 
関連する問題