-->
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.  [ 10 posts ] 
Author Message
 Post subject: hbm Mapping mutilpe-table to a class
PostPosted: Tue Jan 25, 2005 10:15 pm 
Newbie

Joined: Tue Jan 25, 2005 10:07 pm
Posts: 4
hi,I want map mutiple-table to a class.
i.e. TBL_Record_200401, TBL_Record_200402,TBL_Record_200403.......
map to a class , Record.

What should i do?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 8:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look at using entity-name in Hibernate3.

With entity-name you can map the same class to multiple table (the thing that now differs is the entity-name instead of classname)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 4:21 am 
Newbie

Joined: Tue Jan 25, 2005 10:07 pm
Posts: 4
Thanks :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 10:27 am 
Newbie

Joined: Fri Mar 18, 2005 9:30 am
Posts: 7
max wrote:
look at using entity-name in Hibernate3.

With entity-name you can map the same class to multiple table (the thing that now differs is the entity-name instead of classname)


I need to to split data into diffent tables of a legacy-system.
Depending on the id of an object the mapping should be selecetd.
e.g obj1 with id = 1000 has another mapping than obj2 with id= 2000

<class
...
entity-name ="1000"
...
</class>

<class
...
entity-name ="2000"
</class>

This will result in an error of the JDBC-DRIVER when a SELECT-STATEMENT is issued by hibernate, because the value of entity-name (eg. 1000 or 2000) is used to create an alias for the table name.

Is there any way that the value of the <entity-name> tag is not bounded by the JDBC-Driver?


Hibernate: select 1000x_.id, 1000x_.column1 as column2_0_, 1000x_.column2 as column3_0_ from test.t1 1000x_ where 1000x_.id=?
com.mchange.v2.c3p0.impl.NewPooledConnection@3020ad invalidated by Exception: org.postgresql.util.PSQLException: ERROR: syntax error at or near "x_"

at org.postgresql.util.PSQLException.parseServerError(PSQLException.java:139)


A workaround is to use "n1000" and "n2000" instead of "1000" and "2000". But that´s not sufficient for my problem.

In fact the mapping according to the id of an object is not the whole problem.The reason why I´m trying to omit the JDBC-restrictions is, that I´ve also other properties eg. listId, listSelectionId. Depending on the values of these properties the mapping has to be selected.

e.g.
list1Id = 1 and list1SelectionId =1 => mapping1
list1Id = 1 and list1SelectionId =2 => mapping2
...

And depending on the combination of the values of other properties some values have to be modified.

e.g.
list2Id = 1 and list2SelectionId = 1 => Update .... SET x = y *10
list2Id = 1 and list2SelectionId = 2 => Update .... SET x = y *100
list2Id = 1 and list2SelectionId = 3 => Update .... SET x = y *1000


So entity-name does not all I need.


Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 12:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I dont understand why using "n1000" etc doesnt work for you.

all the other stuff you have sounds like its solvable by formula...

Besides your mapping sounds really "scary" ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 5:14 am 
Newbie

Joined: Fri Mar 18, 2005 9:30 am
Posts: 7
max wrote:
I dont understand why using "n1000" etc doesnt work for you.

all the other stuff you have sounds like its solvable by formula...

Besides your mapping sounds really "scary" ,)


All I found about "formula" is, that it can be used for "select" statements or for the <discriminator> tag when working with the table-per-class-hierarchy mapping strategy.

Maybe I´m wrong, but "formula" can´t be used for update/insert statements.

n1000 works fine for the case of choosing a mapping according to an id.
But when it comes to more complex cases that might not be scalable, because the length of the entity-name i.e. the length of the table alias might be the limiting factor.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 5:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes, sorry - formulas doesnt work with updating (since they per definition is read only)

but the update statement you are showing i really dont see a solution for except with something like batch update.

I cant see how you would map (in any orm) those sqls in a more or less static mapping file. they look more like very specific more or less hand og "non-normalized" algoritmic crafted sql.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 6:30 am 
Newbie

Joined: Fri Mar 18, 2005 9:30 am
Posts: 7
[quote="max"]yes, sorry - formulas doesnt work with updating (since they per definition is read only)

but the update statement you are showing i really dont see a solution for except with something like batch update.

I cant see how you would map (in any orm) those sqls in a more or less static mapping file. they look more like very specific more or less hand og "non-normalized" algoritmic crafted sql.

/max[/quote

Yes indeed, "non-normalized" is the right expression for it.
Is there any way to manipulate the update/ insert a runtime (using "PreUpdateEventListener" and "PreInsertEventListener") ?]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 8:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
No - and if there were, how would you know what sql to execute ?

custompersister is what you need in this case i would assume.//

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 9:07 am 
Newbie

Joined: Fri Mar 18, 2005 9:30 am
Posts: 7
max wrote:
No - and if there were, how would you know what sql to execute ?

custompersister is what you need in this case i would assume.//


Thanks a lot for responding so fast.
I will use custompersister and let you know about the results.


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