问题
I am getting the below error. But i am unable to find what the error is.
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1481)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1419)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 91 more
Thanks in advance.
回答1:
find the source code of Configuration,go to line 1481,there is a reference used in that line and the reference is null.
then dig that how this reference is assigned,and trace it back.
or you can debug it.
回答2:
I just stumbled on this issue and @BlackJoker's advice although a bit generic is exactly what one should do.
In my case the error occured in hibernate-core:4.3.1.Final on line 1499 but with the same error.
The code tries to resolve and foreign keys / mappings. I had an entity with an @OneToOne mapping that had as type not the required Entity but String.
@Entity
@Table(name = "MyTable")
public class BrokenEntity {
@Id
@Column(name = "id")
private String flow;
@Id
@JoinColumn(name = "other_id")
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private String group;// Now hibernate tries to map the String as entity and fails!
}
Removing the mapping or replacing java.lang.String with a valid entity resolves the problem.
回答3:
As you have not pointed anything more about your classes, please look at Hibernate throwing NullPointerException - processFkSecondPassInOrder to take a pointer to the above error...
回答4:
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1481)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1419)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
That error means you put an annotation to an object that is missing. Ex: you put @JoinColumn
into private Car car
but that Car
object is nowhere to be found.
回答5:
The exception is called NullPointerException
which indicates you are trying to use an object that is not created, this normally happens when you declare an object, forget to create it and try to use it.
来源:https://stackoverflow.com/questions/15448116/how-i-can-find-the-exact-error