-->
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.  [ 9 posts ] 
Author Message
 Post subject: Beginner Middlegen question - created xml doesn't match dtd
PostPosted: Fri Jul 23, 2004 7:41 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 6:50 pm
Posts: 27
Hi,

I'm using Middlegen with SAPDB to create xml files, which I then convert to Java using hbm2java tool.

However, when I run hbm2java, I get the following error:

[hbm2java] (hbm2java.CodeGenerator 48 ) Error parsing XML: file:/
C:/Middlegen-Hibernate-r5/Middlegen-Hibernate-r5/build/gen-src/com/lexmark/kiosk
/hibernate/Categorykiosk.hbm.xml(28)
[hbm2java] org.xml.sax.SAXParseException: The content of element type "composit
e-id" is incomplete, it must match "(meta*,(key-property|key-many-to-one)+)".
[hbm2java] at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseExce
ption(Unknown Source)
...

The file created by Middlegen looks like this:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.lexmark.kiosk.hibernate.Categorykiosk"
table="CATEGORYKIOSK"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="CATEGORYKIOSK"
</meta>


<composite-id>
<meta attribute="field-description" inherit="false">
@hibernate.id
generator-class="assigned"
</meta>
</composite-id>


<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->

<!-- bi-directional many-to-one association to Kiosk -->
<many-to-one
name="kiosk"
class="com.lexmark.kiosk.hibernate.Kiosk"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="KIOSK_ID"
</meta>
<column name="KIOSK_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to Category -->
<many-to-one
name="category"
class="com.lexmark.kiosk.hibernate.Category"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="CATEGORY_ID"
</meta>
<column name="CATEGORY_ID" />
</many-to-one>

</class>
</hibernate-mapping>

I'm a beginner at all this - can anyone point me in the right direction, please?

Cheers,

David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 9:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
It has generated a composite key without any fields - very odd.
I dont have enough information - so;
What is your DDL for that table?
What is shown in the GUI?
What settings or anything else have you used?

I assume you have not post edited the hbm file.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 26, 2004 12:22 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 6:50 pm
Posts: 27
Hi,

Thanks for the reply...

No, I haven't post edited the hbm file at all.

GUI just shows Many-One relation between CategoryKiosk.Kiosk_ID and Kiosks.ID and another Many-One between CategorKiosk.Category_ID and Categories.ID.

DDL for this table is:

CREATE TABLE "KIOSK"."CATEGORYKIOSK"
(
"CATEGORY_ID" Integer,
"KIOSK_ID" Integer,
FOREIGN KEY "CATEGORIES_CATEGORYKIOSK" ("CATEGORY_ID") REFERENCES "KIOSK"."CATEGORIES" ("ID") ON DELETE RESTRICT,
FOREIGN KEY "KIOSKS_CATEGORYKIOSK" ("KIOSK_ID") REFERENCES "KIOSK"."KIOSKS" ("ID") ON DELETE RESTRICT
)

and for Kiosks and Categories:

CREATE TABLE "KIOSK"."KIOSKS"
(
"ID" Integer NOT NULL,
"NAME" Varchar (83) ASCII,
"ADDRESS" Varchar (80) ASCII,
"PRIMARY_PRINTER" Varchar (80) ASCII,
"BACKUP_PRINTER" Varchar (80) ASCII,
"PRINTER" Varchar (50) ASCII,
"KIOSK_TYPE" Varchar (50) ASCII,
"MACON_TITLE" Varchar (15) ASCII,
"AVAILABLE" Boolean,
"UPPERNAME" Varchar (83) ASCII,
PRIMARY KEY ("ID")
)

CREATE TABLE "KIOSK"."CATEGORIES"
(
"ID" Integer NOT NULL,
"NAME" Varchar (80) ASCII,
"UPPERNAME" Varchar (80) ASCII,
PRIMARY KEY ("ID")
)

Don't think I've changed many of the default settings...

I couldn't figure out how to post a jpg of the gui - can do if you tell me how, or I can email it to you.

Appreciate your help!

Cheers,

David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 26, 2004 2:10 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 6:50 pm
Posts: 27
Sorry - beginners mistake!!

The CategoryKiosk table didn't have a primary key defined (even though we maintained it in our code previously). Created that, and it works fine!

I do have a settings table which doesn't have a primary key, as it will always be just a single row. Will this be a problem for Hibernate?

cheers!!

David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 26, 2004 6:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Glad your found the problem.

Hibernate requires a primary key of some form - I suggest in this case you create a domain object that has only a composite key which includes all fields.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 26, 2004 6:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
BTW: My first suggestion is the safest approach but if you are never ever going to have more than one row then it does not matter which field is used as the primary key.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 3:25 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 6:50 pm
Posts: 27
Hi David,

Tried your second suggestion, and puzzled by the results!!

I have an INFO table, which just stores version number and serial number. It will only ever have 1 row.

So I simply made the version number the primary key, and regenerated everything. The problem is I get a strange error:

net.sf.hibernate.MappingException: composite-id class must override equals(): com.lexmark.kiosk.hibernate.Info

There isn't a composite-id anywhere in sight though!! (as far as I can tell). The table sits by itself, with no relationships, and just the primary key.

All the info's below.

cheers,

David


DDL:

CREATE TABLE "KIOSK"."INFO"
(
"VERSION" Varchar (10) ASCII NOT NULL,
"SERIAL_NUMBER" Varchar (7) ASCII NOT NULL,
PRIMARY KEY ("VERSION")
)


HBM:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.lexmark.kiosk.hibernate.Info"
table="INFO"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="INFO"
</meta>

<id
name="version"
type="java.lang.String"
column="VERSION"
>
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
type="java.lang.String"
column="VERSION"


</meta>
<generator class="assigned" />
</id>

<property
name="serialNumber"
type="java.lang.String"
column="SERIAL_NUMBER"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="SERIAL_NUMBER"
length="7"
not-null="true"
</meta>
</property>

<!-- Associations -->


</class>
</hibernate-mapping>


JAVA:


package com.lexmark.kiosk.hibernate;

import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;


/**
* @hibernate.class
* table="INFO"
*
*/
public class Info implements Serializable {

/** identifier field */
private String version;

/** persistent field */
private String serialNumber;

/** full constructor */
public Info(String version, String serialNumber) {
this.version = version;
this.serialNumber = serialNumber;
}

/** default constructor */
public Info() {
}

/**
* @hibernate.id
* generator-class="assigned"
* type="java.lang.String"
* column="VERSION"
*
*/
public String getVersion() {
return this.version;
}

public void setVersion(String version) {
this.version = version;
}

/**
* @hibernate.property
* column="SERIAL_NUMBER"
* length="7"
* not-null="true"
*
*/
public String getSerialNumber() {
return this.serialNumber;
}

public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}

public String toString() {
return new ToStringBuilder(this)
.append("version", getVersion())
.toString();
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 6:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
It looks fine by me. You sure you don't have an old mapping in the classpath that predates adding the primary key. I ask since Middlegen will create the composite key for all columns if there is no primary key. It might be hiding from you :-)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 4:33 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 6:50 pm
Posts: 27
Doh!!

I recreated everything, but didn't copy the new hbm.xml files into my webserver!!

Sorry for the trouble!

David


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.