Java lang nullpointerexception in hibernate

Grails/Hibernate: Null Pointer Exception on versioning

Working with a legacy codebase in Grails. Under some conditions (we’re unclear exactly what) we get a mysterious NPE, stack trace as below, while doing a findBy. So far we’re sort of stymied; this appears in several fora for Hibernate but the responses seem to come down to «something is wrong with your schema.» It would be wonderful to find some additional detail to help us track the issue down. Update Thanks for the answer. Yes, it’s clear that at the point this NPE happens, version is null . The trouble is that when we look at it in the code, it’s not null . We’ve begun to suspect there’s a threading issue.

Caused by: java.lang.NullPointerException at org.hibernate.type.LongType.next(LongType.java:79) at org.hibernate.engine.Versioning.increment(Versioning.java:131) at org.hibernate.event.def.DefaultFlushEntityEventListener.getNextVersion(DefaultFlushEntityEventListener.java:387) at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:279) at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:151) at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219) at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027) at org.codehaus.groovy.grails.plugins.quartz.listeners.SessionBinderJobListener.jobWasExecuted(SessionBinderJobListener.java:58) at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1910) 

Of course, I don’t have all the details but. how could a threading issue nullify something? A record with a null version column is totally excluded?

Oh, no, just the opposite: it’s clear that at that point the version column is null. It’s just tough to figure out why because in the surrounding code it doesn’t appear to be. We have some confirmation of a threading issue, though, because we forced it to single thread and stopped getting the NPE. Still don’t understand the root cause, ‘tho.

Источник

Hibernate throwing NullPointerException

I’m trying to test Hibernate 4.2.1.Final with JPA using IntelliJ 12.1.3 and I am getting the following error. Everything seems to be setup OK (I let IntelliJ generate the mappings), and as I have zero experience with Hibernate and JPA I am at a loss as to why this is occurring. Why am I getting an NPE on EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(«Heroku-production»); ? main class:

public static void main(final String[] args) throws Exception < EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("Heroku-production"); EntityManager entityManager = entityManagerFactory.createEntityManager(); entityManager.getTransaction().begin(); Listresult = entityManager.createQuery( "from CountryCodesEntity", CountryCodesEntity.class ).getResultList(); for ( CountryCodesEntity countryCodesEntity : result ) < System.out.println( "Code (" + countryCodesEntity.getCode() + ") : " + countryCodesEntity.getNsenum() ); >entityManager.getTransaction().commit(); entityManager.close(); > 
May 16, 2013 3:02:49 PM org.hibernate.annotations.common.Version INFO: HCANN000001: Hibernate Commons Annotations May 16, 2013 3:02:49 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core May 16, 2013 3:02:49 PM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found May 16, 2013 3:02:49 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist May 16, 2013 3:02:54 PM org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: com/***/heroku/CountryCodesEntity.xml May 16, 2013 3:02:54 PM org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: com/***/heroku/StateCodesEntity.xml May 16, 2013 3:02:54 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) May 16, 2013 3:02:54 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 May 16, 2013 3:02:54 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000006: Autocommit mode: true May 16, 2013 3:02:54 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000401: using driver [org.postgresql.Driver] at URL [postgres://*********:***********@ec2-***-**-**-*****.compute-1.amazonaws.com:6232/******] May 16, 2013 3:02:54 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000046: Connection properties: Exception in thread "main" java.lang.NullPointerException at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:214) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117) at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:78) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2293) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2289) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1758) at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:96) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:913) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:898) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at Main.main(Main.java:20) 
 org.hibernate.ejb.HibernatePersistence com/***/heroku/CountryCodesEntity.xml com/***/heroku/StateCodesEntity.xml           

Источник

Читайте также:  Php add data to file
Оцените статью