Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2013
    Posts
    108
    Rep Power
    0

    Default Basic Configuration question

    factory = new Configuration().configure().buildSessionFactory();

    In the above:
    1. Configuration() is a class
    2. configure() is a method in the Configuration class

    What is buildSessionFactory()? How can the configure() method have another method buildSessionFactory() inside it?

    I know it is possible to call a method inside another method, but how can a method have a definition of another method?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Basic Configuration question

    Its incomplete.

    2. configure() is a method in the Configuration class which returns an object
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Join Date
    Aug 2013
    Posts
    108
    Rep Power
    0

    Default Re: Basic Configuration question

    So if a method returns an object then we can call a method on that object.

    1. What happens if a method returns a Wrapper class object? Can we call a method defined for that object?
    2. What if a method returns void or returns a primitive variable can a method be called on them then?
    3. Is it possible to define a method inside another method?
    Last edited by suhaas.mohandos@gmail.com; 08-16-2013 at 12:58 PM.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Basic Configuration question

    Try it.

    Note: I'm not being a jackass, I try very hard to get you to realize how easy it is to answer the questions you are asking for yourself by telling you what should be obvious.
    Last edited by gimbal2; 08-16-2013 at 12:54 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,618
    Rep Power
    5

    Default Re: Basic Configuration question

    Perhaps you should go thru the tutorials linked in my signature.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    jmohandos304 is offline Member
    Join Date
    Apr 2014
    Posts
    90
    Rep Power
    0

    Default Re: Basic Configuration question

    Quote Originally Posted by gimbal2 View Post
    Its incomplete.

    2. configure() is a method in the Configuration class which returns an object
    Sorry for an invoking an old thread. But was just browsing through the Hibernate official documentation. The object returned by configure() is again a Configuration object. How is this configuration object different from the one we created using new Configuration() ? This is so confusing.

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: Basic Configuration question

    Hibernate uses the concept of chaining calls.
    Whereas some coding techniques would not return anything if all the method did was act upon the object in question, others will return the object itself, allowing you to chain calls together.

    This is stated in the documentation.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    jmohandos304 is offline Member
    Join Date
    Apr 2014
    Posts
    90
    Rep Power
    0

    Default Re: Basic Configuration question

    How about using:

    factory = new Configuration().buildSessionFactory();

  9. #9
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: Basic Configuration question

    Since configure() seems to read in the configuration from the 'hibernate.cfg.xml' then it's possible you would get an exception about invalid configs.

    Some of this stuff is now deprecated, by the way, from 4 onwards.

    Also, you can get most of this from simply reading the documentation. After all, that is the primary source of this stuff.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    jmohandos304 is offline Member
    Join Date
    Apr 2014
    Posts
    90
    Rep Power
    0

Similar Threads

  1. Basic GUI Question
    By stuckonjava in forum New To Java
    Replies: 3
    Last Post: 05-12-2012, 09:54 PM
  2. Basic JSP question..
    By casid in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 12-28-2009, 06:51 PM
  3. Basic question on OOP.
    By madthinker in forum New To Java
    Replies: 7
    Last Post: 01-26-2009, 07:09 PM
  4. Basic question about EJB
    By javaplus in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-15-2008, 05:44 PM
  5. Very basic question
    By gvi in forum New To Java
    Replies: 2
    Last Post: 10-30-2007, 06:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •