Reputation: 129
This is project is created spring boot with hibernate and mySql, ::Scenario :: In a apartment details going to store in parent table,the sub table contains block,floor,flat startingand ending numbers. Click Here to see form sample
I created 2 tables ,which is i need to do relationship parent table with child table,in parent table i given
@OneToMany @JoinColumn(name="propertyid",referencedColumnName="propertymasterfk") private List blockListPropSub;
This column is need to do relation ship with
@Column(name="propertymasterfk") private int propertymasterfk;
Here is a complete code snippets Parent Table EntPropertyMaster
@Entity
@Table(name="Property_Master")
public class EntPropertyMaster implements Serializable{
private static final long serialVersionUID = 6162594257264775391L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="propertyid")
private int property_id;
@NotNull
private String property_name;
@NotNull
private String address1;
@NotNull
@Column(columnDefinition="varchar(15) default'None'")
private String address2;
@NotNull
private String city;
@NotNull
private String state;
@NotNull
private String country;
@NotNull
private int zipcode;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="propertyid",referencedColumnName="propertymasterfk")
private List<EntPropertySub> blockListPropSub;
}
Here This is Child table EntPropertySub
@Entity
@Table(name="propertysub")
public class EntPropertySub implements Serializable {
private static final long serialVersionUID = 810618405796553525L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="propertysubpk")
private int propertySub_pk;
@Column(name="propertymasterfk")
private int propertymasterfk;
@NotNull
private String blockname;
@NotNull
private int floors;
@NotNull
private String flatstart;
private String flatend;
}
While i execute The Error Says Unable to map collection com.vfraternity.process.entity.EntPropertyMaster.blockListPropSub
Here is a compete Error Log
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-10-20 12:35:43.638 ERROR 17844 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unable to map collection com.vfraternity.process.entity.EntPropertyMaster.blockListPropSub at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) ~[spring-context-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) ~[spring-context-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M4.jar:2.0.0.M4] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M4.jar:2.0.0.M4] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M4.jar:2.0.0.M4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M4.jar:2.0.0.M4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M4.jar:2.0.0.M4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M4.jar:2.0.0.M4] at com.vfraternity.VfSpringBootMain.main(VfSpringBootMain.java:12) [classes/:na] Caused by: org.hibernate.AnnotationException: Unable to map collection com.vfraternity.process.entity.EntPropertyMaster.blockListPropSub at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1604) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:871) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:786) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:725) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1621) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1589) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:358) ~[spring-orm-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:384) ~[spring-orm-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1761) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1698) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4] ... 16 common frames omitted Caused by: org.hibernate.cfg.RecoverableException: Unable to find column with logical name: propertymasterfk in org.hibernate.mapping.Table(property_master) and its related supertables and secondary tables at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:831) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:243) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1594) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] ... 31 common frames omitted Caused by: org.hibernate.MappingException: Unable to find column with logical name: propertymasterfk in org.hibernate.mapping.Table(property_master) and its related supertables and secondary tables at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:826) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] ... 33 common frames omitted
Please any one help to solve this..
Upvotes: 0
Views: 2004
Reputation: 211
This changes will work... For Parent Table
@OneToMany(cascade=CascadeType.ALL)
@JoinTable(name="propertysub",joinColumns=@JoinColumn(name="propertyid"),
inverseJoinColumns=@JoinColumn(name="propertysubpk"))
private List<EntPropertySub> blockListPropSub = new ArrayList<EntPropertySub>();
For Child table
@ManyToOne(cascade=CascadeType.ALL)
private EntPropertyMaster propertymasterfk = new EntPropertyMaster();
Upvotes: 1