openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <>
Subject Linking Entities Creating too many cascading queries
Date Fri, 11 Sep 2009 07:25:15 GMT


I have a number of entities that are linked so I set there their cascade
type to REFRESH since each of the entities will have a ManyToOne
relationship to the other entities,  for example I have 3 entities, User,
Address, Country


Where more than one user can share the same Address and each Address will be
associated with a Country entity. So my definition in short is like this:


User Entity:


      @ManyToOne (cascade={CascadeType.REFRESH})

      private Address address;



Address Entity:


      @ManyToOne (cascade={CascadeType.REFRESH})

      private Country country;


Hope that makes sense.


What I find is that when I persist/merge a user entity, it also generates
SQL that updates the linked Address entity which in turn also generates SQL
that updates the Country entity. This seems like a load of redundant table
updates when I am only linking the entities together not updating any fields
in the Address or Country entities..


How do others usually achieve this?  Do you not use the cascade
functionality at all and just code the getters and setters manually? It
seems like this is the only other way I can achieve the desired behaviour.
As my entity relationships have become more complex, I am now facing stack
overflows as there may be reverse relationships between entities. 


The advantage of using CascadeType.REFRESH is that OpenJPA will create all
the join tables for me and I don't have to write any code to do this, also
the getters and setters are very simple and I can use lazy loading if
required. But it seems that all these redundant table updates causes a
significant performance hit.


So I want to know if I am taking the correct approach or there is a better


Thanks for any advice.




  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message