-->
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.  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Multiple table map -> migration from Toplink to Hibernate
PostPosted: Fri Feb 13, 2004 6:10 am 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
Hello, I am migrating an application from Toplink to Hibernate.

Toplink has a weird way to map 2 tables and become it in one singe object.

Example:

Table fields....

Table A
---------
A.ACODE >
> composite-id
A.BCODE >


Table B
---------
B.CODE > FK with A.ACODE
B.TEXT


I whould like to have one class with the atributes

private Integer Aacode;
private Integer Abcode;
private String Btext;

Is there any way to do it?

I saw something different at hibernate documentation...telling about composite identifiers but it is not what I want to do.

So could someone try to explain me how to do it?

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 7:10 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I think it is possible to do the same with View in database


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 9:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
We don't support mapping one object to multiple tables yet (it is on the roadmap for 2.2). You could work around probably by mapping two objects and using delegation.


Top
 Profile  
 
 Post subject: Help please
PostPosted: Fri Feb 13, 2004 12:11 pm 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
gloeglm wrote:
We don't support mapping one object to multiple tables yet (it is on the roadmap for 2.2). You could work around probably by mapping two objects and using delegation.


That's ok, I think I can create a join object for now and simply do the mappings independent.

I am having another other problem and I whould like to ask you because it has been a headache to me.

I have one table with composite-id that is described above.

TABLE A
---------
A.CODE > PK (2 elements)
A.TEXT >


and other table with composide-id that is described above.

TABLE B
----------
B.CODE >
B.TEXT1 >> PK (3 elements)
B.TEXT2 >


I am trying to map a Set of one-to-many from A.CODE to B.CODE but I get an error here as described above...

Foreign key must have same number of columns as referenced primary key

Therefore I am using XDoclet to generate the mappings...

It's so complicated to understand this...please help me.

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 5:02 pm 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
It seem like that would be a many-to-many relationship. Is code the primary key of another table? If it is I would map to these relationships via the code entity. It that is not the case, my guess is that a Map with many-to-many may return what you want. You would end up with something like a map element containing a key, index/column(s), and a many-to-many element.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 15, 2004 9:40 am 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
dmmorris wrote:
It seem like that would be a many-to-many relationship. Is code the primary key of another table? If it is I would map to these relationships via the code entity. It that is not the case, my guess is that a Map with many-to-many may return what you want. You would end up with something like a map element containing a key, index/column(s), and a many-to-many element.


It is not a many-to-many, sorry for my mistake to do not explain this, I was kind of desperate. on TABLE A I have a one to many to TABLE B.

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 15, 2004 1:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Something like that
Code:
<class name="B">
  <composite-id ...>
    <key-many-to-one name="a" class="A">
      <column name="code" .../>
      <column name="text1" .../>
    </key-many-to-one>
    <key-property name="text2" .../>
  </composite-id>...

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 15, 2004 4:09 pm 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
emmanuel wrote:
Something like that
Code:
<class name="B">
  <composite-id ...>
    <key-many-to-one name="a" class="A">
      <column name="code" .../>
      <column name="text1" .../>
    </key-many-to-one>
    <key-property name="text2" .../>
  </composite-id>...


Seems that there is some bright light in the end of the tunnel, whould be very nice if you please could tell me how whould I make this happen with xdoclet?

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
 Post subject: Xdoclet, very complicated.
PostPosted: Mon Feb 16, 2004 6:44 am 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
Like Emannuel said I should map as this....

<class name="B">
<composite-id ...>
<key-many-to-one name="a" class="A">
<column name="code" .../>
<column name="text1" .../>
</key-many-to-one>
<key-property name="text2" .../>
</composite-id>...


But the key-many-to-one is composed only with A.CODE not with A.TEXT

For the mapping on class A the join should be A.CODE to B.CODE one to many.

And for the class B the join should be B.CODE many to one to A.CODE but it does not work.

Please I need some help. How to do it with XDOCLET either.

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 6:51 am 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
Like emmanuel said is not possible to map the pk of table B as the table A because the table A also has a composite ID.

I am really frustrated to do not be possible to do this....

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 10:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't get your problem. You said
Quote:
A.CODE > PK (2 elements)
A.TEXT >

So CODE and TEXT is the A composite id. That's why I proposed this mapping.

Mapping A with B using only a part of the id is incosistent as per the many-to-one definition. This is a many-to-many. But I've never try to map a many-to-many using the entity table as link table

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 5:51 am 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
Hi Emmanuel, you were right....

The mistake was in the relation on toplink implementation and I now know it is a many to many relation.

Sorry for the misunderstandings.

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
 Post subject: Another problem...
PostPosted: Tue Feb 17, 2004 7:22 am 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
Hi there, as I got the many-to-many problem now I had tried to do so.

But I am getting another weird error.....

When mapping many-to-many A.CODE to B.CODE and B.CODE to A.CODE I get this error message.....

Repeated column in mapping for collection: com.example.beans.B.a column: CODE

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 7:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hard to tell without your mappings. You must not map the same column twice (for example once in a property and once in a relationship). If you do, you must set one to insert=false update=false.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 7:33 am 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
Thanks for the quick reply.

I think i can't set the insert=false, update=false in the Set and either in the composite-id.

Am I right?

_________________
Best Regards,
Ernani Joppert Pontes Martins


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2  Next

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.