-->
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.  [ 4 posts ] 
Author Message
 Post subject: accessing table with only FK an without PK
PostPosted: Fri Jan 23, 2004 4:04 am 
Beginner
Beginner

Joined: Sun Oct 12, 2003 2:14 pm
Posts: 25
Location: Zagreb, Croatia
I have table CUSTOMER with id CUS_ID, and table CUSTOMER_ADD with attribute CUS_ID which is FK on CUSTOMER and attribute varchar(255) MISC. Because CUSTOMER_ADD does not have PK it must be as collection in CUSTOMER. Here is mapping Customer.hbm.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "file:///C:/var/ws/ks/src/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="Customer" table="CUSTOMER">
<id name="cus_id" column="CUS_ID" type="long" unsaved-value="null">
<generator class="native" />
</id>
<list name="customerAdd" table="CUSTOMER_ADD">
<key column="CUS_ID" foreign-key="CUS_ID"></key>
<index column="CUS_ID"></index>
<one-to-many class="CustomerAdd"/>
</list>

</class>
</hibernate-mapping>

When I run from prompt "net.sf.hibernate.tool.hbm2ddl.SchemaExport --text customer.hbm.xml" I get error:

01:00:58,507 ERROR SchemaExport:310 - Error creating schema
net.sf.hibernate.MappingException: Association references unmapped class: CustomerAdd

What I am doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 4:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well, you have not mapped CustomerAdd. Either map it or consider using a collection of value type (http://www.hibernate.org/hib_docs/reference/html/collections.html#collections-s1-5)

Besides, why are you running SchemaExport? You have your DB allready don't you?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 5:04 am 
Beginner
Beginner

Joined: Sun Oct 12, 2003 2:14 pm
Posts: 25
Location: Zagreb, Croatia
Thanks, works with:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "file:///C:/var/ws/ks/src/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="Customer" table="CUSTOMER">
<id name="cus_id" column="CUS_ID" type="long" unsaved-value="null">
<generator class="native" />
</id>

<set name="customerAdd" table="CUSTOMER_ADD">
<key column="CUS_ID" />
<element column="MISC" type="string"/>
</set>
</class>
</hibernate-mapping>


Here is DDL:

create table CUSTOMER_ADD (CUS_ID BIGINT not null, MISC VARCHAR(255))

create table CUSTOMER (CUS_ID BIGINT not null, primary key (CUS_ID))

alter table CUSTOMER_ADD add constraint FKBFDC7CA07729A7F9 foreign key (CUS_ID) references CUSTOMER

CREATE TABLE hibernate_sequence(id NUMERIC)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 5:35 am 
Beginner
Beginner

Joined: Sun Oct 12, 2003 2:14 pm
Posts: 25
Location: Zagreb, Croatia
hbartolin wrote:

<set name="customerAdd" table="CUSTOMER_ADD">
<key column="CUS_ID" />
<element column="MISC" type="string"/>
</set>


Or even better, instead of set I can use bag because bag does not create PK(cus_id, misc) in CUSTOMET_ADD table.


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