[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Are object references shared?

nalbion do-not-reply at jboss.com
Wed Feb 28 10:54:12 EST 2007


If I use JBoss, EJB3.0, JPA, Hibernate to do a query:

Query q = em.createQuery("SELECT c FROM City c WHERE c.country.id=?").setParameter(1,myCountry.id);
  | List cities = q.getList();
  | 
will the following be true? cities.get(i).country == myCountry

...ie, are object references shared, or will each city have it's own instance of Country such that (only) cities.get(i).country.equals(myCountry)

The second part of my question is along the same lines.  If different users load objects using similar queries, perhaps:
"SELECT c FROM City c WHERE c.country.id IN(?,?,?)" are new instances created for entities which have recently been loaded by another user?  Would the following return true?

for each ( aCity in userA.cities ) {
  |   for each ( bCity in userB.cities ) {
  |     if( aCity == bCity ) {
  |       // share same object, not just copies of same records
  |       return true;
  |     }
  |   }
  | }
  | return false;

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4023768#4023768

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4023768



More information about the jboss-user mailing list