|
Re: CommitManager.sort not working if primary key is a byte array [message #1803386 is a reply to message #1796358] |
Wed, 27 February 2019 18:08  |
Eduardo Garcia Messages: 2 Registered: August 2018 |
Junior Member |
|
|
I deal with UUID by using String as property type (having byte[] or raw in DB), and with helpers like custom made converters and sequencers (UUIDAttributeConverter, UUIDSequence), I was able to generate a UUID at insert time, after some work.
About deleting part, I had same issues as you are reporting, using String as primary key (UUID), and storing key as byte[] in database, not being able to delete by using EntityManager.remove(object):
java.lang.ClassCastException: [B cannot be cast to java.lang.Comparable
I found a work-around by using createCriteriaDelete as follow:
Considering i'm passing "ido" as the key of the object to remove (String in my case), this is how I delete a row for this scenario:
em.getTransaction().begin();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaDelete<MyEntityClass> q = cb.createCriteriaDelete(MyEntityClass.class);
Root<MyEntityClass> root = q.from(MyEntityClass.class);
q.where(cb.equal(root.get(MyEntityClass_.identry),ido));
em.createQuery(q).executeUpdate();
em.getTransaction().commit();
I hope this trick help someone else having same issue.
|
|
|
Powered by
FUDForum. Page generated in 0.01900 seconds