• Post Reply Bookmark Topic Watch Topic
  • New Topic

An amazing issue when using in uuid generator  RSS feed

avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My application server is Jboss ver � 4.2
I have a stateless (facade) that call to a DAO (simple pojo class ).
Due to some restrictions (I need to create schema dynamically) I cant use injection , so I create the factory and bind it to the JNDI.

Immediately after I save an Object I call to find ,but I get null although that the Object will save to the DB after the transaction (the transaction boundaries are in the stateless) will end.

This behavior happen only when the ID is generated in uuid strategy in case that it generated in @GeneratedValue it will find the object.

In case that I use this code to find - em.find(Hotel.class, newHotel.getOrmID()); its okey in both cases , but I cant use this attitude because in the same transaction in another place I can call to another DAO and I want to see the Objects that I already saved .


public class TestSimpleDao {

private EntityManager em = null;

public EntityManager getEntityManager(){
EntityManagerFactory emf = null;
try {
emf = (EntityManagerFactory) new InitialContext().lookup("java:/Demo");
} catch (NamingException e) {
em = emf.createEntityManager();
return em;

public Hotel saveHotel(Hotel newHotel) {
newHotel = getEntityManager().find(Hotel.class, newHotel.getOrmID());
return newHotel;

<persistence-unit name="Demo">
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultComponentSafeNamingStrategy" />
<property name="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>


@Table(name = "HOTELS")
public class Hotel implements Serializable {
@GenericGenerator(name="system-uuid", strategy = "uuid")
protected String ormID = null;

private String name;
private String address;

private List<Room> rooms = new LinkedList<Room>();

private Hotel() {

public Hotel(String name, String address) {
this.name = name;
this.address = address;
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!