-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problems with Mapping Associations
PostPosted: Fri Nov 25, 2005 9:46 am 
Newbie

Joined: Thu Nov 24, 2005 4:59 pm
Posts: 3
I have a problem making a mapping association between two classes, in hibernate 3.0

The fisrt one is like

public class ClassA implements Serializable {

private long id;
private String name;


public ClassA() {}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

With a mapping file:

<hibernate-mapping>
<class name="com.ourcompany.ourproyect.ClassA" table="EntityA">
<id name="id" column="A_Id">
<generator class="increment"/>
</id>
<property name="name" type="string" column="A_name"/>
</class>
</hibernate-mapping>

And my second class is like:

public class ClassB implements Serializable {

private long id;
private String name;
private ClassA a;


public ClassB() {}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setB(String name) {
this.name = name;
}

public ClassA getA() {
return a;
}

public void setA(ClassA a) {
this.a = a;
}
}

With a mapping file:

<hibernate-mapping>
<class name="com.ourcompany.ourproyect.ClassB" table="EntityB">
<id name="id" column="B_Id">
<generator class="increment"/>
</id>
<many-to-one name="a" column="A_Id" class="ClassA"/>
</class>
</hibernate-mapping>

I'm creating two tables to map these classes:

CREATE TABLE "EntityA"
(
"A_Id" int8 NOT NULL,
"A_Name" varchar(20),
CONSTRAINT pka PRIMARY KEY ("A_Id")
)

And,

CREATE TABLE "EntidadB"
(
"B_Id" int8 NOT NULL,
"B_Name" varchar(20),
"A_Id" int8 NOT NULL,
CONSTRAINT pkb PRIMARY KEY ("B_Id"),
CONSTRAINT fka FOREIGN KEY ("A_Id")
REFERENCES "EntityA" ("A_Id") MATCH SIMPLE
ON UPDATE RESTRICT ON DELETE RESTRICT
)

...In a PostgreSQL 8.1 database.

I'm building a .har and deploying it in JBoss 4.0.3, but the console dump me the follow error:

--- MBeans waiting for other MBeans ---
ObjectName: com.protantalo.prueba:name=ControlPagosSessionFactory
State: FAILED
Reason: org.hibernate.MappingException: An association from the table EntidadB refers to an unmapped class: ClassA

--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: com.protantalo.prueba:name=ControlPagosSessionFactory
State: FAILED
Reason: org.hibernate.MappingException: An association from the table EntityB refers to an unmapped class: ClassA


What am I doing wrong???

Thank you very much for any help...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 10:35 am 
Newbie

Joined: Tue Nov 22, 2005 10:01 am
Posts: 7
Long shot but... Not sure what DB you're using there but has table EntityA been created properly?

divo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 10:57 am 
Newbie

Joined: Thu Nov 24, 2005 4:59 pm
Posts: 3
But, the strange thing is that when I use POJO, (without composition between classes) the MBean rise without problems...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 2:50 pm 
Newbie

Joined: Tue Nov 15, 2005 2:16 pm
Posts: 10
On the mapping you state:
<class name="com.ourcompany.ourproyect.ClassB" table="EntityB">

but in the script you name:
CREATE TABLE "EntidadB"

Any way, why don't you try ddl2hbm from the hibernat tools?

Emilio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 3:55 pm 
Newbie

Joined: Thu Nov 24, 2005 4:59 pm
Posts: 3
Thanks... i found the problem... I was forgetting the package attribute in the hibernate-mapping element....

sorry


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