openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ben short" <jamin.sh...@gmail.com>
Subject Re: Id column = null?
Date Thu, 06 Sep 2007 13:13:59 GMT
Whats the id column name on the WebPage table?

On 9/6/07, Xh <xhsaymyname@yahoo.co.uk> wrote:
> Hi Ben!
>
> Data already exists in database (so it is commited ;) ).
> All I try to do is to fetch those data.
>
> Besides, it is very weird that ID for WebModule works and for WebPage does not.
>
> Changing GenerationType to AUTO does not solve the problem.
>
> best regards
> Łukasz
>
> ----- Original Message ----
> From: ben short <jamin.short@gmail.com>
> To: users@openjpa.apache.org
> Sent: Thursday, 6 September, 2007 1:20:59 PM
> Subject: Re: Id column = null?
>
> Try changing to GenerationType to AUTO eg
>
>  @GeneratedValue(strategy = GenerationType.AUTO)
>
> I think that the GenerationType.IDENTITY dosent assign the ids to the
> rows until its commited to the db, so any relations are written to the
> db as nulls.
>
> Ben
>
> On 9/6/07, Xh <xhsaymyname@yahoo.co.uk> wrote:
> > 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
> >
>
>
>
>
>
>       ___________________________________________________________
> Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  http://uk.promotions.yahoo.com/forgood/environment.html
>
Mime
View raw message