2

is there any way to update the column definition of existing table where data is already present or may be table is empty.
Consider this:

@ManyToOne
@JoinColumn(name="type",nullable=false)
private EmpType type;

or

@JoinColumn(name="type",nullable=false)
private String type;  

Considering any of above scenario, once hibernate initialized, it create tables column with Not Null property. but When I change them from nullable=false to nullable=true this changes dont reflect in table. It still not null.
My Configuration is also include
<property name="hibernate.hbm2ddl.auto" value="update" />

Is there any other approach, or am I doing it in wrong way ?

Edit

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="myapp" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
        <property name="hibernate.show_sql" value="false" />
    </properties>
</persistence-unit>

and in my spring application context:

    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="myapp" />
    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.ejb.interceptor"
                value="org.springframework.orm.hibernate3.support.ScopedBeanInterceptor" />
        </map>
    </property>
</bean>
Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
Aman Gupta
  • 5,548
  • 10
  • 52
  • 88
  • How are you testing it ? If the classes are recompiled and deployed, as per hbm2ddl, will create tables as per the definition. BTW how are you creating tables --> script / entity java classes ? – Vinay Veluri Sep 02 '14 at 11:53
  • @VinayVeluri Java entity classes. I am adding changes and running the application in tomcat – Aman Gupta Sep 02 '14 at 11:58
  • So as per http://stackoverflow.com/questions/438146/hibernate-hbm2ddl-auto-possible-values-and-what-they-do, it says update should work. How are you testing it is my another question – Vinay Veluri Sep 02 '14 at 12:00
  • Thanks for link. As I said, Testing simply by making changes and redeploying application. nothing fancy like test cases as of now. I already have `hbm2ddl.auto` value as `update` but still changes dont reflect. Pardon me, Hibernate is sort of new for me – Aman Gupta Sep 02 '14 at 12:07
  • 1
    Maybe you should post a bit more of you configuration, especially that part around where hbm2ddl.auto is set. – John Sep 02 '14 at 12:29
  • @John Question updated.. thanks – Aman Gupta Sep 02 '14 at 13:19
  • Did you try the solution proposed in the top-rated answer [here](http://stackoverflow.com/questions/4307690/how-to-get-automatic-table-creation-working-in-spring-hibernate-jpa)? – John Sep 02 '14 at 14:16

0 Answers0