-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: An amazing issue when using in uuid generator
PostPosted: Mon Jun 18, 2007 12:54 pm 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
Hey,

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.

The issue that immediately after I save an Object I call to find but I get null although that the Object will commit 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 .


DAO:

Code:
public class TestSimpleDao {

   private EntityManager em = null;

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

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


Code:
<persistence>
  <persistence-unit name="Demo">
    <jta-data-source>java:/DemoDS</jta-data-source>
    <properties>
      <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"/>
    </properties>
  </persistence-unit>
</persistence>

Hotel:

Code:
@Entity
@Table(name = "HOTELS")
public class Hotel implements Serializable {
   @Id
    @GeneratedValue(generator="system-uuid")
    @GenericGenerator(name="system-uuid", strategy = "uuid")
    @Column(name="managed_element_id")
    protected String ormID = null;

    private String name;
    private String address;

    @OneToMany(cascade=CascadeType.ALL)
    @JoinColumn
    private List<Room> rooms = new LinkedList<Room>();

    private Hotel() {
    }

    public Hotel(String name, String address) {
        this.name = name;
        this.address = address;
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.