facebook

Problems with "references" and Hibernate-Mappings

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

    thurisaz
    Member

    Hi everybody,

    a few months ago I created a lot of SQL-Tables in Postgresql and when I used MyEclipse to create JavaBeans and Mapping files from these tables with “referenced”-table-attributes like

    CREATE TABLE Category
    (
    
    [...]    father REFERENCES Category  ON UPDATE CASCADE ON DELETE CASCADE, [...]

    MyEclipse created JavaBeans with an attribute named “father” which references another Java-Class from type “Category”.

    
    private Category father;
    

    Today, using MyEclipse 4.1 I tried something simmilar using MySQL. When I create a table with

    CREATE TABLE `Repository` 
    (
    [...]
    `owner` INTEGER NOT NULL,
    FOREIGN KEY (owner) REFERENCES user(userid) ON DELETE CASCADE ON UPDATE CASCADE 
    ) TYPE = innodb;

    and then try to create Java-Classes from this Table using the MyEclipse “Create Hibernate Mapping”-functionality, I get the following:

    public class Cssrepository extends User implements java.io.Serializable {
    
    
        // Fields    
    [...]
         private Integer owner;
    [...]
    
    

    Why does this Class extends from User??? And why is my attribute “owner” a normal “Integer” instead of a reference to an Java-Object from type “User”

    Is this a bug? I have this problems since 4.1pre and I hoped that this was solved with the final version – but the problems are still the same. Am I doing something wrong?

    #246142 Reply

    Haris Peco
    Member

    it is bug for any databases (probably).Can you send schema that i check ?

    #246150 Reply

    thurisaz
    Member

    I’m quite sure that the “Create Hibernate Mapping”-Feature is currently totally unusable but I just tried it with MySQL.

    If you take these SQL-Schemas

    CREATE TABLE user
    (
        userid INTEGER PRIMARY KEY,
        username CHAR(30),
        password CHAR(100)
    )
    CREATE TABLE `CssRepository`
    (
    `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `name` VARCHAR( 255 ) NOT NULL ,
    `description` VARCHAR( 255 ) NOT NULL ,
    `dateofcreation` DATETIME NOT NULL ,
    `lastmodified` DATETIME NOT NULL ,
    `owner` INTEGER REFERENCES User ON UPDATE CASCADE ON DELETE CASCADE
    ) TYPE = innodb;

    MySQL successfully creates a reference from Cssrepository to User, but MyEclipse doesn’t care about it

    Also MyEclipse generates senseless “extends xyz”-strings (independent from any “reference”-string, I already had things like “MyClass extends MyClass”)

    public class Cssrepository extends User implements java.io.Serializable {
    
    
        // Fields    
    
         private Integer id;
         private String name;
         private String description;
         private Date dateofcreation;
         private Date lastmodified;
         private Integer owner;
    
    
        // Constructors
    
        /** default constructor */
        public Cssrepository() {
        }
    
        
        /** full constructor */
        public Cssrepository(String name, String description, Date dateofcreation, Date lastmodified, Integer owner) {
            this.name = name;
            this.description = description;
            this.dateofcreation = dateofcreation;
            this.lastmodified = lastmodified;
            this.owner = owner;
        }
        
    
       
        // Property accessors
    
        public Integer getId() {
            return this.id;
        }
        
        public void setId(Integer id) {
            this.id = id;
        }
    
        public String getName() {
            return this.name;
        }
        
        public void setName(String name) {
            this.name = name;
        }
    
        public String getDescription() {
            return this.description;
        }
        
        public void setDescription(String description) {
            this.description = description;
        }
    
        public Date getDateofcreation() {
            return this.dateofcreation;
        }
        
        public void setDateofcreation(Date dateofcreation) {
            this.dateofcreation = dateofcreation;
        }
    
        public Date getLastmodified() {
            return this.lastmodified;
        }
        
        public void setLastmodified(Date lastmodified) {
            this.lastmodified = lastmodified;
        }
    
        public Integer getOwner() {
            return this.owner;
        }
        
        public void setOwner(Integer owner) {
            this.owner = owner;
        }
    
    <hibernate-mapping>
        <class name="xyz.Cssrepository" table="cssrepository" catalog="csseditor">
            <id name="id" type="java.lang.Integer">
                <column name="id" />
                <generator class="increment" />
            </id>
            <property name="name" type="java.lang.String">
                <column name="name" not-null="true" />
            </property>
            <property name="description" type="java.lang.String">
                <column name="description" not-null="true" />
            </property>
            <property name="dateofcreation" type="java.util.Date">
                <column name="dateofcreation" length="19" not-null="true" />
            </property>
            <property name="lastmodified" type="java.util.Date">
                <column name="lastmodified" length="19" not-null="true" />
            </property>
            <property name="owner" type="java.lang.Integer">
                <column name="owner" not-null="true" />
            </property>
        </class>
    </hibernate-mapping>
    

    So I think there are two Bugs: first: senseless extends-expressions and second MyEclipse doesn’t take care about references… but maybe this is just a MyEclipse – MySQL- Bug?

    #246204 Reply

    thurisaz
    Member

    are there any news yet? is it a bug or am I doing something wrong (wrong DB-drivers or anything else)?

    #246205 Reply

    Brian Fernandes
    Moderator

    Thurisaz,

    I apologize for the delayed response. No, you aren’t doing anything wrong, the reference issue a bug and it will be addressed in 4.1.1.

    Having said that, I’m afraid I could not understand what you meant by “senseless extends-expressions”. Are you talking about

    
    public class Cssrepository extends User

    or did you mean something else?

    Sorry for the inconvenience and thank you for reporting the issue.

    Best,
    Brian.

    #246209 Reply

    thurisaz
    Member

    Thank you for your answer Brian! Well, if I create a hibernate mapping from my “User”-Table [CREATE TABLE user ( userid INTEGER PRIMARY KEY, username CHAR(30), password CHAR(100) ) ] the created class ALWAYS extends from the same class:

    public class User extends User implements java.io.Serializable {

    […]
    }

    This is just a simple example – I have this “extends”-problems with a lot of other classes too!

    When will 4.1.1 be released? ‘Cause this bug creates some troubles in our roadmap.

    #246210 Reply

    thurisaz
    Member

    Can you reproduce this bug?

    #246212 Reply

    Brian Fernandes
    Moderator

    Thurisaz,

    About the extends issue, on the first page of the RE wizard, there is a text box for “Base persistence class”. You probably have “User” in there, if you remove it, the generated classes won’t extend anytying (except if you chose to generate abstract classes).
    I hope I’m talking about the same issue you’re facing here, let me know if it isn’t.

    4.1.1 is due late February, it is, for most part a maintanence and bug fix only release; and we’re trying to get it out asap.

    We were able to reproduce the reference issue.

    Best,
    Brian.

    #246213 Reply

    thurisaz
    Member

    @Support-Brian wrote:

    About the extends issue, on the first page of the RE wizard, there is a text box for “Base persistence class”. You probably have “User” in there, if you remove it, the generated classes won’t extend anytying (except if you chose to generate abstract classes).
    I hope I’m talking about the same issue you’re facing here, let me know if it isn’t.

    You’re right I thought that “Base persistent class” belongs to “Create abstract class” and I thought that the entry is ignored if I don’t want abstract classes.

    Thanks this extends-problem is solved – your support in this forum is really excellent!

    #246214 Reply

    Brian Fernandes
    Moderator

    Thurisaz,

    Thank you for the compliment :). We will take another look at the UI of that page as it conveyed the wrong message to you.

    Best regards,
    Brian.

Viewing 10 posts - 1 through 10 (of 10 total)
Reply To: Problems with "references" and Hibernate-Mappings

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