-->
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.  [ 11 posts ] 
Author Message
 Post subject: Mapping arrays - hasn't anyone done this??!!
PostPosted: Mon Nov 14, 2005 2:53 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 1:03 pm
Posts: 38
I have searched the online documentation exhaustively (is that a word?) and I finally went out and bought a Hibernat book and I have yet to find any clear and definitive examples of mapping an array in a hibernate xml document. Specifically, I am trying to map arrays of Strings and arrays of doubles. It seems that the documentation takes you to a certain point in doing this and then just drops you. I can't get a clear answer from anyone what tags to use. After playing around with it a bit, I finally got my xml map file to the point where it at least parses but I'm still getting errors when I try to map these elements. Can someone give me a clear example of mapping an array of Strings? Or an array of doubles? I am starting to believe that it has never been done!! This is so frustrating! If someone can help me, I'll give you all my credits!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 3:57 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
Why not just use a List of strings, which is more flexible anyway -- the mapping for this is straightforward. If you really need to map a "String[]" array, you may have to revert to a custom mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 4:45 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 1:03 pm
Posts: 38
jensydney wrote:
Why not just use a List of strings, which is more flexible anyway -- the mapping for this is straightforward. If you really need to map a "String[]" array, you may have to revert to a custom mapping.


Because all of the source code is written with static arrays and it has been decided that it will stay that way


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 7:17 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
Quote:
Specifically, I am trying to map arrays of Strings and arrays of doubles.... Can someone give me a clear example of mapping an array of Strings? Or an array of doubles? I am starting to believe that it has never been done!!

How was it done before? I'm sure the app didn't just stuff an entire array into a single column, because that isn't even 1NF, so each array element must be somehow stored individually. If that's true, then mapping each element is just a straight application of Hibernate basic value type mapping.

But should your app be completely whacked, you're more than welcome to post some sample code/mapping here.


jd


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 4:16 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
sarahsmith_books wrote:
jensydney wrote:
Why not just use a List of strings, which is more flexible anyway -- the mapping for this is straightforward. If you really need to map a "String[]" array, you may have to revert to a custom mapping.


Because all of the source code is written with static arrays and it has been decided that it will stay that way


I guess, you might be able to do this with a UserType.

Otherwise, you'll probably have to resort to DTO (data transport objects) in which you load your data from the db using lists and then copy the data to your real objects.

_________________
hth,
Heinz
Don't forget to rate if this helped


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 5:22 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
The main question to ask is.


How is the data currently stored in the databse, how is it currently accessed etc.


Sarah, if you could supply us with the schmea, more info on data storage there is a higher chance we may be able to help you.

Also, are you working for a sonar firm that sells it's products through an agent called tritech? Just some of the code you've posted seems familiar.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 12:53 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 1:03 pm
Posts: 38
I'm going to answer all these posts with one entry to save time:

jd001982:
Quote:
How was it done before? I'm sure the app didn't just stuff an entire array into a single column, because that isn't even 1NF, so each array element must be somehow stored individually. If that's true, then mapping each element is just a straight application of Hibernate basic value type mapping.

*** Yes, it is "stuffed" into a single column as an array declared float8[] and char(256)[]

hhuber:
Quote:
Otherwise, you'll probably have to resort to DTO (data transport objects) in which you load your data from the db using lists and then copy the data to your real objects.

*** I believe this is the solution we are going to use, we will have to convince the team that it is the way to go and then create the methods to do the copying. I think it will be a lot better than creating a bunch of tables to hold the arrays and then mapping them back to the parent table ***

Jaimie:
Quote:
The main question to ask is



"How is the data currently stored in the databse, how is it currently accessed etc." .



*** It is stored as float8[] and char(256)[] -- one dimensional arrays in a column of the database ***


Quote:
Also, are you working for a sonar firm that sells it's products through an agent called tritech? Just some of the code you've posted seems familiar

*** No, I don't work this firm :-) ***


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 10:12 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
sarahsmith_books wrote:
*** Yes, it is "stuffed" into a single column as an array declared float8[] and char(256)[]

Ouch!!
But what database are you using that allows this?
Is the column a BLOB or VARCHAR?
What did the old code do to write the 8 floats into this column?

Hibernate obviously doesn't let you map array to column, but you can always write a stored procedure to do this, and map the SP as shown in 17.4. Custom SQL for create, update and delete.

jd


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 10:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You can do this by writing a UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 3:54 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
sarahsmith_books wrote:
I'm going to answer all these posts with one entry to save time:

...

Jaimie:
Quote:
The main question to ask is

"How is the data currently stored in the databse, how is it currently accessed etc." .



*** It is stored as float8[] and char(256)[] -- one dimensional arrays in a column of the database ***



Then you have another option: Use a UserType.
I'm sure you can write up an implementation that converts from the column value to the array and the other way round.

_________________
hth,
Heinz
Don't forget to rate if this helped


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 12:36 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 1:03 pm
Posts: 38
Again, I will answe all these ensuing posts with a single reply to save time:

jd:

Quote:
Ouch!!
But what database are you using that allows this?
Is the column a BLOB or VARCHAR?
What did the old code do to write the 8 floats into this column?

Hibernate obviously doesn't let you map array to column, but you can always write a stored procedure to do this, and map the SP as shown in 17.4. Custom SQL for create, update and delete. .[/quote]

Well jd, it is Postgresql and it is a char. I'm not sure how the original data was mapped into this column. I haven't looked at the code yet that does it. I'm sure I will get to that point sometime soon.

gavin:

Quote:
You can do this by writing a UserType.


Gavin, I was hoping not to have to get into user types yet since I have just started using Hibernate and I'm taking it one small step at a time, but thanks, I will probably look into this too.

Thanks for all your feedback! I wish I had more credits to give out! I need to start earning some!


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