Hi All!

I have build two entities atop existing database.
 I have successfully created OneToMany   bidirectional mapping.
The mapping is WebModules (one) - WebPage (many)

I can fetch WebModules, display their IDs and iterate through associated 
WebPages.
 BUT WebPages IDs are set to null.

 For example, the below code:

// wef is my SessionBean, it calls WebModule's NamedQuery and returns found 
module
WebModule module = wef.findWebModuleByName("Add");

// module id is displayed properly, e.g. 2

response.getWriter().write(
        module.getId() + ":" + module.getDescription() + "<br/>");

// iterate through associated WebPages

for (WebPage page : module.getPages()) {

// id is displayed as null
// title is displayed properly

    response.getWriter().write("<br/>" + page.getId());
    response.getWriter().write("<br/>" + page.getTitle());
}

Of course the pages' ids are not null, they are primary keys with automatically 
generated identities.

I don't get it, maybe it's something wrong with my classes?
 Here they are:

@Entity
 @Table(name="dw_modules",schema="dw")
 @NamedQuery (
     name = "findWebModuleByName",
     query = "SELECT wm FROM WebModule wm WHERE wm.name = :name"
 )
 public class WebModule implements Serializable {
     private Integer id;
     private Set<WebPage> pages = new HashSet<WebPage>();
 ...
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     public Integer getId() {
         return id;
     }
 ...
 }
 
 @Table(name = "dw_pages", schema = "dw")
 public class WebPage implements Serializable {
     private Integer id;
     private WebModule parentModule;
 ...
...
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     public Integer getId() {
         return id;
     }
 ...
 }
 
thanks for any hints
 best regards
 Ɓukasz




      ___________________________________________________________ 
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  
http://uk.promotions.yahoo.com/forgood/environment.html

Reply via email to