Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Hibernate Transient Annotation (JSF)

Options
  • 19-08-2010 1:41pm
    #1
    Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭


    I have an entity structure as follows:

    Appraisal - > Interims-> Questions -> Score
    Each entity has various different attributes that get persisted to the database.

    I use JSF and richfaces to present the user with a screen that allows them enter ratings and various such things. At the end of each section I average out all the scores from the questions and present it to the user. This averageScore attribute is hanging off the Interim entity. On initial generation of the page, the average score is calculated correctly.

    Here is what I want to do:
    I want to either have a button to re-calculate the score using Ajax or use the <a4j:support> tag to fire an onchange event on the rating drop down so that the score is recalculated each time scores are modified.

    I've done all this successfully and I can see the getAverageScore() method being called on the Interm object, this in turn gets all the questions in it's collection and does the tally. The averageScore attribute is annotated with the transient tag and is not persisted to the database.

    My problem is, I ask the commandbutton to rerender the averageScore label on the page but it does not change. It's driving me potty and I can't figure out why! Please help me try solve this. If I haven't explained it clearly enough, let me know and I'll try to provide more info.


Comments

  • Registered Users Posts: 1,998 ✭✭✭lynchie


    You mean when you load the Interim entity it loads up all its associated Questions? If so, have you got the link between Interim and Question defined to use lazy loading?


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    It's an EAGER fetch from that point.

    My initial scope is request then I use the <a4j:keepAlive> tag to manage my properties on the bean because I never navigate away from that page when doing the editing.


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    Ok, it turns out that despite the CascadeType being set to ALL you need another attribute set called orphanRemoval.

    This allows entities to be deleted from their parent attribute from the database.
    Kind of an annoying problem but hopefully this will help someone else.

    This is fine for this particular entity but what happens in future if I develop functionality that requires history? I want to delete the object by incrementing the "deleted" attribute as opposed to deleting the actual row ... food for thought.

    EDIT: I'm also aware that my grasp of hibernate isn't that strong but it's all a big learning curve!

    How do I set the Question to Resolved in the thread title?


Advertisement