facebook

[Closed] Error in table.hbm.xml file

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

    Ghazalawahid
    Member

    HI,

    As soon as i create a hibernate mapping o a table,it generates table.hbm.xml file but give error on line where class tag close e.g </class> ,when i move the mouse over error it says:

    “The content of element type “class” must match “(meta*,cache|jcs-cache)?,(id|composite-id),discriminator?,(version|timestamp),(property|many-to-one|one-to-one|component………..”

    Its showing the mapping entry in hibernate.cfg.xml as

    <mapping resource=”com/genuitec/hibernate/Doctordetail.hbm.xml” />

    #247582 Reply

    Riyad Kalla
    Member

    My guess, since you didn’t post the file, is that the table you mapped does not have a primary key set, and it must, in order for Hibernate to map the table. If you are missing a PK for that table, then your <class> entry gets mapped with an ID field, which IS invalid.

    Correction: Set a PK in that table and re-reverse-engineer it.

    #247594 Reply

    Ghazalawahid
    Member

    Table has primary key,and i am not selecting increment field as ID Generator,even then its giving same error.I have two doubts:

    1) Primary key is of type number in MSAccess Database,there could be data compatibility problem?

    2) In hibernate configuration xml file , its not displaying any dialect value for JDBC ODBC Datasource , so i am selecting Generic,could it be the reason?

    #247595 Reply

    Riyad Kalla
    Member

    Can you paste the hbm.xml file?

    #247626 Reply

    Ghazalawahid
    Member

    Here is code for 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 Wed Mar 01 23:27:27 EST 2006 –>
    <hibernate-mapping package=”com.genuitec.hiberanate”>

    <class name=”Doctordetail” table=”Doctordetail”>

    <property name=”doctorName” column=”Doctor_Name” type=”string” />
    <property name=”category” column=”Category” type=”string” />
    <property name=”doctorId” column=”Doctor_id” type=”integer” />
    </class>

    </hibernate-mapping>

    #247628 Reply

    Riyad Kalla
    Member

    Ok so it does look like the class is getting generated without an ID. Can you post the create table script for your table?

    Also there is no dialect for ODBC/JDBC: http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#configuration-optional-dialects

    #247631 Reply

    Riyad Kalla
    Member

    We are discussing the possiblity of having MyEclipse auto-generate a PK for you on a table that doesn’t have one defined. In the mean time this is the problem. If you do have a PK defined and MyEclipse still cannot identify it, this may be a problem with the JDBC-ODBC driver in the JDK.

    #247649 Reply

    Ghazalawahid
    Member

    Script for table generation :

    create table `C:\Ghazala\HospitalMangmnt\Hospitaldb`.`Doctordetail`(
    `Doctor_Name` VARCHAR(50),
    `Category` VARCHAR(50),
    `Doctor_id` INTEGER(10))

    I have defined the Doctor_id as Primary key but its not displaying in script.Note: I created the table directly in MSAccess not by script.The above script i have generated in MyEclipse by right clicking table and selecting Generate Table script and it looks like it is ignoring the primary key.

    #247650 Reply

    Riyad Kalla
    Member

    I think the problem is and will be that MyEclipse is not able to get the PK information from the ODBC/JDBC driver, so it doesn’t know what to do. You can enter in the id field manually into the hbm.xml file as a workaround or switch to using another DB like MySQL or PostgreSQL.

    We have filed this issue as a bug in our tracking system that MyEclipse should handle this situation better and just use every field as a composite ID when it can’t tell which field is the PK. Sorry for the inconvenience.

    #247666 Reply

    Haris Peco
    Member

    Ghazalawahid ,

    There isn’t MS Access dialect for hibernate.It is better that you pick other databases (as rkalla says) or you have to make own Dialect for MS Access, but it’s unsupported with hibernate (search supported databases on hibernate site http://www.hibernate.org)

    Best

    #247805 Reply

    Ghazalawahid
    Member

    Would you please write the syntax for specifying id field in hbm.xml file as i could not find any id field in my hbm.xml file.Where does id field fits in file below?(Doctor_id is primary key).

    <class name=”Doctordetail” table=”Doctordetail”>

    <property name=”doctorName” column=”Doctor_Name” type=”string” />
    <property name=”category” column=”Category” type=”string” />
    <property name=”doctorId” column=”Doctor_id” type=”integer” />

    </class>

    #247811 Reply

    Haris Peco
    Member

    Ghazalawahid ,

    <class name=”Doctordetail” table=”Doctordetail”>

    <id name=”doctorId” type=”string”>
    <column name”Doctor_id” />
    <generator class=”assigned” />
    </id>

    <property name=”doctorName” column=”Doctor_Name” type=”string” />
    <property name=”category” column=”Category” type=”string” />
    <property name=”doctorId” column=”Doctor_id” type=”integer” />

    </class>

    name, type and generator can be different, but this is example.However , you can’t work with MSAccess and hibernate except you make your own dialect for MSAccess
    If you have PK doctor_detail then you have worng jdbc driver (jdbc-odbc) and it don’t return correct primary key
    MyEclipse RE eng. find PK correct for moslty databases
    Do you try version 4.1.1 ? – we fixed a lot bugs in this version

    Best

    #247905 Reply

    Ghazalawahid
    Member

    I wrote the code for id field as you mentioned,error is gone.Thanks for help.

Viewing 13 posts - 1 through 13 (of 13 total)
Reply To: [Closed] Error in table.hbm.xml file

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