Reputation: 6581
first my Code.
Specialization
@Entity
public class Specialization {
@Id
private String name;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="att_id", referencedColumnName="ID")
private List<Attribute> attributes;
//Getters and Setters
}
Attribute
@Entity
public class Attribute {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
private String name;
private double scaling;
//Getters and Setters
}
My Problem is that i get a following Exception:
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1460)
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:864)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:779)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:728)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
... 98 more
This Exception only Occurs after adding the attribute attributes
to the Class Specialization
. So without this attribute everything works fine, but if I add this attribute, the exception comes up. I don't get what I'm doing wrong.
Maybe somebody could find my mistake?
Additional information:
Hibernate Core Version: 4.3.7. Final.
There is another Entity GameClass
with a oneToMany relationship to Specialization => Every GameClass
has multiple Specialization
s and every Specialization
has multiple Attribute
s.
Don't know if this matters but this is a Spring-Boot application
Upvotes: 4
Views: 4770
Reputation: 33
May not be silver bullet, but For me it went away when I removed referencedColumnName
from below:
@JoinColumn(name="att_id")
Upvotes: 0
Reputation: 6581
I've got my mistake. Sleeping a bit helped. I've mixed up the relations.
If one Specialization
has many Attribute
s, the annotations should look like this:
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="specc_id", referencedColumnName = "name")
private List<Attribute> attributes;
and NOT like this:
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="att_id", referencedColumnName="ID")
private List<Attribute> attributes;
Upvotes: 4