-->
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.  [ 14 posts ] 
Author Message
 Post subject: Middlegen -> hbm2java problem
PostPosted: Wed Oct 29, 2003 7:34 am 
Newbie

Joined: Wed Oct 29, 2003 7:16 am
Posts: 6
Hello,

I'm new to Hibernate. I'm using Middlegen to create my .hbm.xml files from an existing database but when I feed these files into hbm2java it does generate the .java files but complains about the XML when doing so;

[hbm2java] (hbm2java.CodeGenerator 48 ) Error parsing XML: file:/C:/eclipse/workspace/Stakez-Hibernate/build/gen-src/stakez/hibernate/Stakezuser.hbm.xml(19)
[hbm2java] org.xml.sax.SAXParseException: Element "class" does not allow "property" here.
[hbm2java] at org.apache.crimson.parser.Parser2.error(Parser2.java:3210)
.........
.........

Where am I going wrong? Is the xml generated by Middlegen correct? am I missing somthing when I call hbm2java?


many thanks

James




The hbm.xml files generated from Middlegen are;

Xchangelog.hbm.xml & Stakezuser.hbm.xml

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

<?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="stakez.hibernate.Xchangelog"
table="xchangelog"
>
<property
name="username"
type="java.lang.String"
column="username"
length="20"
/>
<property
name="ipaddress"
type="java.lang.String"
column="ipaddress"
length="15"
/>
<property
name="sentdate"
type="java.sql.Date"
column="sentdate"
length="4"
/>

<!-- associations -->

</class>
</hibernate-mapping>



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


<?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="stakez.hibernate.Stakezuser"
table="stakezuser"
>
<property
name="username"
type="java.lang.String"
column="username"
not-null="true"
length="20"
/>
<property
name="password"
type="java.lang.String"
column="password"
not-null="true"
length="20"
/>
<property
name="email"
type="java.lang.String"
column="email"
not-null="true"
length="60"
/>
<property
name="level"
type="java.lang.String"
column="level"
length="10"
/>
<property
name="url"
type="java.lang.String"
column="url"
length="80"
/>
<property
name="sent"
type="int"
column="sent"
length="4"
/>
<property
name="recieved"
type="int"
column="recieved"
length="4"
/>
<property
name="status"
type="java.lang.String"
column="status"
length="10"
/>
<property
name="owed"
type="int"
column="owed"
length="4"
/>

<!-- associations -->

</class>
</hibernate-mapping>



I call hbm2java from ant;

<target name="hbm2java"
description="Generate .java from .hbm files.">

<taskdef
name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="lib.class.path"
/>

<hbm2java output="${build.java.dir}" classpathref="lib.class.path">
<fileset dir="${build.gen-src.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 10:19 am 
Beginner
Beginner

Joined: Thu Sep 25, 2003 5:22 pm
Posts: 29
Location: NC
It looks as though your id field is not being generated correctly.bbAre your tables using composite primary ids that are made up of two or more foreign keys? If so, this is a bug in middlegen.

-Kat


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 11:05 am 
Newbie

Joined: Wed Oct 29, 2003 7:16 am
Posts: 6
Ah well that would explain why the first db I tried didn't work.

Thanks for pointing me in the right direction.

James


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 7:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have finished adding support in the middlgen for this. I will release it after testing and finishing further enhancement I have been working on.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 7:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Actually - How about sending me the database schema for this just to make sure it is coverred. david@hibernate.org


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 8:43 pm 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
have the same problem David.

See topic "Middlegen generates hbm xml without ids?" for example DDL.

-Joe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 2:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Already fixed it and it is getting closer to a release. The weekend I expect.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 10:50 am 
Beginner
Beginner

Joined: Thu Sep 25, 2003 5:22 pm
Posts: 29
Location: NC
Cool! My boss will be pleased.. he has been breathing down my neck on this.

-K


Top
 Profile  
 
 Post subject: hbm2java problem / are composite primary id's bad?
PostPosted: Fri Oct 31, 2003 9:33 am 
Newbie

Joined: Wed Oct 29, 2003 7:16 am
Posts: 6
Are composite primary ids made up of foreign keys considered bad form for Hibernate? I've heard Surrogate keys are prefered. Why ?

I'm using Middlegen to generate stuff from an existing DB, but I can redesign things if need be.

What's people opinion on this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 5:11 pm 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
I've wondered the exact same thing.

Part of me worries that my object model is suffering from tunnel-vision because of my database schema.

_________________
"A statistician is a mathmetician, broken down by age and sex".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 6:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I don't have links to pass on but compound keys are not the best database design. Just use synthetic keys and keep away from business knowledge based keys. It will bite you otherwise. The other side is that its so much nicer dealing with the objects, database and mappings with synthetic keys as compound keys just add complexity for no (or negative) benefit.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 01, 2003 12:31 am 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
david wrote:
I don't have links to pass on but compound keys are not the best database design. Just use synthetic keys and keep away from business knowledge based keys. It will bite you otherwise. The other side is that its so much nicer dealing with the objects, database and mappings with synthetic keys as compound keys just add complexity for no (or negative) benefit.


We shouldnt use composite keys even in the *database*??

I figured that was always right on the DB level, and Hibernate abstracted that for us into the object model.

While we're on the subject, what's wrong with this? I keep getting told key-property tags have to have class defined, and mine do.

Code:

      <composite-id name="compId" class="bb.hibernate.UserLanguageKey">
        <key-property class="bb.hibernate.User" name="userId"  column="UserId"/>
        <key-property class="bb.hibernate.Language" name="languageCode" column="LanguageCode"/>
      </composite-id>

[/code]

_________________
"A statistician is a mathmetician, broken down by age and sex".


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2003 3:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If you are designing a new database or new tables. You should use synthetic keys if at all possible. You will avoid many issues as the schema (and data requirements) change.

The compound key - key-property does not have class on it. Name yes but not class. Maybe you were thinking of key-many-to-one. Anyway, here is an example:


Code:
<composite-id
        name="propertyName"
        class="ClassName"
        unsaved-value="any|none">

        <key-property name="propertyName" type="typename" column="column_name"/>
        <key-many-to-one name="propertyName class="ClassName" column="column_name"/>
        ......
</composite-id>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2003 3:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
BTW: Middlegen r3 has been released.


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