[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3030) NullPointerException happens in versioning

Roger Barnes (JIRA) noreply at atlassian.com
Tue Jul 14 22:10:12 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3030?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33609#action_33609 ] 

Roger Barnes commented on HHH-3030:
-----------------------------------

I've created a workaround for this.  It hasn't been thoroughly tested, but it appears to work.  It subclasses IntegerType and overrides the next method so that it's nullsafe.  To use it, replace the "integer" type in the version hbm definition with this one.

public class NullSafeVersionIntegerType extends IntegerType {
	/**
	 * This override avoids the NullPointerException thrown by IntegerType.next
	 * when a null "current" object is passed in, and returns a 1 instead
	 */
	@Override
	public Object next(Object current, SessionImplementor session) {
		Object next;
		if (current != null) {
			next = super.next(current, session);
		} else {
			next = new Integer(1);
		}

		return next;
	}

}

> NullPointerException happens in versioning
> ------------------------------------------
>
>                 Key: HHH-3030
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3030
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.5
>         Environment: any
>            Reporter: John
>            Priority: Minor
>
> Here is the stack trace:
> java.lang.NullPointerException
> 	at org.hibernate.type.IntegerType.next(IntegerType.java:59)
> 	at org.hibernate.engine.Versioning.increment(Versioning.java:25)
> 	at org.hibernate.event.def.DefaultFlushEntityEventListener.getNextVersion(DefaultFlushEntityEventListener.java:358)
> 	at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:250)
> 	at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:121)
> 	at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
> 	at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
> 	at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
> 	at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
> 	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
> 	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
>         ......
> The code is:
> 	public Object next(Object current, SessionImplementor session) {
> 		return new Integer( ( (Integer) current ).intValue() + 1 );
> 	}
> Should there be a null checking for the object "current"?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list