-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping list elements to separate fields on a database
PostPosted: Tue Aug 10, 2004 6:01 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
I have the following setup:

A class called Address that contains a String (post code) and a List (of address lines).

On the database this is stored as a CHAR for the post code, and 5 separate address CHAR line fields (i.e addressLine1, addressLine2 etc).

The database design is nothing to do with me and unfortunately I am stuck with it.

Is there an easy way of mapping element 0 of the list to addressLine1, element 1 to addressLine2 etc.

Basically I am stuck with the database and the object model, so my only option is to do something clever in the mapping file.

Thanks.

_________________
On the information super B road


Top
 Profile  
 
 Post subject: Re: Mapping list elements to separate fields on a database
PostPosted: Wed Aug 11, 2004 5:23 am 
Beginner
Beginner

Joined: Mon Aug 02, 2004 1:08 pm
Posts: 42
Paul Newport wrote:
I have the following setup:

A class called Address that contains a String (post code) and a List (of address lines).

On the database this is stored as a CHAR for the post code, and 5 separate address CHAR line fields (i.e addressLine1, addressLine2 etc).

The database design is nothing to do with me and unfortunately I am stuck with it.

Is there an easy way of mapping element 0 of the list to addressLine1, element 1 to addressLine2 etc.

Basically I am stuck with the database and the object model, so my only option is to do something clever in the mapping file.

Thanks.


Why don't you inroduce five getters/setters in your object?
public String getAddressLine1()
{
return mylist.get(0);
}

public void setAddressLine1(String addressLine1)
{
return mylist.set(0, addressLine1);
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 5:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Just use a usertype, or even a <dynamic-component>


Top
 Profile  
 
 Post subject: Re: Mapping list elements to separate fields on a database
PostPosted: Wed Aug 11, 2004 2:45 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
lexi wrote:

Why don't you inroduce five getters/setters in your object?
public String getAddressLine1()
{
return mylist.get(0);
}

public void setAddressLine1(String addressLine1)
{
return mylist.set(0, addressLine1);
}


I've done that as a stop gap. I want to avoid whereever possible doing any changes to the exisiting model, as then I have to do a whole bunch of regression testing and so on.

Thanks anyway though.

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 4:29 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
gavin wrote:
Just use a usertype, or even a <dynamic-component>


Ta, I used a user type, based on DoubleStringType.

That's two user tpyes I've written in a week Gavin, maybe you'd like to incorporate my latest address one into the core Hibernate code ;-)

_________________
On the information super B road


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