4

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 Specializations and every Specialization has multiple Attributes.

Don't know if this matters but this is a Spring-Boot application

3
  • What version of Hibernate are you using? Commented Feb 22, 2015 at 1:20
  • you should post the relevant code where you're adding the list Commented Feb 22, 2015 at 7:41
  • Sorry i think i did not make myself clear. With adding the list i mean i add the List as an Attribute to the Class Specialization. So without this attribute everything works fine, but if I add this attribute, the exception comes up. The Version of Hibernate Core is 4.3.7. Final Commented Feb 22, 2015 at 8:50

2 Answers 2

4

I've got my mistake. Sleeping a bit helped. I've mixed up the relations.

If one Specialization has many Attributes, 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;
Sign up to request clarification or add additional context in comments.

Comments

0

May not be silver bullet, but For me it went away when I removed referencedColumnName from below:

@JoinColumn(name="att_id")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.