-->
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.  [ 6 posts ] 
Author Message
 Post subject: Help with association mapping in Hibernate
PostPosted: Thu Dec 15, 2005 2:45 pm 
Newbie

Joined: Wed Dec 14, 2005 5:17 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: db2

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hello...

Can somebody please tell me how to create an association for two tables that need to be joined like substr(table1.field1,4,10) = table2.field1


How can I define that association in Hibernate..?

<one-to-one ..?

_________________
-ramr.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 15, 2005 2:52 pm 
Beginner
Beginner

Joined: Thu Apr 07, 2005 5:12 pm
Posts: 27
Location: Hamburg
I would use a "one to many / many to one" relation. See Manual chapter 7.


Top
 Profile  
 
 Post subject: Help with association mapping in Hibernate
PostPosted: Thu Dec 15, 2005 3:26 pm 
Newbie

Joined: Wed Dec 14, 2005 5:17 pm
Posts: 5
Thanks, but, how can I specify an association like substr(table1.field,4,10) = table2.field, I mean the value of field for table2 is contained in the field of table1, that's why I need to take only the characters from position 4 to 10 in the string field for table1.

Both fields are primary keys in their respective tables...

Thanks,

_________________
-ramr.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 15, 2005 3:35 pm 
Beginner
Beginner

Joined: Thu Apr 07, 2005 5:12 pm
Posts: 27
Location: Hamburg
chapter 5.1.5. composite-id

I think you can use this to construct your own primary key.


Top
 Profile  
 
 Post subject: Help with association mapping in Hibernate
PostPosted: Thu Dec 15, 2005 4:18 pm 
Newbie

Joined: Wed Dec 14, 2005 5:17 pm
Posts: 5
Thanks for you answer again, I did look but I guess that what I need is not there... I don't know if I explain myself crearly, so here I go again...

Let suppose that I have this two tables...

create table table1 (field1 varchar(10) not null primary key, field2 int)
create table table2 (field1 varchar(8) not null primary key, field2 int null, field3 int null)

field1 in table1 contains what's on field1 in table2, the only different is two characters on field1 in table1, that I do not want to take into consideration.

Need to join them, taking only 8 of the 10 characters from field1 in table1 and the 8 character of field1 in table2

How do I create this association, so I only have to use a join in a query


Thanks,

_________________
-ramr.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 10:14 am 
Beginner
Beginner

Joined: Thu Apr 07, 2005 5:12 pm
Posts: 27
Location: Hamburg
To be free from Database Implementations I wold write a methos to the object with the cropped String (here Object2) and use this property for you HQL.

Sth. like

select o1 from Object1 as o1, Object2 as o2 where o1.pk = o2.croppedFk;

If you want to be close to your database use a native sql query and the given substr('field',startIndex,endIndex) function.

Now closer to your problem?


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