facebook

rev engeneering for hibernate

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #311494 Reply

    shaykr
    Member

    Hi,

    I have the following 2 tables:
    CREATE TABLE `listings` (
    `LISTING_SEQ_NO` int(11) NOT NULL,
    `LBLCODE` char(6) NOT NULL,
    `PRODCODE` char(4) NOT NULL,
    `STRENGTH` char(10) DEFAULT NULL,
    `UNIT` char(10) DEFAULT NULL,
    `RX_OTC` char(1) DEFAULT NULL,
    `TRADENAME` char(100) DEFAULT NULL,
    PRIMARY KEY (`LISTING_SEQ_NO`)
    )

    CREATE TABLE `medlist` (
    `LISTING_SEQ_NO` int(11) NOT NULL,
    `DOSAGE` varchar(45) DEFAULT NULL,
    `SCHEDULE_CODE` varchar(45) DEFAULT NULL,
    `SCHEDULE_INSTRUCTIONS` varchar(45) DEFAULT NULL,
    `ROUTE_CODE` varchar(45) DEFAULT NULL,
    `REF_NO` varchar(45) NOT NULL,
    PRIMARY KEY (`LISTING_SEQ_NO`,`REF_NO`),
    CONSTRAINT `fk_medlistLISTING_SEQ_NO_listingsLISTING_SEQ_NO` FOREIGN KEY (`LISTING_SEQ_NO`) REFERENCES `listings` (`LISTING_SEQ_NO`) ON DELETE NO ACTION ON UPDATE NO ACTION
    )

    Once rev eng, I see the following snippet in the medlist.hbm.xml:

    <many-to-one name=”listings” class=”com.myeclipse.hibernatespring.Listings” update=”false” insert=”false” fetch=”select”>
    <column name=”LISTING_SEQ_NO” not-null=”true” />
    </many-to-one>

    but for some reason the generated pojo for AbstractMedList looks like:

    private MedlistId id;
    private Listings listings;
    private String dosage;
    private String scheduleCode;
    private String scheduleInstructions;
    private String routeCode;

    Instead of having a set of Listings.

    Please advice…

    #311497 Reply

    davemeurer
    Member

    Hello,

    It sounds like you are using the JPA Reverse Engineering feature. Is that correct? If so, that’s a feature found in the base MyEclipse product, so your question is better served in the Database Tools forum. I’d be happy to move this thread if you like.

    On the other hand, another way to reverse engineer those tables is use the MyEclipse for Spring Scaffolding – using the Database option. Once scaffolded, you should see a Set of Listings in the Medlist domain object.

    -Dave

    #311498 Reply

    shaykr
    Member

    ok, so I did what you suggested and used scaffolding. Tables are the same. What I get now is the following:

    In the listings class:
    @OneToMany(mappedBy = “listings”, cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
    @XmlElement(name = “”, namespace = “”)
    java.util.Set<com.testCRUDagain.domain.Medlist> medlists;

    In the Medlist class:

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns( { @JoinColumn(name = “LISTING_SEQ_NO”, referencedColumnName = “LISTING_SEQ_NO”, nullable = false, insertable = false, updatable = false) })
    @XmlTransient
    Listings listings;

    I need it the other way round…i.e, i want to be able to associate one medlist to a many listings.
    Any idea?

    #311520 Reply

    davemeurer
    Member

    Hello,

    If I’m not mistaken your table structure contains a foreign key on the medlist table to the listings table, which would make this relationship a One Listings to Many Medlist. This is why you are seeing the reverse engineering functions behave this way.

    If you want one medlist to have many listings, I would recommend placing the foreign key on the listings table.

    — Or — you can start from a java bean or JPA entity, and use the scaffolding (which uses hibernate) to create the tables the way you want it. For example, In the Medlist class, add a collection of listings:
    Set <Listings> listings;
    and if you want a bi-directional relationship, add a Medlist attribute in the listings class.

    Then scaffold from those two Java Beans.

    HTH,
    Dave

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: rev engeneering for hibernate

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