简体   繁体   中英

Moving Eclipselink Entities to separate jar

I have a working Java EE application that is hosted on JBoss. It uses EclipseLink to manage data in a Postgres database. I am now moving the entity classes to a separate jar so that they can be shared by other components. After doing this, Postgres is giving the following error:

ERROR:  operator does not exist: uuid = bytea at character 209
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

It looks like my converter class is not being called. Here is what my converter class looks like:

package model.util;

import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.mappings.converters.Converter;
import org.eclipse.persistence.sessions.Session;

import java.sql.Types;
import java.util.UUID;

public class PgUuidConverter
        implements Converter
{
    @Override
    public boolean isMutable ()
    {
        return false;
    }
    @Override
    public Object convertDataValueToObjectValue (Object value, Session session)
    {
        return (UUID) value;
    }
    @Override
    public Object convertObjectValueToDataValue (Object value, Session session)
    {
        return (UUID) value;
    }
    @Override
    public void initialize (DatabaseMapping mapping, Session session)
    {
        mapping.getField ().setSqlType (Types.OTHER);
    }
}

And here is how I'm using it in my entities:

package model;

import model.util.PgUuidConverter;
import org.eclipse.persistence.annotations.Convert;
import org.eclipse.persistence.annotations.Converter;

import java.util.UUID;
import javax.persistence.*;

@Entity
@Table (
    name           = "item",
    schema         = "main"
)
@Converter (
    name           = "uuid",
    converterClass = PgUuidConverter.class
)
public class Item
{
    public Item () {}

    @Id
    @Column (
        name     = "item_id",
        unique   = true,
        nullable = false
    )
    private UUID      itemId;
    @Column (name = "layer_id")
    @Convert ("uuid")
    private UUID      layerId;

    public UUID getItemId ()
    {
        return this.itemId;
    }

    public UUID getLayerId ()
    {
        return this.layerId;
    }

    public void setItemId (UUID itemId)
    {
        this.itemId = itemId;
    }

    public void setLayerId (UUID layerId)
    {
        this.layerId = layerId;
    }
}

Is there some kind of configuration that I'm missing?

It looks like the problem is one that appears obvious now. I need to apply the Convert annotation to all UUID fields.

Previously I had only applied the Convert annotation to nullable UUID fields since Postgres was only giving me type errors when UUID fields were set to NULL. Now Postgres is throwing exceptions for all of the UUID fields that don't have Convert annotations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM