Hi,
I encountered a strange error and could not figured out what could have caused the problem. Searching using the abovementioned key words did not return a exact match. I wonder has someone had the similar problem? and how did you solve it? Thanks for any suggestions or hints
Problems:
(1) the XML parser throws a strange exception, during resolving the DTD, the error message indicates that it used the older version of hibernate DTD but I ran a searched and found no local DTD of the older version in my classpath nor the one specified in the XML header.
The actual error message was as follows:
Quote:
Caused by: org.xml.sax.SAXParseException: 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|dynamic-component|any|map|set|list|bag|idbag|
array|primitive-array)*,(subclass*|joined-subclass*))".
I reviewed the DTD of the hibernate and learned that the error message is pointing to the older version of the hibernate DTD.
(2) Now if I turned off the resolving by modifying the source code of hibernate. The program will ignored the DTD problem but now it has another error that is a duplicated error.
Quote:
Caused by: net.sf.hibernate.MappingException: duplicate import: ProjectUserAssoc
Once again, highly appreciated if anyone could give me some hints.
Dung
----------------------------------------------
problem background:
---------------------------------------------
I have three tables
User
Project
ProjectUserAssoc (is an association table with two primary keys are from the based tables - User and Project)
here is the DDL script
Code:
----------------------
CREATE TABLE BUG_USER (
user_id INTEGER NOT NULL,
firstname VARCHAR2(32) NOT NULL,
lastname VARCHAR2(32) NOT NULL,
email VARCHAR2(64) NOT NULL,
workphone VARCHAR2(20) NULL
);
ALTER TABLE BUG_USER
ADD ( PRIMARY KEY (user_id) ) ;
CREATE TABLE PROJECT (
project_name VARCHAR2(256) NOT NULL,
descr VARCHAR2(256) NULL
);
ALTER TABLE PROJECT
ADD ( PRIMARY KEY (project_name) ) ;
CREATE TABLE PROJECT_USER_ASSOC (
project_name VARCHAR2(256) NOT NULL,
user_id INTEGER NOT NULL
);
ALTER TABLE PROJECT_USER_ASSOC
ADD ( PRIMARY KEY (project_name, user_id) ) ;
ALTER TABLE PROJECT_USER_ASSOC
ADD ( FOREIGN KEY (user_id)
REFERENCES BUG_USER ) ;
ALTER TABLE PROJECT_USER_ASSOC
ADD ( FOREIGN KEY (project_name)
REFERENCES PROJECT ) ;
---------------------
I used hibernate middle generator to generate the bhm xml and the source code.
here are the bhm file for project user assoc. The other two were successfully loaded into system.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="cisd870.component.ProjectUserAssoc"
table="PROJECT_USER_ASSOC"
>
<!-- associations -->
<!-- bi-directional many-to-one association to Project -->
<many-to-one
name="project"
class="cisd870.component.Project"
not-null="true"
>
<column name="PROJECT_NAME" />
</many-to-one>
<!-- bi-directional many-to-one association to BugUser -->
<many-to-one
name="bugUser"
class="cisd870.component.BugUser"
not-null="true"
>
<column name="USER_ID" />
</many-to-one>
</class>
</hibernate-mapping>
In case you want to see the generated source code
Code:
package cisd870.component;
import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
public class ProjectUserAssoc implements Serializable {
/** persistent field */
private cisd870.component.Project project;
/** persistent field */
private cisd870.component.BugUser bugUser;
/** full constructor */
public ProjectUserAssoc(cisd870.component.Project project, cisd870.component.BugUser bugUser) {
this.project = project;
this.bugUser = bugUser;
}
/** default constructor */
public ProjectUserAssoc() {
}
public cisd870.component.Project getProject() {
return this.project;
}
public void setProject(cisd870.component.Project project) {
this.project = project;
}
public cisd870.component.BugUser getBugUser() {
return this.bugUser;
}
public void setBugUser(cisd870.component.BugUser bugUser) {
this.bugUser = bugUser;
}
public String toString() {
return new ToStringBuilder(this)
.toString();
}
}
--------------------------------------------------------------------------------