-->
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.  [ 7 posts ] 
Author Message
 Post subject: hbm2dll error: composite-id
PostPosted: Wed Jan 19, 2005 1:23 am 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
middlegen r5

hbm2dll error: table without primary key

i like to mapping composite-id without other class.........

the table has no primary key , so it mapping as

<?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="org.ctais.hibernate.DmZsxm"
table="DM_ZSXM"
>

<composite-id>
<key-property
name="zsxmDm"
column="ZSXM_DM"
type="java.lang.String"
length="2"
/>
<key-property
name="zsxmMc"
column="ZSXM_MC"
type="java.lang.String"
length="30"
/>
<key-property
name="zsxmJc"
column="ZSXM_JC"
type="java.lang.String"
length="10"
/>
<key-property
name="xybz"
column="XYBZ"
type="java.lang.String"
length="1"
/>
</composite-id>


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


</class>
</hibernate-mapping>


[schemaexport] (cfg.Binder 230 ) Mapping class: org.cta
is.hibernate.DjNsrxxKz -> DJ_NSRXX_KZ
[schemaexport] (cfg.Configuration 169 ) Mapping file: D:\Progr
am Files\Middlegen-Hibernate-r5\build\gen-src\org\test\hibernate\DmZspm.hbm.xml

[schemaexport] (cfg.Binder 230 ) Mapping class: org.cta
is.hibernate.DmZspm -> DM_ZSPM
[schemaexport] (cfg.Configuration 255 ) Could not compile the
mapping document
[schemaexport] net.sf.hibernate.MappingException: composite-id class must overri
de equals(): org.ctais.hibernate.DmZspm
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:306)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
[schemaexport] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252
)
[schemaexport] at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java
:174)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.getConfigurati
on(SchemaExportTask.java:195)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.execute(Schema
ExportTask.java:135)
[schemaexport] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.ja
va:275)
[schemaexport] at org.apache.tools.ant.Task.perform(Task.java:364)
[schemaexport] at org.apache.tools.ant.Target.execute(Target.java:341)
[schemaexport] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[schemaexport] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)

[schemaexport] at org.apache.tools.ant.Project.executeTargets(Project.java:1062
)
[schemaexport] at org.apache.tools.ant.Main.runBuild(Main.java:673)
[schemaexport] at org.apache.tools.ant.Main.startAnt(Main.java:188)
[schemaexport] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
[schemaexport] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
[schemaexport] (cfg.Configuration 178 ) Could not configure da
tastore from file: D:\Program Files\Middlegen-Hibernate-r5\build\gen-src\org\cta
is\hibernate\DmZspm.hbm.xml
[schemaexport] net.sf.hibernate.MappingException: composite-id class must overri
de equals(): org.test.hibernate.DmZspm
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:306)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
[schemaexport] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252
)
[schemaexport] at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java
:174)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.getConfigurati
on(SchemaExportTask.java:195)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.execute(Schema
ExportTask.java:135)
[schemaexport] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.ja
va:275)
[schemaexport] at org.apache.tools.ant.Task.perform(Task.java:364)
[schemaexport] at org.apache.tools.ant.Target.execute(Target.java:341)
[schemaexport] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[schemaexport] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)

[schemaexport] at org.apache.tools.ant.Project.executeTargets(Project.java:1062
)
[schemaexport] at org.apache.tools.ant.Main.runBuild(Main.java:673)
[schemaexport] at org.apache.tools.ant.Main.startAnt(Main.java:188)
[schemaexport] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
[schemaexport] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)

BUILD FAILED
D:\Program Files\Middlegen-Hibernate-r5\build.xml:264: Schema text failed: net.s
f.hibernate.MappingException: composite-id class must override equals(): org.test.hibernate.DmZspm

Total time: 26 seconds

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 11:04 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A "table without a primary key" doesn't exist in a relational database system.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 1:07 pm 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
usally your mean is right. but some table of the old database without primary key

or a table only two fields and using the two field for composite key .

except that, it seems if a table has composite key, it must have a other class for composite key. otherwise hbm2ddl can't work?

is it true?

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 22, 2005 6:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Integrated composite keys are quite possible. See docos.
(I know you sorted this issue out from the content of another thread).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 23, 2005 5:54 am 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
thanks.
the problem ablove was settled.

if I want to use intergrate composite keys , I use the older extension-tools 2.1.2 for generate codes.

I've find the docs in Wiki , http://www.hibernate.org/109.html

I see now why give up using equals() and hashCode().

but use a addtional class for implent the composite keys ,
I feel some unconvenient.
for example :

create table relation (
id integer,
friend_id integer,
note varchar(50),
primary key(id,friend_id)
)

if I use a addtional class for the composite-key , I can't use hsql like this,
"select * from Relation relation where relation.id=1

I wish it could do the same things with intergrate keys or not.
I want to use hsql also for select without intergrate keys. Is there any ways?

how about use xr.comp_id.id = 1 ?????????

althought using hsql isn't OOP, it is really convenient and intuitionistic.

using intergrate keys , the mapping is very like table's struct.
It 's easy for understand.



it seems it 's a bug:

Iterator it = ss.createQuery("select xr.title from Relation xr where id=1").iterate();

I didn't specify the table name, but it 's no error message. why ?
I change it to xr.id=1 ,it's errors be shown



======================

un other problem: I use hsqldb, the id type is identity. but why in generate d mapping file it is assigned type?
is it a bug ?

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 23, 2005 7:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Lots of questions:
1) I would not use 'id' in the table as its a reserved word in HQl so make you table (NOte id -> rel_id:
Code:
create table relation (
rel_id integer,
friend_id integer,
note varchar(50),
primary key(rel_id,friend_id)
)


2) Accessing a property of the key is straight forward.
Code:
select * from Relation relation where relation.id.rel_id=1

Note: id in the HQL means the id of the entity (which also answer you next querstion)

3) Composite key are automatically categorised as 'assigned'. If your using a identity field [rel_id for example] then you don't require the composite key (which is preferable).

I strongly suggest you keep reading the docs. Purchase HIA and create small examples.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 4:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Quote:
I would not use 'id' in the table as its a reserved word in HQl so make you table (NOte id -> rel_id:


I agree with david on this, but just to make it clear - this is *not* a requirement just a best practice to avoid confusion with respect to names. (seen to many people assuming something was a requirement in hibernate just because we recommended a certain way of doing things)

_________________
Max
Don't forget to rate


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