/ / Spring JPA / HIbernate tworzenie / aktualizowanie widoków podczas uruchamiania aplikacji - wiosna, hibernacja, postgresql, jpa

Spring JPA / HIbernate tworzenie / aktualizowanie widoków po uruchomieniu aplikacji - wiosna, hibernacja, postgresql, jpa

Nasza aplikacja oparta jest na spring, JPA, Hibernate (3.5.1), postgresql 8.4

Dostarczymy nowy plik .war naszym klientom, ale mamy sporo nowych widoków w bazie danych, które trzeba było utworzyć, zanim będą mogli uruchomić niektóre raporty.

Próbowałem umieścić plik import.sql w folderze src i skonfigurowałem mój persistence.xml w ten sposób :

<?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>

a mój data-access-context.xml w ten sposób:

<?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>

Ale nie mogę utworzyć nowych widoków? dowolny pomysł? Z góry dziękuję.

Odpowiedzi:

1 dla odpowiedzi № 1

To nie jest tak naprawdę odpowiedź na twoje pytanie, ale może wartościowe rozwiązanie. A co z użyciem struktury migracji bazy danych? sugeruję flyway co daje pełny dostęp do Twojej bazy danych.

Podczas uruchamiania aplikacji (patrz stanowisko) migrację można uruchomić za pomocą 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();