-->
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: Map multiple columns to one array?
PostPosted: Wed Dec 15, 2010 8:17 am 
Newbie

Joined: Wed Dec 15, 2010 7:55 am
Posts: 7
Hi,

I have an unchangeable database table with columns like "week1", "week2"..."week53", and I want to map them to an object field like "int[] weeks = new int[53]". where each week column is in a different array index. Is that possible?

Regards
Roar


Top
 Profile  
 
 Post subject: Re: Map multiple columns to one array?
PostPosted: Thu Dec 16, 2010 6:28 am 
Newbie

Joined: Wed Dec 15, 2010 7:55 am
Posts: 7
No one knows?


Top
 Profile  
 
 Post subject: Re: Map multiple columns to one array?
PostPosted: Thu Dec 16, 2010 7:09 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
You could map your 53 columns as a component and add some convenience methods to your component class such as getValueForWeek(int weekNo).


Top
 Profile  
 
 Post subject: Re: Map multiple columns to one array?
PostPosted: Thu Dec 16, 2010 7:10 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Might be possible with a custom user type implementation. See http://docs.jboss.org/hibernate/core/3. ... pes-custom for more information.


Top
 Profile  
 
 Post subject: Re: Map multiple columns to one array?
PostPosted: Thu Dec 16, 2010 8:45 am 
Newbie

Joined: Wed Dec 15, 2010 7:55 am
Posts: 7
Thanks for the responses. I'll try to make a custom user type, and post back if I make it:)


Top
 Profile  
 
 Post subject: Re: Map multiple columns to one array?
PostPosted: Fri Dec 17, 2010 5:35 am 
Newbie

Joined: Wed Dec 15, 2010 7:55 am
Posts: 7
Yes, got i working like this.
Code:
<property name="weekValues" type=".package.MyUserType" >
            <column name="WEEK1"/>
            <column name="WEEK2"/>           
            <column name="WEEK3"/>
            ...
            <column name="WEEK53"/>     
</property>

    public Object nullSafeGet( ResultSet resultSet, String[] names, Object owner )
        throws HibernateException, SQLException
    {

        //    assert names.length == 53;
        int[] result = new int[ 53 ];
        for ( int i = 0; i < result.length; i++ )
        {
            result[ i ] = resultSet.getInt( names[ i ] );
        }
        if ( resultSet.wasNull() )
        {
            return null;
        }
        return result;
    }




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.