-->
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.  [ 29 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: int[] in a single column
PostPosted: Tue Aug 30, 2005 5:15 pm 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
Hibernate version: 3.0.5

I'm trying to store an array of ints in a single column (not in a separate table).
I think most databases support this. At least Postgresql does :
http://www.postgresql.org/docs/current/ ... rrays.html

Is it possible to do that with hibernate ?
I saw there is a Types.ARRAY type but I couldn't find any example using it. Would this be the solution ?
Would I need to implement a special UserType ?

An alternative would be to use a String, with a special UserType that converts/decodes from int[] to String.
But this isn't as nice, as it wouldn't permit flexible queries based on the indexes like in the doc above :
SELECT pay_by_quarter[3] FROM sal_emp;

Thanks for any direction.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 10:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You'd need to write a UserType to do this provided you want to use SQL arrays for storage. Its fairly trivial. It is not supported in the built types because Hibernate types need fore-knowledge of the java type

Another option is to simply serialize the int array into the column which is supported by the built-in SerializableType


Top
 Profile  
 
 Post subject: I'll try that
PostPosted: Wed Aug 31, 2005 6:38 am 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
Thanks Steve,

I'll try to implement the UserType.


Top
 Profile  
 
 Post subject: returnedClass ?
PostPosted: Wed Aug 31, 2005 11:00 am 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
One more question :
in the case of a UserType implementing an array of ints, what should be the result of returnedClass ?
My guess is that it would need to be {Types.ARRAY}
but if I'm right, then how will the hbm2ddl work ?

Is there a way to have the hbm2dll automatically generate an int[] column ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
the returned class is the java type, not the sql type. Use "int[].class", provided thats how you want it exposed in java...


Top
 Profile  
 
 Post subject: Sorry, I meant sqlTypes()
PostPosted: Wed Aug 31, 2005 11:29 am 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
You're right, I meant the sqlTypes() method.

I think this is the one used by hbm2ddl.
So, the question remains what should this method return to have hbm2ddl generate the right DDL ?

Thanks,

Sylvain.


Top
 Profile  
 
 Post subject: hbm2dll fix found
PostPosted: Wed Aug 31, 2005 5:11 pm 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
I've found a fix for the hbm2ddl to work : Specify the column sql-type :
@hibernate.column name="my_column" sql-type="int[]"

It's not as clean as having it embedded into the UserType, but at least it work :-)

Thanks for your help.


Top
 Profile  
 
 Post subject: Solution?
PostPosted: Wed Mar 22, 2006 4:35 am 
Newbie

Joined: Mon Mar 20, 2006 9:24 am
Posts: 1
Hi, i have the same problem as Sylvain. I need to strore int[] to single Array column in postgres table. I implement UserType for this, but if i try to use it, hibernate throws exception: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003

I resolve it by creating an own dialect as subclass from PostgreSQLDialect. More info about: http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1468
And here is my first question: Is there any way of registering custom UserType to any dialect provided by hibernate?

So, dialect problem is resolved, but i have another problem - implementation of methods nullSafeGet() and nullSafeSet() in my UserType. I am not able to convert int[] to java.sql.Array. I was looking for some example or some hint, but i can't found anything. Both of the above methods deals with java.sql.Array (PreparedStatement.setArray() and ResultSet.getArray()) but i don't know how to implement interface java.sql.Array. In postgres forum i found cool solution - store int[] as string in this format: "{" numbers in int[] separated by comma "}". I dont know if this is the regular solution, but it looks like a little smut.
My second question is: How to correctly convert int[] to java.sql.Array?

Any idea?
Thanks a lot

Martin


Top
 Profile  
 
 Post subject: Code to store primitive arrays in a column
PostPosted: Wed Mar 22, 2006 5:38 am 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
Here is the code I use to store int[], String[], Date[], ... in a single column.
It works fine for me.

Hope this helps.

Code:
/*
* $LastChangedBy: sylvain $
* $LastChangedDate: 2006-02-22 17:52:11 +0400 (Wed, 22 Feb 2006) $
* $LastChangedRevision: 2613 $
*/
package com.seanergie.persistence;

import java.io.Serializable;
import java.sql.Array;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

/**
* Hibernate type to store Lists of primitives using SQL ARRAY.
* @author Sylvain
*
* References :
* http://forum.hibernate.org/viewtopic.php?t=946973
* http://archives.postgresql.org/pgsql-jdbc/2003-02/msg00141.php
*/
public abstract class ListAsSQLArrayUserType<T> implements UserType {
   private static final int SQL_TYPE = Types.ARRAY;
   private static final int[] SQL_TYPES = { SQL_TYPE };

   abstract protected Array getDataAsArray(Object value);
   
   abstract protected List<T> getDataFromArray(Object primitivesArray);

   /**
    * To use, define :
     * hibernate.property
     *       type="com.seanergie.persistence.ListAsSQLArrayUserType$BOOLEAN"
     * hibernate.column
     *       name="fieldName"
     *       sql-type="bool[]"
    */
   public static class BOOLEAN extends ListAsSQLArrayUserType<Boolean>{
      @Override
      @SuppressWarnings("unchecked")
       protected Array getDataAsArray(Object value){
           return new SqlArray.BOOLEAN( (List<Boolean>)value );
       }
      
      @Override
      protected List<Boolean> getDataFromArray(Object array){
         boolean[] booleans = (boolean[]) array;
         ArrayList<Boolean> result = new ArrayList<Boolean>( booleans.length );
         for(boolean b: booleans)
            result.add( b );
         
         return result;
      }
   }

   /**
    * To use, define :
     * hibernate.property
     *       type="com.seanergie.persistence.ListAsSQLArrayUserType$INTEGER"
     * hibernate.column
     *       name="fieldName"
     *       sql-type="int[]"
    */
   public static class INTEGER extends ListAsSQLArrayUserType<Integer>{
      @Override
      @SuppressWarnings("unchecked")
       protected Array getDataAsArray(Object value){
           return new SqlArray.INTEGER( (List<Integer>)value );
       }
      
      @Override
      protected List<Integer> getDataFromArray(Object array){
         int[] ints = (int[]) array;
         ArrayList<Integer> result = new ArrayList<Integer>( ints.length );
         for(int i: ints)
            result.add( i );
         
         return result;
      }
   }
   
   /**
    * To use, define :
     * hibernate.property
     *       type="com.seanergie.persistence.ListAsSQLArrayUserType$FLOAT"
     * hibernate.column
     *       name="fieldName"
     *       sql-type="real[]"
    */
   public static class FLOAT extends ListAsSQLArrayUserType<Float>{
      @Override
      @SuppressWarnings("unchecked")
       protected Array getDataAsArray(Object value){
           return new SqlArray.FLOAT( (List<Float>)value );
       }
      
      @Override
      protected List<Float> getDataFromArray(Object array){
         float[] floats = (float[]) array;
         ArrayList<Float> result = new ArrayList<Float>( floats.length );
         for(float f: floats)
            result.add( f );
         
         return result;
      }
   }

   /**
    * To use, define :
     * hibernate.property
     *       type="com.seanergie.persistence.ListAsSQLArrayUserType$DOUBLE"
     * hibernate.column
     *       name="fieldName"
     *       sql-type="float8[]"
    */
   public static class DOUBLE extends ListAsSQLArrayUserType<Double>{
      @Override
      @SuppressWarnings("unchecked")
       protected Array getDataAsArray(Object value){
           return new SqlArray.DOUBLE( (List<Double>)value );
       }
      
      @Override
      protected List<Double> getDataFromArray(Object array){
         double[] doubles = (double[]) array;
         ArrayList<Double> result = new ArrayList<Double>( doubles.length );
         for(double d: doubles)
            result.add( d );
         
         return result;
      }
   }
   
   /**
    * To use, define :
     * hibernate.property
     *       type="com.seanergie.persistence.ListAsSQLArrayUserType$STRING"
     * hibernate.column
     *       name="fieldName"
     *       sql-type="text[]"
    */
   public static class STRING extends ListAsSQLArrayUserType<String>{
      @Override
      @SuppressWarnings("unchecked")
       protected Array getDataAsArray(Object value){
           return new SqlArray.STRING( (List<String>)value );
       }
      
      @Override
      protected List<String> getDataFromArray(Object array){
         String[] strings = (String[]) array;
         ArrayList<String> result = new ArrayList<String>( strings.length );
         for(String s: strings)
            result.add( s );
         
         return result;
      }
   }
   
   /**
    * To use, define :
     * hibernate.property
     *       type="com.seanergie.persistence.ListAsSQLArrayUserType$DATE"
     * hibernate.column
     *       name="fieldName"
     *       sql-type="timestamp[]"
    */
   public static class DATE extends ListAsSQLArrayUserType<Date>{
      @Override
      @SuppressWarnings("unchecked")
       protected Array getDataAsArray(Object value){
           return new SqlArray.DATE( (List<Date>)value );
       }
      
      @Override
      protected List<Date> getDataFromArray(Object array){
         Date[] dates = (Date[]) array;
         ArrayList<Date> result = new ArrayList<Date>( dates.length );
         for(Date d: dates)
            result.add( d );
         
         return result;
      }
   }
   
   /**
    * Warning, this one is special.
    * You have to define a class that extends ENUM_LIST&lt;E&gt; and that has a no arguments constructor.
    * For example : class MyEnumsList extends ENUM_LIST&&ltMyEnumType&gt; { public MyEnumList(){ super( MyEnum.values() ); } }
    * Then, define :
     * hibernate.property
     *       type="com.myPackage.MyEnumsList"
     * hibernate.column
     *       name="fieldName"
     *       sql-type="int[]"
    */
   public static class ENUM<E extends Enum<E>> extends ListAsSQLArrayUserType<E>{
       private E[] theEnumValues;
      
       /**
        * @param clazz the class of the enum.
        * @param theEnumValues The values of enum (by invoking .values()).
        */
       protected ENUM(E[] theEnumValues) {
           this.theEnumValues = theEnumValues;
       }
      
      @Override
      @SuppressWarnings("unchecked")
       protected Array getDataAsArray(Object value){
         List<E> enums = (List<E>) value;
         List<Integer> integers = new ArrayList<Integer>( enums.size() );
         for(E theEnum: enums)
            integers.add( theEnum.ordinal() );

           return new SqlArray.INTEGER( integers );
       }
      
      @Override
      protected List<E> getDataFromArray(Object array){
         int[] ints = (int[]) array;
         ArrayList<E> result = new ArrayList<E>( ints.length );
         for(int val: ints){
            for(int i=0; i < theEnumValues.length; i++) {
                    if (theEnumValues[i].ordinal() == val) {
                        result.add( theEnumValues[i] );
                        break;
                    }
                }
         }
         
         if( result.size() != ints.length )
            throw new RuntimeException( "Error attempting to convert "+array+" into an array of enums ("+theEnumValues+")." );
         
         return result;
      }
   }
   
   public Class returnedClass(){
      return List.class;
   }
   
   public int[] sqlTypes(){
      return SQL_TYPES;
   }
   
    public Object deepCopy(Object value){
          return value;
    }
   
    public boolean isMutable(){
          return true;
    }
     
    @SuppressWarnings("unused")
    public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
        throws HibernateException, SQLException {
       
      Array sqlArray = resultSet.getArray(names[0]);
        if( resultSet.wasNull() )
              return null;

        return getDataFromArray( sqlArray.getArray() );
    }

    public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
        if( null == value )
            preparedStatement.setNull(index, SQL_TYPE);
        else
              preparedStatement.setArray(index, getDataAsArray(value));
    }

    public int hashCode(Object x) throws HibernateException {
        return x.hashCode();
    }
   
    public boolean equals(Object x, Object y) throws HibernateException {
        if( x == y)
            return true;
        if( null == x || null == y )
            return false;
        Class javaClass = returnedClass();
        if( ! javaClass.equals( x.getClass() ) || ! javaClass.equals( y.getClass() ) )
              return false;
       
        return x.equals( y );
    }
   
    @SuppressWarnings("unused")
    public Object assemble(Serializable cached, Object owner) throws HibernateException {
         return cached;
    }

    public Serializable disassemble(Object value) throws HibernateException {
        return (Serializable)value;
    }

    @SuppressWarnings("unused")
    public Object replace(Object original, Object target, Object owner) throws HibernateException {
        return original;
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 7:37 pm 
Newbie

Joined: Wed Nov 02, 2005 1:17 pm
Posts: 13
Looks like a good general purpose solution. However, the SqlArray class is undefined. Is that another class in your com.seanergie.persistence package?


Top
 Profile  
 
 Post subject: SqlArray class
PostPosted: Fri Apr 21, 2006 2:11 am 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
Indeed, this is another class.
Here is the code :
Code:
package com.seanergie.persistence;

import java.sql.Array;

/**
* Hibernate type to store a java array using SQL ARRAY.
* @author Sylvain
*
* References :
* http://forum.hibernate.org/viewtopic.php?t=946973
* http://archives.postgresql.org/pgsql-jdbc/2003-02/msg00141.php
*/
   
class SqlArray<T> implements Array{
   private List<T> data;
   private int baseType;
   private String baseTypeName = null;
   
   protected SqlArray(List<T> data, int baseType){
      this.data = data;
      this.baseType = baseType;
   }
   
   protected SqlArray(List<T> data, int baseType, String baseTypeName){
      this(data, baseType);
      this.baseTypeName = baseTypeName;
   }
   
   public static class BOOLEAN extends SqlArray<Boolean>{
      public BOOLEAN(List<Boolean> data){
         super(data, Types.BIT);
      }
   }
   
   public static class INTEGER extends SqlArray<Integer>{
      public INTEGER(List<Integer> data){
         super(data, Types.INTEGER);
      }
   }
   
   public static class FLOAT extends SqlArray<Float>{
      public FLOAT(List<Float> data){
         super(data, Types.FLOAT);
      }
   }
   
   public static class DOUBLE extends SqlArray<Double>{
      public DOUBLE(List<Double> data){
         super(data, Types.DOUBLE);
      }
   }
   
   public static class STRING extends SqlArray<String>{
      public STRING(List<String> data){
         super(data, Types.VARCHAR, "text");
      }
   }
   
   public static class DATE extends SqlArray<Date>{
      public DATE(List<Date> data){
         super(data, Types.TIMESTAMP);
      }
   }
   
   public String getBaseTypeName(){
      if( baseTypeName != null )
         return baseTypeName;
      return SessionsManager.getSettings().getDialect().getTypeName( baseType );
   }

   public int getBaseType(){
      return baseType;
   }

   public Object getArray(){
      return data.toArray();
   }

   public Object getArray(long index, int count){
      int lastIndex = count-(int)index;
      if( lastIndex > data.size() )
         lastIndex = data.size();
      
      return data.subList((int)(index-1), lastIndex).toArray();
   }

   @SuppressWarnings("unused")
   public Object getArray(Map<String, Class<?>> arg0){
      throw new UnsupportedOperationException();
   }

   @SuppressWarnings("unused")
   public Object getArray(long arg0, int arg1, Map<String, Class<?>> arg2){
      throw new UnsupportedOperationException();
   }

   public ResultSet getResultSet(){
      throw new UnsupportedOperationException();
   }

   @SuppressWarnings("unused")
   public ResultSet getResultSet(Map<String, Class<?>> arg0){
      throw new UnsupportedOperationException();
   }

   @SuppressWarnings("unused")
   public ResultSet getResultSet(long index, int count){
      throw new UnsupportedOperationException();
   }

   @SuppressWarnings("unused")
   public ResultSet getResultSet(long arg0, int arg1, Map<String, Class<?>> arg2){
      throw new UnsupportedOperationException();
   }
   
   @Override
   public String toString(){
      StringBuilder result = new StringBuilder();
      result.append('{');
      boolean first = true;
      
      for(T t: data){
         if( first )
            first = false;
         else
            result.append( ',' );
         
         if( t == null ){
            result.append( "null" );
            continue;
         }
         
         switch( baseType ){
            case Types.BIT:
            case Types.BOOLEAN:
               result.append(((Boolean)t).booleanValue() ? "true" : "false");
               break;

            case Types.INTEGER:
            case Types.FLOAT:
            case Types.DOUBLE:
            case Types.REAL:
            case Types.NUMERIC:
            case Types.DECIMAL:
               result.append( t );
                break;
                
            case Types.VARCHAR:
               String s = (String)t;
               // Escape the string
                 result.append('\"');
                 for(int p=0; p < s.length(); ++p){
                     char ch = s.charAt( p );
                     if( ch == '\0' )
                         throw new IllegalArgumentException( "Zero bytes may not occur in string parameters." );
                     if( ch == '\\' || ch == '"' )
                         result.append('\\');
                     result.append(ch);
                 }
                 result.append('\"');
                 break;
                
            case Types.TIMESTAMP:
               Date d = (Date)t;
               result.append('\'');
               appendDate(result, d);
               result.append( d );
               result.append('\'');
               break;

            default:
               throw new UnsupportedOperationException("Unsupported type "+baseType+" / "+getBaseTypeName());
         }
      }
      
      result.append('}');
      
      return result.toString();
   }
   
   private static GregorianCalendar calendar = null;
   protected void appendDate(StringBuilder sb, Date date){
      if (calendar == null)
         calendar = new GregorianCalendar();
      
      calendar.setTime( date );
      
      // Append Date
      {
         int l_year = calendar.get(Calendar.YEAR);
           // always use at least four digits for the year so very
           // early years, like 2, don't get misinterpreted
           //
           int l_yearlen = String.valueOf(l_year).length();
           for(int i = 4; i > l_yearlen; i--)
               sb.append("0");
   
           sb.append(l_year);
           sb.append('-');
           int l_month = calendar.get(Calendar.MONTH) + 1;
           if( l_month < 10 )
               sb.append('0');
           sb.append(l_month);
           sb.append('-');
           int l_day = calendar.get(Calendar.DAY_OF_MONTH);
           if (l_day < 10)
               sb.append('0');
           sb.append(l_day);
      }      

      sb.append(' ');
       
        // Append Time
        {
           int hours = calendar.get(Calendar.HOUR_OF_DAY);
           if (hours < 10)
               sb.append('0');
           sb.append(hours);
   
           sb.append(':');
           int minutes = calendar.get(Calendar.MINUTE);
           if (minutes < 10)
               sb.append('0');
           sb.append(minutes);
   
           sb.append(':');
           int seconds = calendar.get(Calendar.SECOND);
           if (seconds < 10)
               sb.append('0');
           sb.append(seconds);
   
           if( date instanceof Timestamp ){
              // Add nanoseconds.
              // This won't work for postgresql versions < 7.2 which only want
              // a two digit fractional second.
   
              Timestamp t = (Timestamp) date;
              char[] decimalStr = {'0', '0', '0', '0', '0', '0', '0', '0', '0'};
              char[] nanoStr = Integer.toString( t.getNanos() ).toCharArray();
              System.arraycopy(nanoStr, 0, decimalStr, decimalStr.length - nanoStr.length, nanoStr.length);
              sb.append('.');
              sb.append(decimalStr, 0, 6);
           }
      }
       
        // Append Time Zone offset
        {
           //int offset = -(date.getTimezoneOffset());
              int offset = (calendar.get(Calendar.ZONE_OFFSET)+calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
           int absoff = Math.abs(offset);
           int hours = absoff / 60;
           int mins = absoff - hours * 60;
   
           sb.append((offset >= 0) ? "+" : "-");
   
           if (hours < 10)
               sb.append('0');
           sb.append(hours);
   
           if (mins < 10)
               sb.append('0');
           sb.append(mins);
        }
       
        // Append Era
        if( calendar.get(Calendar.ERA) == GregorianCalendar.BC )
            sb.append(" BC");
   }
}


Top
 Profile  
 
 Post subject: What's missing from SqlArray.java
PostPosted: Thu May 18, 2006 9:05 am 
Newbie

Joined: Thu May 18, 2006 8:58 am
Posts: 2
I followed this thread because I'm trying to determine how to stuff a java double[] into a PostgreSQL column declared as a float8[]. Has anyone done this?

Here are the imports missing from your SqlArray.java:
Code:
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.sql.Array;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.sql.Types;


However, even with this it appears your SessionsManager class is required as well:
Code:
[javac] SqlArray.java:78: cannot find symbol
[javac] symbol  : variable SessionsManager
[javac] location: class SqlArray<T>
[javac]       return SessionsManager.getSettings().getDialect().getTypeName( baseType );


Top
 Profile  
 
 Post subject: SessionsManager.getSettings
PostPosted: Sat May 20, 2006 10:01 am 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
Here is the SessionsManager.getSettings() :
Code:
    public static Settings getSettings(){

        return ((SessionFactoryImpl)factory).getSettings();

    }

Where factory is the hibernate SessionFactory.


Top
 Profile  
 
 Post subject: Re: SessionsManager.getSettings
PostPosted: Tue May 23, 2006 11:29 am 
Newbie

Joined: Thu May 18, 2006 8:58 am
Posts: 2
Sylvain wrote:
Here is the SessionsManager.getSettings() :
Code:
    public static Settings getSettings(){

        return ((SessionFactoryImpl)factory).getSettings();

    }

Where factory is the hibernate SessionFactory.


Thanks for the assistance! Everything is working great and I am able to read/write double[] columns into PostgreSQL via JBoss/Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 6:15 am 
Newbie

Joined: Fri Dec 29, 2006 2:28 pm
Posts: 11
Hi there!
I didn't understand how to use your class ;-(
I have to store a String[] in a single column...

Originally it was:

Code:
    private String[] data;
    /**
     *   @hibernate.property
     *     column="Data"
     *     type="java.lang.String[]"
     *   @hibernate.column
     *     name="Data"
     *     sql-type="text[]"
     *     not-null="true"
     */
    public String[] getData() {
        return data;
    }
    public void setData(String[] data) {
        this.data = data;
    }


but type="java.lang.String[]" throws an error at runtime!

Code:
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.lang.String[], for columns: [org.hibernate.mapping.Column(Data)]
Exception in thread "main" java.lang.ExceptionInInitializerError


I changed it to:

Code:
    private ListAsSQLArrayUserType.STRING data;
    /**
     *   @hibernate.property
     *     column="Data"
     *     type="popolamentodb.ListAsSQLArrayUserType$STRING"
     *   @hibernate.column
     *     name="Data"
     *     sql-type="text[]"
     *     not-null="true"
     */
    public ListAsSQLArrayUserType.STRING getData() {
        return data;
    }
    public void setData(ListAsSQLArrayUserType.STRING data) {
        this.data = data;
    }


Now my problem is here:

Code:
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
       
        session.beginTransaction();
       
        Spettro nuovo = new Spettro();
        nuovo.setTeff(Teff);
        nuovo.setLogg(Integer.parseInt(Logg.trim()));
        nuovo.setFeh(Fe_h);
        nuovo.setVrot(Integer.parseInt(VRot.trim()));
        nuovo.setK(Integer.parseInt(K.trim()));
        nuovo.setAlpha(Alpha);
        nuovo.setOdf(ODF);
        nuovo.setRes(Res);
        nuovo.setTipo(Tipo);
        nuovo.setData(dati);

// how can I create and handle "dati"???
// it had to be a String[]?
// a ListAsSQLArrayUserType.STRING?
// a SqlArray.STRING?

        session.save(nuovo);
       
        session.getTransaction().commit();


please help me...
Code:

_________________
F/\B!O


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 29 posts ]  Go to page 1, 2  Next

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.