-->
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.  [ 3 posts ] 
Author Message
 Post subject: Database Complex Datatype Mapping
PostPosted: Fri Aug 03, 2007 6:10 pm 
Newbie

Joined: Fri Aug 03, 2007 5:31 pm
Posts: 2
Location: Utah, USA
Hibernate version: 3.1 - N/A

Mapping documents: That's the help I need

Name and version of the database you are using:
Informix 9.x and 10.x


This is a good general question to which I have been unable to find the answer in the forum, the general Hibernate Documentation, or just searching the web.

Informix 9.x onward (and I can only assume other database engines as well) has support for complex, user-defined data types. For example you can create an address data type like this:

create row type my_address_type (
line_1 varchar(50,0),
line_2 varchar(50,0),
city varchar(30,0),
....
);

And this user-defined data type can be included in any table, or such a definition can be 'in-lined' into the table (without a name) and each of the data type's fields is simply accessed through dot notation, c-style constructor notation, etc. like this:

create table person(
address my_address_type,
other_info row(name varchar(50,0), birthdate date, age integer, ...)
...
);

select address.line_1, other_info.name from person where...
insert into person values ( row('1234 Nowhere', 'apt 4', 'Podunk', ...), row('John Smith', '01/01/19xx', 'xx', ...) )...

------------------------------------

These examples are simple, but sufficiently demonstrative for my question. I would like it if I were not told to simply do it a different way - As I said, this is a simplified example.

This question is, by nature, directed at those who already knew that this object-oriented capability existed in contemporary database engines ;), but I would appreciate any help I get. I can find NO method of mapping this in hibernate. It is simple and well documented how to map simple database tables into complex objects, but there is no way I have seen to map complex database tables. Am I missing something? My search on the subject was entirely fruitless. If there is documentation for this capability somewhere, I would be forever grateful for a link. If the capability does not exist, is it in planning? I would prefer to continue to use the hibernate layer and not have to engineer a workaround. Thank you in advance for any relevant suggestions!

_________________
----------------------------------------------------
Steve ;)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 04, 2007 5:22 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
When you insert rows into these tables must you use the constructor type syntax?
i.e. insert into person values (row('123', 'qwe', 'ttt') )
or can you use the dot notation?
i.e. insert into person (row.name, row.birthdate, row.age) values ('123', 'qwe', 'ttt') )

If the latter is true then simply defining the column names in the mapping file as field.sub-field should work:
<property name="name" column="row.name"/>
<property name="birthdate" column="row.birthdate"/>
etc.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 1:11 pm 
Newbie

Joined: Fri Aug 03, 2007 5:31 pm
Posts: 2
Location: Utah, USA
Unfortunately, I can't do it that way. Informix does require the row constructor for insert and update operations. (I assume that when the user-defined data type is stored, they verify that what is in the constructor can be properly converted to the row type.)

Thanks for helping me to clear this up in my head though. It is now clear that Hibernate MUST know about these complex data types in order to use them. If it doesn't know to use a row constructor, then there is no way that I can think of to force it to use them.

Is there a way to somehow program in weird custom sql rules into the hibernate framework? Well, I just looked it up and the answer is YES. You can override hibernate's default sql with any custom sql strings you wish. That's in the online docs under 16.3. Custom SQL for create, update and delete.

Well, that's the only workaround I've found and it's probably what I'll end up having to do, but it seems like a lot of trouble all for naught to end up programming my own custom sql for every query done against the affected tables.

Hopefully Hibernate will one day have native support for object-oriented database models. Does anyone know if that's the case? I'm still wishing that it didn't have to be such a messy workaround just to get my desired transactions up and running in the Hibernate layer.

Even better, is this support built in to Hibernate and I simply still don't know? Let me know!

_________________
----------------------------------------------------
Steve ;)


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