@Converter(autoApply=true)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

@Converter(autoApply=true)

Rob Scala
Hello,

I'm trying OpenJPA 3.0.0 so I can use the AttributeConverter annotation.

But I'm having problems.  My converter is simple:

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)
public class StringInternConverter implements AttributeConverter<String,
String>
{
     @Override
     public String convertToDatabaseColumn(String attribute)
     {
         return attribute;
     }

     @Override
     public String convertToEntityAttribute(String dbData)
     {
         return dbData != null ? dbData.intern(): null;
     }
}

The problem is that I can't get JPA to see this converter.  When I add
it to persistence.xml like this:

     <!-- Converters -->
<class>com.be.db.jpa.StringInternConverter</class>

The enhancer complains that it StringInternConverter "does not have
persistence metadata".

Is there a trick to get this to work?

Thanks,

Rob


--
Rob Scala
Buyers Edge, Inc.
351 North Frontage Road, Suite A210
New London, CT 06320
Phone: (860) 865-2127
Reply | Threaded
Open this post in threaded view
|

Re: @Converter(autoApply=true)

Mark Struberg-3
 Hi Rob!
Thanks for your example!
I'll gonna check your sample and try to get it working.It's likely not working in 3.0.0 right now, but we try to fix it for 3.0.1.
What you can do in the meantime is to use a ValueHandler instead.
This is the OpenJPA specific version which predates the JPA @Converter logic.
rsandtner/openjpa-converter

|
|
|
|  |  |

 |

 |
|
|  |
rsandtner/openjpa-converter

Contribute to rsandtner/openjpa-converter development by creating an account on GitHub.
 |

 |

 |




LieGrue,strub

    On Wednesday, 6 February 2019, 22:05:48 CET, Robert Scala <[hidden email]> wrote:  
 
 Hello,

I'm trying OpenJPA 3.0.0 so I can use the AttributeConverter annotation.

But I'm having problems.  My converter is simple:

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)
public class StringInternConverter implements AttributeConverter<String,
String>
{
     @Override
     public String convertToDatabaseColumn(String attribute)
     {
         return attribute;
     }

     @Override
     public String convertToEntityAttribute(String dbData)
     {
         return dbData != null ? dbData.intern(): null;
     }
}

The problem is that I can't get JPA to see this converter.  When I add
it to persistence.xml like this:

     <!-- Converters -->
<class>com.be.db.jpa.StringInternConverter</class>

The enhancer complains that it StringInternConverter "does not have
persistence metadata".

Is there a trick to get this to work?

Thanks,

Rob


--
Rob Scala
Buyers Edge, Inc.
351 North Frontage Road, Suite A210
New London, CT 06320
Phone: (860) 865-2127
 
Reply | Threaded
Open this post in threaded view
|

Re: @Converter(autoApply=true)

Rob Scala
Thanks, Mark.  I'll check it out when I get some time.  Can you point me
to some documentation?

On 2/7/19 3:12 AM, Mark Struberg wrote:

>   Hi Rob!
> Thanks for your example!
> I'll gonna check your sample and try to get it working.It's likely not working in 3.0.0 right now, but we try to fix it for 3.0.1.
> What you can do in the meantime is to use a ValueHandler instead.
> This is the OpenJPA specific version which predates the JPA @Converter logic.
> rsandtner/openjpa-converter
>
> |
> |
> |
> |  |  |
>
>   |
>
>   |
> |
> |  |
> rsandtner/openjpa-converter
>
> Contribute to rsandtner/openjpa-converter development by creating an account on GitHub.
>   |
>
>   |
>
>   |
>
>
>
>
> LieGrue,strub
>
>      On Wednesday, 6 February 2019, 22:05:48 CET, Robert Scala <[hidden email]> wrote:
>  
>   Hello,
>
> I'm trying OpenJPA 3.0.0 so I can use the AttributeConverter annotation.
>
> But I'm having problems.  My converter is simple:
>
> import javax.persistence.AttributeConverter;
> import javax.persistence.Converter;
>
> @Converter(autoApply = true)
> public class StringInternConverter implements AttributeConverter<String,
> String>
> {
>       @Override
>       public String convertToDatabaseColumn(String attribute)
>       {
>           return attribute;
>       }
>
>       @Override
>       public String convertToEntityAttribute(String dbData)
>       {
>           return dbData != null ? dbData.intern(): null;
>       }
> }
>
> The problem is that I can't get JPA to see this converter.  When I add
> it to persistence.xml like this:
>
>       <!-- Converters -->
> <class>com.be.db.jpa.StringInternConverter</class>
>
> The enhancer complains that it StringInternConverter "does not have
> persistence metadata".
>
> Is there a trick to get this to work?
>
> Thanks,
>
> Rob
>
>
--
Rob Scala
Buyers Edge, Inc.
351 North Frontage Road, Suite A210
New London, CT 06320
Phone: (860) 865-2127