- This topic has 12 replies, 3 voices, and was last updated 18 years, 8 months ago by Ghazalawahid.
-
AuthorPosts
-
GhazalawahidMemberHI,
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” />
Riyad KallaMemberMy 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.
GhazalawahidMemberTable 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?
Riyad KallaMemberCan you paste the hbm.xml file?
GhazalawahidMemberHere 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” ><!– 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>
Riyad KallaMemberOk 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
Riyad KallaMemberWe 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.
GhazalawahidMemberScript 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.
Riyad KallaMemberI 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.
Haris PecoMemberGhazalawahid ,
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
GhazalawahidMemberWould 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>
Haris PecoMemberGhazalawahid ,
<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 versionBest
GhazalawahidMemberI wrote the code for id field as you mentioned,error is gone.Thanks for help.
-
AuthorPosts