facebook

Newbie Questions

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • #268257 Reply

    ls_toronto
    Member

    Hello;

    I am trying to figure out the GUI for the Hibernate Reverse Engineering.

    On the last page of the wizard I can including referencing tables. If I click this I get a list of tables with foreign keys to my current table.

    So far so good.

    Now if I select one of the tables I need to specify a class name and an ID generator. I am lost what to put here.

    Can someone direct me to some documentation that explains how this feature works?

    Thanks,

    Luke

    #268288 Reply

    ls_toronto
    Member

    Ok, if I selected one of the referencing table I get a list of the fields. When I selected the foreign key name I get a form on the right looking for a JDBC Type, Property Name and Hibernate type.

    Can someone describe what these do or point me to some documentation on this feature?

    Thanks,

    Luke

    #268289 Reply

    ls_toronto
    Member
    #268307 Reply

    ls_toronto
    Member

    Continuing with this thread…

    I have a Patient table for a foriegn key of countryId referencing country (countryId).

    But when my PatientDAO is created, there is no List findByCountry (which I was expecting).

    Am I missing a configuration in my hibernate reverse engineering step?

    Should I just create a Patient object with the country set and use the findByExample, or the findByProperty during run time or is it better practise to add this method to the generated DAO (which I assume means it will be over written if I generate again)?

    I am asking this question as someone new to myeclipse and hibernate (double learning curve).

    I would really appreciate it if someone could through me a tip.

    Thanks,

    Luke

    #268308 Reply

    Riyad Kalla
    Member

    Luke,
    Depending on which options you chose to generate finders (by default it does ID fields only, but if you select precise finder methods, it will generate a finder for every field). I think that’s what you want.

    #268316 Reply

    ls_toronto
    Member

    Ok, I have that option selected in the first screen of the wizard.

    I am reverse engineering country. When I selected included references A<-B (last screen) I see participant and patient table (both have a foreign key countryId pointing to the country table).

    I click finished and I see in the Country Pojo I have a set for Patients and Participants (as expected). However nond of the generated DAOs (Country, Patient or Participant) contain any logic to get these lists.

    I think I have something configured wrong, or I am expecting something to be there that is not.

    Am I explaining this clearly?

    Thanks for your help.

    Luke

    #268324 Reply

    Riyad Kalla
    Member

    Luke,
    I might be misunderstanding… but if you have two classes:
    A and B

    and A has a 1:m relationship to B and you reverse them, you will get a POJO for A and B, and a DAO for A and B… but in order to get the list of B that A refers to… that method will be on A… a.getBList() or something.

    Did I totally misunderstand you?

    #268326 Reply

    ls_toronto
    Member

    Ok, if I reverse engineer for Country selecting included references A<-B (last screen) I get a Patient and Participant set in the Country POJO but neither the PatientDAOs or ParticipantDAOs contain any reference to country.

    Then if I reverse engineer for the Patient table and Participant table (seperately) without including any references I get a findByCountryID in each of the generated DAOs (which was not there in the DAO generated when I reverse engineered the Country table and its references).

    This now gives me a way to populate the patient and participant sets in the Country POJO (ie: PatientDAO.findByCountryId, ParticipantDAO.findByCountryId).

    What is confusing me is why this was not made for me by reverse engineering the Country table including references A<-B.

    Since I am still figuring this out I am just ensuring I am not missing anything important.

    Thanks,

    Luke

    #268327 Reply

    ls_toronto
    Member

    Hi Riyad;

    and A has a 1:m relationship to B and you reverse them, you will get a POJO for A and B, and a DAO for A and B… but in order to get the list of B that A refers to… that method will be on A… a.getBList() or something.

    Yes, this is what I want. My confusion is in the A DAO there is no getBList().

    Thanks,

    Luke

    #268331 Reply

    Riyad Kalla
    Member

    Luke, gotcha. Ok so A’s 1:m relation with B is a property of A… not the DAO. All the DAOs help you do is get references to the entities that they represent, not other entities. So you might do something like this:

    
    A instanceA = aDAO.findByID(new Integer(1));
    List listOfB = instanceA.getBList();
    

    That’s all horrible peusdo code but I hope it makes sense.

    #268333 Reply

    ls_toronto
    Member

    Makes sense, thank you. I think I was expecting something in the DAO that may is not there.

    I guess the only thing I don’t like is the fact I have to do a seperate reverse engineer on B to get the findByAId method. I am still not sure why the reverse gen of A does not provide this in the B code (since I creates a find for every other field in B).

    This is a great product BTW!

    Thanks,

    Luke

    #268337 Reply

    Riyad Kalla
    Member

    Luke,
    Have you tried selecting all your tables at once and doing the rev-eng? It’s pretty good about capturing all the relationships in one go. I normally just select all the tables, fire up rev-eng and hit Finish.

    And thank you for the kind words!

    #268343 Reply

    ls_toronto
    Member

    Hmm. I tried that however I get the same problem. DAO B doesn’t contain findByAId, although Pojo A contains a collection of B(s) as a member.

    I need to go back and generate for B on its own to get the findByAId method.

    I think I have something checked in the GUI from previous gens that should not be checked or I have something wrong with my table definitions (although the fact the GUI detects the relationships makes me think this is not the case).

    Luke

    #268345 Reply

    ls_toronto
    Member

    And when I go to regen B I have to ensure nothing is checked on the last page. Otherwise there is not reference for AId in the DAO at all.

    #268356 Reply

    ls_toronto
    Member

    Ah, just noticed something. When I do all the tables at once, I have a A object an a member in my B pojo, rather than a AId.

    This is much better since when looking a B data I may need to get info from the associated A record.

    But why does the B DAO not have a findByA(Object A)?

Viewing 15 posts - 1 through 15 (of 27 total)
Reply To: Newbie Questions

You must be logged in to post in the forum log in