Hi Craig, I have just created a JIRA.
best regards Łukasz ----- Original Message ---- From: Craig L Russell <[EMAIL PROTECTED]> To: [email protected] Sent: Thursday, 6 September, 2007 4:29:17 PM Subject: Re: Id column = null? Hi Łukasz, Can you please file a JIRA on this? The @Id annotation on the getId was illegal since it didn't have a corresponding setId method. This should have been flagged as an error. Thanks, Craig On Sep 6, 2007, at 6:56 AM, Xh wrote: > Hi Christian! > > Yes, You are absolutely right, I didn't have setter for that field. > > thanks! > best regards > Łukasz > > ----- Original Message ---- > From: Christian Defoy <[EMAIL PROTECTED]> > To: [email protected] > Sent: Thursday, 6 September, 2007 3:46:58 PM > Subject: Re: Id column = null? > > Hi, > > It is probably because you do not have a setId() method in your > WebPage class. Since you are using Property access, you must define > setters for every field (or at least that's how I understand it). If > you were using Field access, you wouldn't have that issue. > > Hope this helps! > > Christian > > On 9/6/07, ben short <[EMAIL PROTECTED]> wrote: >> Are you doing all your work within a transacion? I wonder if the ids >> are not being set as ou havent tried to access them within a >> transaction. >> >> On 9/6/07, ben short <[EMAIL PROTECTED]> wrote: >>> Maybe you could try and load one of the WebPage objects directly >>> rather than via the WebModule and see if the id gets set? >>> >>> On 9/6/07, Xh <[EMAIL PROTECTED]> wrote: >>>> Hi Ben! >>>> >>>> Both WebModule and WebPage have id column name 'id'. >>>> >>>> best regards >>>> Łukasz >>>> >>>> >>>> ----- Original Message ---- >>>> From: ben short <[EMAIL PROTECTED]> >>>> To: [email protected] >>>> Sent: Thursday, 6 September, 2007 3:13:59 PM >>>> Subject: Re: Id column = null? >>>> >>>> Whats the id column name on the WebPage table? >>>> >>>> On 9/6/07, Xh <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> >>>>> To: [email protected] >>>>> 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 <[EMAIL PROTECTED]> 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 >>>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> ___________________________________________________________ >>>> NEW Yahoo! Cars - sell your car and browse thousands of new and >>>> used cars online! http://uk.cars.yahoo.com/ >>>> >>> >> > > > > > > ___________________________________________________________ > Want ideas for reducing your carbon footprint? Visit Yahoo! For > Good http://uk.promotions.yahoo.com/forgood/environment.html Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp! ___________________________________________________________ Want ideas for reducing your carbon footprint? Visit Yahoo! For Good http://uk.promotions.yahoo.com/forgood/environment.html
