facebook

one-to-one HBM generation problem with MyEclipse

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #237827 Reply

    govindsri
    Member

    This message has not been recovered.

    #237850

    rmerc
    Member

    This message has not been recovered.

    #237851

    Brian Fernandes
    Moderator

    This message has not been recovered.

    #237855

    govindsri
    Member

    This message has not been recovered.

    #237856

    govindsri
    Member

    This message has not been recovered.

    #237858

    govindsri
    Member

    This message has not been recovered.

    #237860

    govindsri
    Member

    This message has not been recovered.

    #237863

    Brian Fernandes
    Moderator

    This message has not been recovered.

    #238523

    tarantula
    Participant

    @Support-Brian wrote:

    Govindsri,

    Thank you for sending us all the details requested. We are investigating the matter internally and will keep you posted on this thread.

    Best,
    Brian.

    Any news on this? I am also interested in support for one-to-one Hibernate relationship mapping with MyEclipse.

    #238525

    Brian Fernandes
    Moderator

    tarantula,

    Could you please try it out yourself and see if you have issues with the generated code as well?

    In general, these are more like short comings of our mapping generator than a bug. Our generated does not know what kind of relationship you want to set up (bi-directional or uni-directional – from which end) and hence it might create a relationship different from what you’re expecting.

    There is no workaround for this behaviour at this time, but we will be concentrating on Hibernate support for the 4.1 release and the 5.0 release. There will ultimately be a Visual mapper which will allow very fine grained control over the process.

    Best,
    Brian.

    #239540

    sashalin
    Member

    I met the same problem with myeclipse 4.0. And I found that not only the generated hbm file but also the pojo have problems. In the following example, I have two tables: person and author, the primary key of author is also a foreign key referring to the primary key of person, namely, there is a one-to-one mapping between author and person.

    The following is my generated pojo and hbm file:
    1. AbstractPerson.java
    /*
    * WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized
    * by MyEclipse Hibernate tool integration.
    *
    * Created Mon Oct 17 17:05:21 CST 2005 by MyEclipse Hibernate Tool.
    */
    package model;

    import java.io.Serializable;

    /**
    * A class that represents a row in the person table.
    * You can customize the behavior of this class by editing the class, {@link Person()}.
    * WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized
    * by MyEclipse Hibernate tool integration.
    */
    public abstract class AbstractPerson
    implements Serializable
    {
    /** The cached hash code value for this instance. Settting to 0 triggers re-calculation. */
    private int hashValue = 0;

    /** The composite primary key value. */
    private java.lang.Integer id;

    /** The value of the authorSet one-to-many association. */
    private java.util.Set authorSet;

    /** The value of the simple name property. */
    private java.lang.String name;

    /** The value of the simple email property. */
    private java.lang.String email;

    /**
    * Simple constructor of AbstractPerson instances.
    */
    public AbstractPerson()
    {
    }

    /**
    * Constructor of AbstractPerson instances given a simple primary key.
    * @param id
    */
    public AbstractPerson(java.lang.Integer id)
    {
    this.setId(id);
    }

    /**
    * Return the simple primary key value that identifies this object.
    * @return java.lang.Integer
    */
    public java.lang.Integer getId()
    {
    return id;
    }

    /**
    * Set the simple primary key value that identifies this object.
    * @param id
    */
    public void setId(java.lang.Integer id)
    {
    this.hashValue = 0;
    this.id = id;
    }

    /**
    * Return the value of the name column.
    * @return java.lang.String
    */
    public java.lang.String getName()
    {
    return this.name;
    }

    /**
    * Set the value of the name column.
    * @param name
    */
    public void setName(java.lang.String name)
    {
    this.name = name;
    }

    /**
    * Return the value of the email column.
    * @return java.lang.String
    */
    public java.lang.String getEmail()
    {
    return this.email;
    }

    /**
    * Set the value of the email column.
    * @param email
    */
    public void setEmail(java.lang.String email)
    {
    this.email = email;
    }

    /**
    * Return the value of the Id collection.
    * @return Author
    */
    public java.util.Set getAuthorSet()
    {
    return this.authorSet;
    }

    /**
    * Set the value of the Id collection.
    * @param authorSet
    */
    public void setAuthorSet(java.util.Set authorSet)
    {
    this.authorSet = authorSet;
    }

    /**
    * Implementation of the equals comparison on the basis of equality of the primary key values.
    * @param rhs
    * @return boolean
    */
    public boolean equals(Object rhs)
    {
    if (rhs == null)
    return false;
    if (! (rhs instanceof Person))
    return false;
    Person that = (Person) rhs;
    if (this.getId() == null || that.getId() == null)
    return false;
    return (this.getId().equals(that.getId()));
    }

    /**
    * Implementation of the hashCode method conforming to the Bloch pattern with
    * the exception of array properties (these are very unlikely primary key types).
    * @return int
    */
    public int hashCode()
    {
    if (this.hashValue == 0)
    {
    int result = 17;
    int idValue = this.getId() == null ? 0 : this.getId().hashCode();
    result = result * 37 + idValue;
    this.hashValue = result;
    }
    return this.hashValue;
    }
    }

    2.AbstractAuthor.java
    /*
    * WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized
    * by MyEclipse Hibernate tool integration.
    *
    * Created Mon Oct 17 17:06:14 CST 2005 by MyEclipse Hibernate Tool.
    */
    package model;

    import java.io.Serializable;

    /**
    * A class that represents a row in the author table.
    * You can customize the behavior of this class by editing the class, {@link Author()}.
    * WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized
    * by MyEclipse Hibernate tool integration.
    */
    public abstract class AbstractAuthor
    implements Serializable
    {
    /** The cached hash code value for this instance. Settting to 0 triggers re-calculation. */
    private int hashValue = 0;

    /** The composite primary key value. */
    private Person person;

    /** The value of the simple alias property. */
    private java.lang.String alias;

    /**
    * Simple constructor of AbstractAuthor instances.
    */
    public AbstractAuthor()
    {
    }

    /**
    * Constructor of AbstractAuthor instances given a simple primary key.
    * @param person
    */
    public AbstractAuthor(Person person)
    {
    this.setPerson(person);
    }

    /**
    * Return the simple primary key value that identifies this object.
    * @return Person
    */
    public Person getPerson()
    {
    return person;
    }

    /**
    * Set the simple primary key value that identifies this object.
    * @param person
    */
    public void setPerson(Person person)
    {
    this.hashValue = 0;
    this.person = person;
    }

    /**
    * Return the value of the alias column.
    * @return java.lang.String
    */
    public java.lang.String getAlias()
    {
    return this.alias;
    }

    /**
    * Set the value of the alias column.
    * @param alias
    */
    public void setAlias(java.lang.String alias)
    {
    this.alias = alias;
    }

    /**
    * Implementation of the equals comparison on the basis of equality of the primary key values.
    * @param rhs
    * @return boolean
    */
    public boolean equals(Object rhs)
    {
    if (rhs == null)
    return false;
    if (! (rhs instanceof Author))
    return false;
    Author that = (Author) rhs;
    if (this.getPerson() == null || that.getPerson() == null)
    return false;
    return (this.getPerson().equals(that.getPerson()));
    }

    /**
    * Implementation of the hashCode method conforming to the Bloch pattern with
    * the exception of array properties (these are very unlikely primary key types).
    * @return int
    */
    public int hashCode()
    {
    if (this.hashValue == 0)
    {
    int result = 17;
    int personValue = this.getPerson() == null ? 0 : this.getPerson().hashCode();
    result = result * 37 + personValue;
    this.hashValue = result;
    }
    return this.hashValue;
    }
    }

    3. Author.hbm.xml
    <?xml version=”1.0″ encoding=’UTF-8′?>
    <!DOCTYPE hibernate-mapping PUBLIC
    “-//Hibernate/Hibernate Mapping DTD 3.0//EN”
    http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&#8221; >

    <!– DO NOT EDIT: This is a generated file that is synchronized –>
    <!– by MyEclipse Hibernate tool integration. –>
    <!– Created Mon Oct 17 17:06:14 CST 2005 –>
    <hibernate-mapping package=”model”>

    <class name=”Author” table=”author”>
    <id name=”person” column=”Id” type=”java.lang.Integer”>
    <generator class=”foreign”/>
    </id>

    <property name=”alias” column=”alias” type=”java.lang.String” />
    </class>

    </hibernate-mapping>

    4.Person.hbm.xml
    <?xml version=”1.0″ encoding=’UTF-8′?>
    <!DOCTYPE hibernate-mapping PUBLIC
    “-//Hibernate/Hibernate Mapping DTD 3.0//EN”
    http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&#8221; >

    <!– DO NOT EDIT: This is a generated file that is synchronized –>
    <!– by MyEclipse Hibernate tool integration. –>
    <!– Created Mon Oct 17 17:05:21 CST 2005 –>
    <hibernate-mapping package=”model”>

    <class name=”Person” table=”person”>
    <id name=”id” column=”Id” type=”java.lang.Integer”>
    <generator class=”native”/>
    </id>

    <property name=”name” column=”name” type=”java.lang.String” />
    <property name=”email” column=”email” type=”java.lang.String” />

    <set name=”authorSet” inverse=”true”>
    <key column=”Id”/>
    <one-to-many class=”Author”/>
    </set>
    </class>

    </hibernate-mapping>

    Person.java and Author.java omitted.

    there is 4 problems in the above code:
    1. there is no field “id” in AbstractAuthor.java, which is needed
    2. there is a field “authorSet” in AbstractPerson.java, which is not needed
    3. in author.hbm.xml, there are 2 problems:
    a.
    <generator class=”foreign”/>
    should be
    <generator class=”foreign”>
    <param name=”property”>person</param>
    </generator>
    b.
    there is no one to one declaration in author.hbm.xml, which should be :
    <one-to-one name=”person” class=”Person” cascade=”all” constrained=”true” />
    4. there is a <set> </set> declaration in person.hbm.xml, which is not needed.

    Considering the above problems, it seems that myeclipse mapping generator has taken the relationship between author and person
    to be a many-to-one relationship, and not a one-to-one one as we expected. But apparently since the only primary key id of table
    author refers to the primary key id of person, there can only be one possibility of the relationship: one-to-one. I think it is a bug more than a shortcoming. I do hope you can fix it soon.

    #240042

    tarantula
    Participant

    Good post sashalin. This highlights the difficulty of using inheritance in a MyEclipse-Hibernate object model. I also hope they find a solution soon.

    #240047

    Riyad Kalla
    Member

    Guys we are looking into working with the HibernatePlugin over at hibernate.org for future releases to help consolidate the work in the Hibernate mapping arena, hopefully that will get rid of these hickups along the way. IIRC the beginning of this work is starting in the 4.1 release and continuing on through 5.0.

    #240465

    sashalin
    Member

    It’s good news to hear. I’m looking forward to the new release to solve this problem. Thanks for your effort

    #242670

    sashalin
    Member

    I tried the new release 4.1M1, but things don’t change a little

Viewing 15 posts - 1 through 15 (of 16 total)
Reply To: one-to-one HBM generation problem with MyEclipse

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