facebook

Bug report ! about hibernate dao

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

    eclipsecnbj
    Member

    Myeclips 5.01
    hibernate 3.1,spring

    Datebase ,mysql,test
    db url is : jdbc:mysql://localhost:3306/test

    table: user

    1. Datebalse Explorer

    I user Datebalse Explorer(Reverse Engineering) to create User.hbm.xml ,User.class,UserDAO.class

    I chose the pakege “com.h819.hibernate”,but the created file always be created in defaut pakege “src”!
    I tried serveral times,it alway do the same thing!
    I have to move them to com.h819.hibernate pakege,and have to change the sources.

    2. the created User.hbm.xml file

    <hibernate-mapping package=”com.h819.hibernate”>
    <class name=”User” table=”user” catalog=”test”>
    <id name=”id” type=”java.lang.Long”>
    <column name=”id” />
    <generator class=”native”></generator>
    </id>
    <property name=”name” type=”java.lang.String”>
    <column name=”name” not-null=”true” />
    </property>
    <property name=”password” type=”java.lang.String”>
    <column name=”password” not-null=”true” />
    </property>
    </class>
    </hibernate-mapping>

    pay attention: catalog=”test”
    If have the string catalog=”test” , I will get the exception
    java.sql.SQLException: Table ‘test.test__user’ doesn’t exist

    I delete the string catalog=”test” as below
    <hibernate-mapping package=”com.h819.hibernate”>
    <class name=”User” table=”user”>
    <id name=”id” type=”java.lang.Long”>
    <column name=”id” />
    <generator class=”native”></generator>
    </id>
    <property name=”name” type=”java.lang.String”>
    <column name=”name” not-null=”true” />
    </property>
    <property name=”password” type=”java.lang.String”>
    <column name=”password” not-null=”true” />
    </property>
    </class>
    </hibernate-mapping>

    I will get the right result!

    So ,hibernate tool of Myeclipse should check the generator templete of hibernate if catalog=”test” should add to the hbm file.

    #257795 Reply

    eclipsecnbj
    Member

    and the third problem

    3. spring DAO

    I use it to create srping DAO

    UserDAO.java has some methods.one is

    public User findById(java.lang.Long id) {
    log.debug(“getting User instance with id: ” + id);
    try {
    User instance = (User) getHibernateTemplate()
    .get(“com.h819.hibernate.User”, id);

    return instance;
    } catch (RuntimeException re) {
    log.error(“get failed”, re);
    throw re;
    }
    }

    “com.h819.hibernate.User” is a string.
    because the first problem,the User.java is created in default pakege “src” ,so the first time is get(“User”, id)! It is wrong,because I move the User.java to com.h819.hibernate pakege myselft,I spend a day to check the reason.

    “com.h819.hibernate.User” is a string,so can not check the wrong, get(User.class,id) do the same thing,and User is a java object,the ide can check it ,so if Myeclipse can change the generator of hibernate templete?
    Use object ,not string.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Bug report ! about hibernate dao

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