-->
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: New feature for Hibernate 3.1+:<Formula> inside <Se
PostPosted: Tue Sep 06, 2005 3:06 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Hi Hibernate Developers,

Is it possible to ask for this new feature for Hibernate 3.1+ in JIRA?

I previously ask in theis forum (http://forum.hibernate.org/viewtopic.php?t=947145&highlight=) if it was possible to add the <formula> tag inside the <set> element (or any Collection).

I would need that to link 2 tables (parent->children) in a one-to-many relationship, because the primary key (parent) and the foreign key (child) are not in the same type! (CHAR vs NUMERIC). I work with a legacy database, and I cannot change the type of the column.

If I could use a <formula> inside the Set instead of declaring the <column> element, I could tell Hibernate to generate the inner join using the CONVERT(VARCHAR, column) command.

All my reading about making collection in a one-to-many tells me that there is no other way to make this mapping... And I need this mapping to be able to make a HQL left outer join between theses 2 tables.

Thanks.

Etienne.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 3:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
AFAIK, this is already possible in HB 3.1. (Maybe even in 3.0.x.) Have you tried it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 4:03 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Thanks Gavin,

according to the documentation of Hibernate 3.1 section 7.2, Map (Set and other collection) can be populate with theses attributes:
see: Hibernate 3.1b2 PDF documentation, Page 80.

Code:
<map
name="propertyName" (1)
table="table_name" (2)
schema="schema_name" (3)
lazy="true|extra|false" (4)
inverse="true|false" (5)
cascade="all|none|save-update|delete|all-delete-orphan" (6)
sort="unsorted|natural|comparatorClass" (7)
order-by="column_name asc|desc" (8)
where="arbitrary sql where condition" (9)
fetch="join|select|subselect" (10)
batch-size="N" (11)
access="field|property|ClassName" (12)
optimistic-lock="true|false" (13)
mutable="true|false" (14)
node="element-name|."
embed-xml="true|false"
>


The DTD of Hibernate 3.0.5 and 3.1 (same DTD header in 3.1beta2) shows that theses are the only element for a Set:

Code:
<!ELEMENT set (
   meta*,
   subselect?,
   cache?,
   synchronize*,
   comment?,
   key,
   (element|one-to-many|many-to-many|composite-element|many-to-any),
   loader?,sql-insert?,sql-update?,sql-delete?,sql-delete-all?,
   filter*
)>
   <!ATTLIST set name CDATA #REQUIRED>
   <!ATTLIST set access CDATA #IMPLIED>
   <!ATTLIST set table CDATA #IMPLIED>                                                <!-- default: name -->
   <!ATTLIST set schema CDATA #IMPLIED>                                             <!-- default: none -->
   <!ATTLIST set catalog CDATA #IMPLIED>                                             <!-- default: none -->
   <!ATTLIST set subselect CDATA #IMPLIED>
   <!ATTLIST set lazy (true|false|extra) #IMPLIED>
   <!ATTLIST set sort CDATA "unsorted">                                              <!-- unsorted|natural|"comparator class" -->
   <!ATTLIST set inverse (true|false) "false">
   <!ATTLIST set mutable (true|false) "true">
   <!ATTLIST set cascade CDATA #IMPLIED>
   <!ATTLIST set order-by CDATA #IMPLIED>                                              <!-- default: none -->
   <!ATTLIST set where CDATA #IMPLIED>                                                <!-- default: none -->
   <!ATTLIST set batch-size CDATA #IMPLIED>
   <!ATTLIST set outer-join (true|false|auto) #IMPLIED>
   <!ATTLIST set fetch (join|select|subselect) #IMPLIED>
   <!ATTLIST set persister CDATA #IMPLIED>   
   <!ATTLIST set collection-type CDATA #IMPLIED>                                          
   <!ATTLIST set check CDATA #IMPLIED>                                                <!-- default: none -->
   <!ATTLIST set optimistic-lock (true|false) "true">      <!-- only supported for properties of a class (not component) -->
   <!ATTLIST set node CDATA #IMPLIED>
   <!ATTLIST set embed-xml (true|false) "true">


I dont see where I could use the formula Tag. The formula tag is available for properties, many-to-one and one-to-one but not for any <Set> element. Also, the one-to-many element is declared without any sub-tag or formula attribut:

Code:
<!ELEMENT one-to-many EMPTY>
   <!ATTLIST one-to-many class CDATA #IMPLIED>
   <!ATTLIST one-to-many not-found (exception|ignore) "exception">
   <!ATTLIST one-to-many node CDATA #IMPLIED>
   <!ATTLIST one-to-many embed-xml (true|false) "true">
   <!ATTLIST one-to-many entity-name CDATA #IMPLIED>


Is there an other way to do this? Thanks a lot for helping me, and sorry if I didn't see something obvious,I am still searching to make it work.

regards,


Etienne.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 4:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Oh right, it is a one-to-many.

All you need is for <key> to accept <formula> as an alternative to <column>.

Hibernate does not currently support this, but it is probably reasonably straightforward to implement in AbstractCollectionPersister.

You could produce a patch for that.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 1:44 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Thank Gavin,

could I have a small clue how to do this? What method should I look? I have checked AbstractEntityPersister to see how you manage the formulas and I must confess that it seems quite complexe.

I dont think I can patch AbstractCollectionPersister in a reasonnable time frame to make it works with formulas. If it can be part of Hibernate 3.1.1 or 3.2, I guess it is better for me to wait for it.

Thanks anyway.

Etienne.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 1:07 pm 
Newbie

Joined: Wed Jun 14, 2006 6:43 am
Posts: 4
Any updates on this problem, as I too am trying to map a collection where the columns are of different types.

Having the the key accept a formula seems a good solution, but has anyone else got a different one.

Currently I am having to initialise the collection within the DAO for all the loaded parent objects.

Cheers


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.