Announcement Announcement Module
Collapse
No announcement yet.
How does really work bean initialization??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    hey...

    I tried that one - from setters to constructors, its not helping.

    And, sorry i was unable to attach any docs , guess i haven't been given the permission.

    Thanks,
    Sucheta.

    Comment


    • #17
      Hello,

      concerning attachments - take a look on an info just above "Manage attachments" button.
      Code:
      Valid file extensions: bmp doc gif jpe jpeg jpg pdf png psd txt zip
      So if you try to attach any java/xml code you have to zip them.

      Regards,
      Oleksandr

      Comment


      • #18
        Initialization of Map using Hibernate Annotation

        Hey,

        First of all, I am really very thankfull to you for your quick replies.

        My ques is even when I use Hibernate Annotations, is then also Map variable get initialized to null or with values from databse ?

        And when objects get persisted in database (when there is no further refernce to object or as soon as any fields are changed in the object)?

        Thanks,
        Sucheta.

        (I have attached the code, I checked logs and conclusion is setters are called after all objects get created that are being referenced in SessionFactory.)

        Comment


        • #19
          Hello,

          Hibernate annotations do not influence a way how object fields are initialized when object is created with new operator.
          They only establish mapping to database (and some related issues). Till you load object from DB or save it to DB they do not come into play. And anyway, first Hibernate constructs object with default (i.e. no-arg) constructor, by this construction all fields are set to their defaults according to Java Language Specification and only then Hibernate set fields to values acqured from DB.

          And when objects are persisted - when you persist them i.e. when you flush/commit session (directly or indirectly, by means of Spring Hibernate template or declarative transaction mangement).

          More exactly, if objects are attached to the session they are saved by flush()/commit() and if you work with detached objects you need to persist them explicitly (e.g. saveOrUpdate) before flush/commit. There are to many details about this process that just can not be covered in a post - their explanation requires if not the whole book, then at least 1-2 chapters. And my strong suggestion is to read carefully one of the good books about Hibernate, preferably, "Java Persistence with Hibernate. Second Edition of Hibernate in Action" by Christian Bauer and Gavin King (latter is main developer of Hibernate AFAIK).

          BTW, I really do not see how code attached to your post relates to the problem from which this thread has started.

          Regards,
          Oleksandr

          Comment


          • #20
            Hey,

            See, I want Map to be loaded with values from database only when dealersite (boolean variable) is false else not.
            Is there any way to do it? (will the current code do that? )

            Thanks,
            Sucheta.

            Comment


            • #21
              Originally posted by Sucheta24 View Post
              Hey,

              See, I want Map to be loaded with values from database only when dealersite (boolean variable) is false else not.
              Is there any way to do it? (will the current code do that? )

              Thanks,
              Sucheta.
              No, if you want to load some property from DB selectively you shoukd not map this property at all and then load it manually. It looks as if your code has other problems as well, but I'm not expert in the Hibernate annotations (and here is not Hibernate forum) so I'm not sure if they really exist and would not discuss them. Try to post your question in some forum devoted to Hibernate (or at least into the Data Access forum on this site) then you may found better answer.

              Regards,
              Oleksandr

              Comment


              • #22
                Hey,

                Ok thanks for your interest and advice. I will post in Data Access forum.

                Regards,
                Sucheta.

                Comment

                Working...
                X