facebook

database fields created missing the asscociated field ?

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

    amir55
    Participant

    heelo all dear colleagues and teamforce work

    I have deployed a simple hibernate web project to MySQL of a Honey.java class which has an assciated field to a Bee class. see code

    public class Honey implements Serializable {
    private Integer id;
    private String name;
    private String taste;
    private Set<Bee> bees = new HashSet<Bee>(); // the question is on this line
    }
    //******************************** here is the question *********************
    // previous last line is a property bees which is an association one-to-many which does not applearin the database created.on the hibernate web deployment why>
    how to get it created as a field too ?

    All I get the id, name and taste.

    Therefore when I use reverse engineering using table to hibernate generation I get the java class missing the bees property as well as the honey.htm.xml generated misses the set entry which should look like as next

    <set name=”bees” inverse=”true”>
    <key column=”honey_id”></key>
    <one-to-many class=”Honey” />
    </set>

    so I suppose if we get the assciated filed in the database, we should get its entry in the mapping file.
    /********************************************************

    so many thanks

    Amir

    #286134 Reply

    Brian Fernandes
    Moderator

    Amir,

    Did you select both the Honey and the Bee table when reverse engineering?

    Also, do you explicitly declare a relationship in your database between these two tables? Please note that for MySQL, even though you declare a relationship, it will not be saved unless you use the InnoDB (or some other) storage engine (in some cases). If the relationship is not present in the database, it will not be picked up by our tools. A quick way to check is to create an ER diagram for your schema and see if a relationship line connects the two tables.

    Please let us know if you need further assistance.

    #286160 Reply

    amir55
    Participant

    hi dear Brian :

    so many thanks to you but my main questions were :

    1 – how to get database tabels of two related Honey and Bee classes in my UML
    2 – how to get database tabels of two related Honey and Bee classes in my Java

    Note if I use MySQL then the system tool should be able to recognise and hence use the InnoDB for showing the related classes in the db as shown in its corrispondent java or uml

    great greatitude of you

    Amir
    l.

    #286164 Reply

    Riyad Kalla
    Member

    Amir,
    It seems you have a lot of questions about this process, UML and Java source files, instead of trying to address each question which might in turn just create more questions, let me explain the entire process to you, how it works and how you can leverage all these tools to do what you want.

    1. Everything starts with the DB first. You need to create your tables exactly as you want them, with full FK relationships and indexes if necessary. NOTE: Brian already mentioned that some versions of MySQL, out of the box, use the MYISAM table engine which does *not* support relationships. So you will need to check your DB tables to make sure they are using the InnoDB database engine in order to define relationships between fields and tables.

    2. Simply naming fields a certain way does not implicitly define relationships between fields in MySQL. So for example, just because you have a field in Honey named “bees” does not tell MySQL to create a relationship. You have to manually create a foreign key between bees and Bee.id fields.

    3. Our Hibernate and JPA reverse-engineer tools honor all relationships defined in your DB. So once you have your foreign keys setup correctly as mentioned in #2, when you reverse-engineer the tables together (at the same time), MyEclipse will generate the correct many-to-one and one-to-many relationship for you. If your relationships are not setup in the database OR if you are only reverse-engineering 1 table at a time, MyEclipse won’t be able to generate those relationships for you.

    4. After you have reverse-engineered from your database and gotten your classes, you can create a new UMR file that will contain a class diagram, and Drag and Drop your generated classes directly onto the Class DIagram to have their features reverse-engineered and displayed on the diagram for you.

    I hope that helped explain what is going on. The key issue is that you need to make sure your DB is defined correctly first, then from there MyEclipse will generate all the right code for you.

    As Brian mentioned, if you aren’t sure if the relationships aren’t defined in your DB, you can generate an ER Diagram for your schema and should see lines (relationships) connecting tables. If you don’t, then your relationships are not defined correctly in the DB. Here’s more information on the subject of ER Diagrams:
    http://www.myeclipseide.com/documentation/quickstarts/erdesigner/

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: database fields created missing the asscociated field ?

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