NullPointerException when updating or deleting multiple entities of same type with non-comparable IDs

Description

If in composite-id is a field of type byte[] then removing more than one entity throws NullPointerException.

it doesnt work on Hibernate 4.3.0.Final, It worked on Hibernate 4.2.8.Final.

EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpaDemo");

EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Query query = em.createQuery("select s from MyEntity s");
List l = query.getResultList();//returns 3 objects
em.remove(l.get(0));
em.remove(l.get(1));//throws exception

java.lang.NullPointerException
at org.hibernate.type.AbstractStandardBasicType.compare(AbstractStandardBasicType.java:221)
at org.hibernate.type.ComponentType.compare(ComponentType.java:230)
at org.hibernate.action.internal.EntityAction.compareTo(EntityAction.java:171)
at org.hibernate.engine.spi.ExecutableList.add(ExecutableList.java:222)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:219)
at org.hibernate.event.internal.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:299)
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:160)
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:916)
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:892)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:1214)
at hibernatetest.Main.test(Main.java:23)
at hibernatetest.Main.main(Main.java:9)

Attachments

3

Activity

Show:

Former user June 21, 2016 at 7:48 PM

Fixed in master, 5.1, and 5.0 branches.

Former user June 21, 2016 at 7:48 PM

This affects all ID types that are not Comparable or contain an ID type that is not Comparable, types such as byte[], Byte[], char[], Character[], and UserType.

The fix only checks for a sorted ExecutableList when hibernate.order_updates=true or hibernate.order_inserts=true.

When hibernate.order_updates=true or hibernate.order_inserts=true, IncomparableComparator.INSTANCE is used for byte[], Byte[], char[], Character[]. If a UserType is used, it must implement Comparable; otherwise ClassCastException will continue to be thrown.

Hack Kampbjørn May 19, 2016 at 9:03 AM

This is not limited to byte arrays, it affects any custom type used as an ID or part of an embededId that does not implement Comparable. The solution was simple just implement Comparable.

Former user May 2, 2016 at 8:38 PM

Yes, this will be fixed in 5.0.10 and 5.1.1, within the next 3 weeks or so.

Alessandro Polverini April 30, 2016 at 5:29 PM
Edited

Today this bug hit me hard.

Is there a timeline for a release that fixes this problem?

Fixed

Details

Assignee

Reporter

Labels

Original estimate

Time tracking

No time logged16h remaining

Components

Fix versions

Affects versions

Priority

Created February 25, 2014 at 1:09 PM
Updated June 30, 2016 at 4:22 PM
Resolved June 21, 2016 at 7:48 PM