facebook

Generate Hibernate mapping and Java classes from database

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #254714 Reply

    eei
    Member

    Hi,
    I am having trouble with hibernate while generating hibernate mappings.
    When I generate the Java class and the xml file using Myeclipse database explorer I get 2 java files.

    I don’t want 2 files, I just need one file with one xml file. I read many hibernate books and they all had one java file. first time I see a file like “Databaseconnection.java” below. I want a file like “DatabaseconnectionId.java”.

    do I have to do any configuration for Myeclipse database explorer to get only one file? thanks.

    ——————– Databaseconnection.java —————–
    package hibernate;

    /**
    * Databaseconnection generated by MyEclipse – Hibernate Tools
    */

    public class Databaseconnection implements java.io.Serializable {

    // Fields

    private DatabaseconnectionId id;
    // Constructors

    /** default constructor */
    public Databaseconnection() {
    }
    // Property accessors

    public DatabaseconnectionId getId() {
    return this.id;
    }

    public void setId(DatabaseconnectionId id) {
    this.id = id;
    }

    ——————– DatabaseconnectionId.java —————–

    package hibernate;

    /**
    * DatabaseconnectionId generated by MyEclipse – Hibernate Tools
    */

    public class DatabaseconnectionId implements java.io.Serializable {

    // Fields

    private long connectionid;
    private String url;
    private String driver;

    // Constructors

    /** default constructor */
    public DatabaseconnectionId() {
    }

    /** minimal constructor */
    public DatabaseconnectionId(long connectionid) {
    this.connectionid = connectionid;
    }

    // Property accessors

    public long getConnectionid() {
    return this.connectionid;
    }

    public void setConnectionid(long connectionid) {
    this.connectionid = connectionid;
    }

    public String getUrl() {
    return this.url;
    }

    public void setUrl(String url) {
    this.url = url;
    }

    public String getDriver() {
    return this.driver;
    }

    public void setDriver(String driver) {
    this.driver = driver;
    }

    public boolean equals(Object other) {
    if ( (this == other ) ) return true;
    if ( (other == null ) ) return false;
    if ( !(other instanceof DatabaseconnectionId) ) return false;
    DatabaseconnectionId castOther = ( EDatabaseconnectionId ) other;

    return (this.getConnectionid()==castOther.getConnectionid())
    && ( (this.getUrl()==castOther.getUrl()) || ( this.getUrl()!=null && castOther.getUrl()!=null && this.getUrl().equals(castOther.getUrl()) ) )
    && ( (this.getDriver()==castOther.getDriver()) || ( this.getDriver()!=null && castOther.getDriver()!=null && this.getDriver().equals(castOther.getDriver()) ) );
    }

    public int hashCode() {
    int result = 17;

    result = 37 * result + (int) this.getConnectionid();
    result = 37 * result + ( getUrl() == null ? 0 : this.getUrl().hashCode() );
    result = 37 * result + ( getDriver() == null ? 0 : this.getDriver().hashCode() );
    return result;
    }

    #254769 Reply

    Riyad Kalla
    Member

    The reason you get two files is because you are using a code-generation tool. If you want to make customizations to the generated files, you need to put those customizations in the concrete subclass. That way if you add a few methods, then regenerate your mappings, only the abstract base classes get overwritten.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Generate Hibernate mapping and Java classes from database

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