|
View:
New views
15 Messages
—
Rating Filter:
Alert me
|
|
|
hibernate problems in webflows..Hi folks, I cannot get hibernate saving to work inside a
webflow. Is this supposed to work? All I am getting is errors. I have one class that holds a number of other classes.
It will let me save the container class, but it is not persisted to the
database at all. If I go and look at the other pages, the classes I just
saved don’t show up. Then when I try to add the list of items in
the container, and try and save them, it says “[234373]
builder.ClosureInvokingAction Exception occured invoking flow action: not-null
property references a null or transient value: OwnershipSnapshot.series; nested
exception is org.hibernate.PropertyValueException: not-null property references
a null or transient value: OwnershipSnapshot.series” – but that series
property is a reference to the class I just saved! And when I print out all the properties of the class, all of
the hibernate-related closures are listed as null, things like beforeInsert and
beforeUpdate – these were null properties on the class, where it usually
lists a closure with an ID and some other information. I had to comment
these two closures out to even get the save() function to work at all –
before that it would say I was trying to invoke a null action when I tried to
save. I have been struggling with this for several days now.
Usually this means there’s either something I don’t know, or there’s
something wrong with the tool I’m trying to use. I would really
like NOT to start over without using webflows. Any help would be greatly
appreciated. Thanks, Pam |
|
|
scaffolding code has errors?Forgive the noobie post, but this seems odd
Scaffolding generates invalid code. I made a toy BBS system as a learning tool. has Forums, which have a one-to-many relationship to Postings. Set up the domains, did generate-all. Hmm... if I go and edit a posting I get a select tag, but the initial value is ignored, and the for="forum"> isn't even valid (needs to match the select) <tr class="prop"> <td valign="top" class="name"> <label for="forum">Forum:</label> <-- oops, not valid! </td> <td valign="top" class="value ${hasErrors(bean:posting,field:'forum','errors')}"> <g:select optionKey="id" from="${Forum.list()}" name="forum.id" value="${posting?.forum?.id}" > <-- ignored </g:select> </td> </tr> and the generated HTML <tr class="prop"> <td valign="top" class="name"> <label for="forum">Forum:</label> </td> <td valign="top" class="value "> <select name="forum.id" id="forum.id" > <option value="1" >Forum : 1</option> <option value="3" >Forum : 3</option> <option value="4" >Forum : 4</option> </select> </td> </tr> it also seems strange to me that it generates a select statement at all. After all, the usual reason for a one-to-many relationship is as a has-A relationship. Wouldn't a 'hidden' or something make more sense? Or am I being a clueless noobie here? The relevant domain classes class Forum { String name static hasMany = [postings:Posting] } class Posting { String title String post static belongsTo = [forum:Forum] } I've tried a bunch of refactorings, etc. Other than some trivial changes to field names this is pretty much the example in 5.2.1.2 of the manual and scaffold code. But it's broken. Is this a bug? That seems unlikely, I'm such a noob, and it seems like it's such a common thing to do in the real world that it'd be pretty apparent the scaffold code was broken. Thanks, Annie the noob --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: scaffolding code has errors?I came across this as well. Looks like it has been logged as a bug:
http://jira.codehaus.org/browse/GRAILS-3000 As to your other question, making it a hidden field would make it so that you could not select a parent class when creating a child class if you accessed the child class create action directly (without going through the parent class's edit action). It's debatable whether you would ever really do this in the real world but I think the scaffolding views are really just intended as a way to get an app up and running quickly and are expected to be replaced. I, too, am a bit of a new to Grails so I could be mistaken. Jason On Thu, Jul 3, 2008 at 5:28 PM, Anne Ogborn <anne@...> wrote: > Forgive the noobie post, but this seems odd > > Scaffolding generates invalid code. > I made a toy BBS system as a learning tool. has Forums, which have a > one-to-many relationship to Postings. Set up the domains, did generate-all. > Hmm... > if I go and edit a posting I get a select tag, but the initial value is ignored, and the for="forum"> isn't even valid (needs to match the > select) > <tr class="prop"> > <td valign="top" class="name"> > <label for="forum">Forum:</label> <-- oops, not valid! > </td> > <td valign="top" class="value > ${hasErrors(bean:posting,field:'forum','errors')}"> > <g:select optionKey="id" from="${Forum.list()}" > name="forum.id" > value="${posting?.forum?.id}" > <-- ignored > </g:select> > </td> > </tr> > > and the generated HTML > <tr class="prop"> > > <td valign="top" class="name"> > <label for="forum">Forum:</label> > </td> > <td valign="top" class="value "> > <select name="forum.id" id="forum.id" > > <option value="1" >Forum : 1</option> > <option value="3" >Forum : 3</option> > <option value="4" >Forum : 4</option> > > </select> > </td> > </tr> > > > it also seems strange to me that it generates a select statement at all. > After all, the usual reason for a one-to-many relationship is as a has-A relationship. Wouldn't a 'hidden' or something make more sense? > > Or am I being a clueless noobie here? > > The relevant domain classes > > class Forum { > String name > static hasMany = [postings:Posting] > } > > > class Posting { > String title > String post > static belongsTo = [forum:Forum] > } > > I've tried a bunch of refactorings, etc. Other than some trivial > changes to field names this is pretty much the example in 5.2.1.2 > of the manual and scaffold code. But it's broken. > > Is this a bug? That seems unlikely, I'm such a noob, and it seems like it's such a common thing to do in the real world that it'd be pretty apparent the scaffold code was broken. > > Thanks, > > Annie the noob > > > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: scaffolding code has errors?Thanks, I really, really promise I went looking for this in JIRA first. I just missed it. > As to your other question, making it a hidden field would > make it so > that you could not select a parent class when creating a > child class > if you accessed the child class create action directly > (without going > through the parent class's edit action). That seems like the semantics that's wanted here - it makes no sense, for example, in my example, to have a posting that isn't to some forum. > It's > debatable whether you > would ever really do this in the real world but I think the > scaffolding views are really just intended as a way to get > an app up > and running quickly and are expected to be replaced. OK, at the very least it's confusing for us noobies. Well, it's been JIRA'ed, there's a patch in, all is well in my soul. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: scaffolding code has errors?> Thanks, I really, really promise I went looking for this in JIRA first.
> I just missed it. No worries, there's a lot of JIRA issues in there with the word "scaffolding" in them - it took some poking around to find it. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: hibernate problems in webflows..> I have been struggling with this for several days now. Usually this means
> there's either something I don't know, or there's something wrong with the > tool I'm trying to use. I would really like NOT to start over without using > webflows. Any help would be greatly appreciated. If no-one else answers, can you package up a sample project that demonstrates the problem and send it to me? I'll take a look. I know almost nothing about the webflow support, but I should be able to work out what's going on with a practical example in my hands (and a debugger :) ). Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: hibernate problems in webflows..I can only remotely guess, and it's only a semi-educated guess (I'm no grails expert, without seeing the code it is even harder :) but:
Make sure you are not using the *it variable within the beforeInsert and beforeUpdate closures, calling a closure within a closure can cause name shadowing issues within the second closure. Another idea is that maybe you are replacing the container.series set (or list or whatever) with your own, hibernate doesn't like that you mess around with its managed collections. If that's the case, try clearing the collection and adding all the elements. HTH xD, Miguel On Fri, Jul 4, 2008 at 7:38 AM, Peter Ledbrook <peter@...> wrote:
|
|
|
RE: hibernate problems in webflows..Hi Peter,
Thanks for the response. Here's a test application that I was working with when I was figuring out webflows. Interestingly enough, this code worked before I upgraded to 1.0.3 (at least, I'm pretty sure it did), now it does not. The error is very similar to the error in my code, but it's saying that something is transient that I am pulling directly from the saved database, rather than something I just created and called .save(flush:true) on. Thanks for being willing to help. What debugger do you use? I am trying to use IntelliJ, but it still doesn't shed any light on the problem. Thanks, Pam > -----Original Message----- > From: Peter Ledbrook [mailto:peter@...] > Sent: Friday, July 04, 2008 2:39 AM > To: user@... > Subject: Re: [grails-user] hibernate problems in webflows.. > > > I have been struggling with this for several days now. Usually this > means > > there's either something I don't know, or there's something wrong > with the > > tool I'm trying to use. I would really like NOT to start over > without using > > webflows. Any help would be greatly appreciated. > > If no-one else answers, can you package up a sample project that > demonstrates the problem and send it to me? I'll take a look. I know > almost nothing about the webflow support, but I should be able to work > out what's going on with a practical example in my hands (and a > debugger :) ). > > Cheers, > > Peter > > -- > Software Engineer > G2One, Inc. > http://www.g2one.com/ > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > This attachment was removed. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
RE: hibernate problems in webflows..Hi Miguel, Thanks for the response. I’m not using the “it” variable, so
that problem can be ruled out. I just wanted to make sure I understood your comment about
container.series set. This is how I’m defining it: class OwnershipSnapshot implements Comparable, Serializable{ … OwnershipSnapshotSeries series static
belongsTo = OwnershipSnapshotSeries … } class OwnershipSnapshotSeries implements Comparable,
Serializable { … Set snapshots = new TreeSet() static hasMany =
[snapshots:OwnershipSnapshot] … def addToSnapshots(OwnershipSnapshot
snap) { snap.orderInSeries = snapshots.size()
+ 1 snapshots.add(snap) } … } Would that “Set snapshots = new TreeSet()” be what you are
referring to? I needed to be able sort the collection, which is why I’m using
a TreeSet rather than anything else. Or would having the custom addToSnapshots cause a problem? Thanks, Pam From: Miguel Ping
[mailto:miguel.ping@...] I can only remotely guess, and
it's only a semi-educated guess (I'm no grails expert, without seeing the code
it is even harder :) but: |
|
|
Re: hibernate problems in webflows..> Thanks for the response. Here's a test application that I was working with when I was figuring out webflows. Interestingly enough, this code worked before I upgraded to 1.0.3 (at least, I'm pretty sure it did), now it does not. The error is very similar to the error in my code, but it's saying that something is transient that I am pulling directly from the saved database, rather than something I just created and called .save(flush:true) on.
> > Thanks for being willing to help. The attachment has been stripped. Either change the file extension or send it to my e-mail address direct. > What debugger do you use? I am trying to use IntelliJ, but it still doesn't shed any light on the problem. IntelliJ. Are you debugging into the Grails code? That's what I'll probably be doing... Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: hibernate problems in webflows..> Thanks for the response. Here's a test application that I was working with when I was figuring out webflows. Interestingly enough, this code worked before I upgraded to 1.0.3 (at least, I'm pretty sure it did), now it does not. The error is very similar to the error in my code, but it's saying that something is transient that I am pulling directly from the saved database, rather than something I just created and called .save(flush:true) on.
> > Thanks for being willing to help. Hi Pamela, I finally worked out the problem and it doesn't really have anything to do with flows. In the setup of the flow you save the series and then add a new, empty structure to it. The problem is, that structure is still attached to the series in the "createStructure" action and so when you save the series, you also save the empty structure. However, the structure won't save because "baseOfStructure" is null - that's why you're getting the "not-null property" exception for OwnershipStructure.baseOfStructure. To be honest, I don't think you should be attaching the empty structure to the series during the setup. As far as I can tell, you don't need to. However, you should probably attach the _populated_ structure to the series in the "createStructure" action. Also, you don't need to save the structure explicitly - once it is attached to the series, saving the series will cascade to the structure. HTH, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
RE: hibernate problems in webflows..> -----Original Message----- > From: Peter Ledbrook [mailto:peter@...] > > I finally worked out the problem and it doesn't really have anything > to do with flows. In the setup of the flow you save the series and > then add a new, empty structure to it. The problem is, that structure > is still attached to the series in the "createStructure" action and so > when you save the series, you also save the empty structure. However, > the structure won't save because "baseOfStructure" is null - that's > why you're getting the "not-null property" exception for > OwnershipStructure.baseOfStructure. > > To be honest, I don't think you should be attaching the empty > structure to the series during the setup. As far as I can tell, you > don't need to. However, you should probably attach the _populated_ > structure to the series in the "createStructure" action. Also, you > don't need to save the structure explicitly - once it is attached to > the series, saving the series will cascade to the structure. > Thanks Peter, thank you very much. As you can tell, I'm still learning, although I probably should have seen that one. I've tried so many things, the code is just kind of jumbled up. I still can't get it to work in my "real" code - probably some of the other objects that are in the structure are also null, I'm just going to have to track it down, now that I know what to look for. Thanks again. About saving the structure and the cascading effect - It seems that if I don't call save on that structure directly, it doesn't show up in the lists or anything. Even if I put flush:true in the series save call. It seems to me that I have to save and flush the structure in order to get it to show up... You can try it and see... just comment out the save line for the structure. It's odd. I am understanding it wrong? Thanks... def createSeriesFlow = { setup { action { //println "in Action" //println params OwnershipStructureSeries series; if(params.series){ series = OwnershipStructureSeries.get(Long.parseLong(params.series.id)) } else{ series = new OwnershipStructureSeries(startDate:new Date()) } series.save(flush:true) OwnershipStructure structure = new OwnershipStructure() //series.addToStructures(structure) structure.seriesOrder = series.structures.size() + 1 flow.series = series //println flow return [owernshipSeries:series, ownershipStructure:structure] } on("success").to "createStructure" on(Exception).to "handleError" } createStructure { on("skip").to "addTransactions" on("save") { println "in Create Structure - save" println params println flow println flow.series if(!params.ownershipStructure) return error() SimpleDateFormat stupid = new SimpleDateFormat("MM/dd/yyyy") flow.series.startDate = stupid.parse( "${params.startDate_month}/${params.startDate_day}/${params.startDate_year}") println flow.series if(!(flow.series.validate() && flow.series.save(flush:true))) error () println "series saved: ${flow.series}" println flow.ownershipStructure Date newDate = stupid.parse( "${params.ownershipStructure.dateOfStructure_month}/${params.ownershipStructure.dateOfStructure_day}/${params.ownershipStructure.dateOfStructure_year}") println "newDate: ${newDate}" //flow.structure.dateOfStructure = stupid.parse( // "${params.ownershipStructure.dateOfStructure_month}/${params.ownershipStructure.dateOfStructure_day}/${params.ownershipStructure.dateOfStructure_year}") flow.ownershipStructure.dateOfStructure = newDate; println "imported date: ${flow.ownershipStructure.dateOfStructure}" flow.ownershipStructure.series= flow.series flow.ownershipStructure.baseOfStructure= Organization.get(Long.parseLong(params.ownershipStructure.baseOfStructure.id)) flow.ownershipStructure.seriesOrder= Integer.parseInt(params.ownershipStructure.seriesOrder) flow.ownershipStructure.notes= params.ownershipStructure.notes println flow.ownershipStructure if(!(flow.ownershipStructure.validate())) error() if(!(flow.series.validate() && flow.series.save(flush:true))) error () flow.ownershipStructure.save(flush:true) println flow.ownershipStructure }.to "addTransactions" on(Exception).to "handleError" } ... } --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: hibernate problems in webflows..I've modified it a little bit and it seems to work. The two points to note are:
1. I've added the organisation structure to the series before saving the latter 2. I've kept the "flush: true" when saving the series It seems that the session does not get automatically flushed inside webflow actions, or it may just be for transition actions. Can anyone with more web flow knowledge confirm? Anyway, here's the code: class OwnershipStructureSeriesController { def scaffold = OwnershipStructureSeries def createSeriesFlow = { setup { action { OwnershipStructureSeries series; if(params.series){ series = OwnershipStructureSeries.get(Long.parseLong(params.series.id)) } else{ series = new OwnershipStructureSeries(startDate:new Date()) series.save() } OwnershipStructure structure = new OwnershipStructure() structure.seriesOrder = series.structures.size() + 1 flow.series = series return [owernshipSeries:series, ownershipStructure:structure] } on("success").to "createStructure" on(Exception).to "handleError" } createStructure { on("skip").to "addTransactions" on("save") { println "in Create Structure - save" println params println flow println flow.series if(!params.ownershipStructure) return error() SimpleDateFormat stupid = new SimpleDateFormat("MM/dd/yyyy") flow.series.startDate = stupid.parse( "${params.startDate_month}/${params.startDate_day}/${params.startDate_year}") flow.series.merge() flow.structure = new OwnershipStructure( dateOfStructure: stupid.parse( "${params.ownershipStructure.dateOfStructure_month}/${params.ownershipStructure.dateOfStructure_day}/${params.ownershipStructure.dateOfStructure_year}"), series: flow.series, baseOfStructure: Organization.get(params.ownershipStructure.baseOfStructure.id), seriesOrder: params.ownershipStructure.seriesOrder?.toInteger(), notes: params.ownershipStructure.notes) flow.series.addToStructures(flow.structure) if(!flow.series.save(flush: true)) { println ">> Series errors: ${flow.series.errors.allErrors}" error() } else { success() } }.to "addTransactions" on(Exception).to "handleError" } addTransactions { println flow on("save").to "confirm" } confirm { on("confirm").to "summary" } summary { } handleError { //TODO } } } Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
RE: hibernate problems in webflows.. |