0

I am trying to update my project from spring 3 to 4 and hibernate 3 to 5.when i run my application,

<prop key="hibernate.hbm2ddl.auto">validate</prop> 

causes following exception

  Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [EditionNewsletterNS_id] in table [Edition_SubscriptionGroup]
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:85)
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:484)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:416)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:401)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 34 more

Here are my classes

@Entity
public class Edition extends VersionedBaseEntity {
private String name;
private String emailSubject;
private String emailAddress;

//setters and getter

}
@Entity
public class EditionNewsletterNS extends Edition
{
private final Log logger = LogFactory.getLog(getClass());

private List<SubscriptionGroup> subscriptionGroups;\

public void setSubscriptionGroups(List<SubscriptionGroup> 
subscriptionGroups)
{
    this.subscriptionGroups = subscriptionGroups;
}
@ManyToMany(fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
public List<SubscriptionGroup> getSubscriptionGroups()
{
    return subscriptionGroups;
}

}

Edition_SubscriptionGroup has edition_id as column rather than EditionNewsletterNS_id which is actually a dtype.The whole project works well in hibernate 3 and spring 3. Any help is appreciated!

Sai
  • 49
  • 5
  • You did not define the column names in your ManyToMany relation. I suspect Hibernate will therefor try to autogenerate them and the autogenerated ones are different from the ones in your existing database. You never seem to define table or column names in the code you posted. I don't think thats a good style. Also you did not define wether Edition and EditionNewsletterNS should both have completly sperate tables, be saved in one table or work with joined Tables (The InheritanceType). Again I would feel very uncomfortable just letting hibernate decide all of that by default. – OH GOD SPIDERS Sep 27 '17 at 09:45
  • Hibernate is not considering the "extends Edition" but considers name of the dtype class in generating the column name . is there some thing to do with naming strategy of hibernate 5? – Sai Sep 27 '17 at 09:50

0 Answers0