Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: AttributeConverter with SQL Array?
PostPosted: Tue Jun 06, 2017 6:28 pm 
Newbie

Joined: Fri May 05, 2017 12:09 pm
Posts: 7
Hi,

I have a database column that is a `varchar[]`. I'm trying to convert that to a Java property that is an `EnumSet<Foo>`. I defined an AttributeConverter to go from `java.sql.Array` to an EnumSet. The converter method is getting called, but I don't see how I can create an `Array` at that point.

Code:
   
@Convert(converter = FooConverter.class)
private EnumSet<Foo> foos;


In the converter, I don't see how to build the array:

Code:
public class FooConverter extends EnumSetConverter<Foo> { ... }
public class EnumSetConverter<T extends Enum<T>> implements AttributeConverter<EnumSet<T>, Array> {
  public Array convertToDatabaseColumn(EnumSet<T> ts) {
    for (T e : ts) {
        String s = e.toString();
        ???
    }
  }


Maybe I shouldn't use java.sql.Array for this?


Top
 Profile  
 
 Post subject: Re: AttributeConverter with SQL Array?
PostPosted: Wed Jun 07, 2017 12:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1226
AttributeConverters are way too limited.

Try using the Hibernate Types and Descriptors for that, like in this example.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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.