What I do here, not very clean but it works,
I have created an annotation called Sequence and then I place it on my bean as follow
@Sequence(name="TABLE_SEQ") where table_seq is the name of my Oracle sequence.
In my persistent class, I create a new persistent bean when needed with empty properties.
But I set already its id by doing this (pb is my persistent bean):
| StringBuilder sb = new StringBuilder("select ");
| Sequence seqAnnotation =
persistentBeanClass.getAnnotation(Sequence.class);
| if (seqAnnotation != null)
| sb.append(seqAnnotation.name());
|
| sb.append(".nextVal from dual");
|
| Query query = entityManager.createNativeQuery(sb.toString());
| Long id = new Long(((Number) query.getSingleResult()).longValue());
| pb.setId(id);
|
So your bean has the same id generated by the Oracle sequence, before comit. Hope this
helps
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4085466#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...