-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: A strange error:net.sf.hibernate.MappingException: invalid m
PostPosted: Sat Apr 24, 2004 12:36 pm 
Newbie

Joined: Sat Apr 24, 2004 12:02 pm
Posts: 2
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

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>



Problems:
(1) the XML parser throws a strange exception, during resolve 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:
Code:
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.


Code:
Caused by: net.sf.hibernate.MappingException: duplicate import: ProjectUserAssoc

Once again, highly appreciated if you could give me some hint.

Dung


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();
    }

}



Top
 Profile  
 
 Post subject: problem with XML parsing and duplicated import
PostPosted: Sat Apr 24, 2004 5:23 pm 
Newbie

Joined: Sat Apr 24, 2004 12:02 pm
Posts: 2
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();
    }

}






--------------------------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 25, 2004 2:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Your class don't have an id, as per the DTD id or composite-id is required.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.