Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring JPA Hibernate未更新列_Java_Postgresql_Hibernate_Jpa_Spring Data Jpa - Fatal编程技术网

Java Spring JPA Hibernate未更新列

Java Spring JPA Hibernate未更新列,java,postgresql,hibernate,jpa,spring-data-jpa,Java,Postgresql,Hibernate,Jpa,Spring Data Jpa,我将Spring4.1.0与HibernateEntityManager 4.1.9一起使用 另外,我正在使用Postgres 9.6 我有以下实体: @Entity @Table(name = "audit", schema = "public") @SequenceGenerator(name = "AUDIT_SEQUENCE", sequenceName = "AUDIT_SEQUENCE", allocationSize = 1, initialValue = 1) public cl

我将Spring4.1.0与HibernateEntityManager 4.1.9一起使用

另外,我正在使用Postgres 9.6

我有以下实体:

@Entity
@Table(name = "audit", schema = "public")
@SequenceGenerator(name = "AUDIT_SEQUENCE", sequenceName = "AUDIT_SEQUENCE", allocationSize = 1, initialValue = 1)
public class AuditTrail {

        @Id
        @Column(name = "auditid", unique = true)
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUDIT_SEQUENCE")
        private long auditId;

        @Column(name = "auditvalue")
        private String auditValue;


        ... getter setters ...
}
这将使列结构变为字符(255)

我想将auditValue列的长度更新为10000。因此,我将实体更新为:

@Column(name = "auditvalue", length = 10000)
private String auditValue;
但列结构不会更新

My applicationContext.xml包含:

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.avaya.mediamanager.entity" />
    <property name="jpaVendorAdapter" ref="hbAdapterBean_pgsql"/>   
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.id.new_generator_mappings">true</prop>
        </props>
    </property>     
</bean>
<bean id="hbAdapterBean_pgsql" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">  
    <property name="showSql" value="false"></property>  
    <property name="generateDdl" value="true"></property>  
    <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect"></property>  
</bean>  

假的
真的
更新
真的

如何从应用程序更新列?

据我所知,
hibernate.hbm2ddl.auto
设置为
update
实际上不会更新已创建的表,但会添加新表而不会删除数据

您可以将
hibernate.hbm2ddl.auto
更改为
create drop
,这将导致每次重新启动服务时都重新创建您的架构,但我不确定它是否正是您想要的,因为它还将删除您的所有数据

如果您想保留数据,可能需要考虑使用flyway之类的工具来填充数据

我希望这有帮助!
玩得开心

对不起,但我认为这在大多数情况下是不可接受的。