Generic MappedSuperclass

39 views
Skip to first unread message

Diogo Ferreira

unread,
May 15, 2023, 8:26:05 AM5/15/23
to Ebean ORM
Hello everyone!

I was wondering of generic MappedSuperclasses are supported. I saw an old post saying they were not but it was from 10 years ago so I was wondering if that changed.

What I am trying to do:

I have this MappedSuperclass

@MappedSuperclass
public abstract class LongIDTimestampedEntity<I> extends TimestampedEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, updatable = false)
    private Long underlyingId;

    @Convert(converter = LongIDAttributeConverter.class)
    @Column(name = "id", nullable = false, insertable = false, updatable = false)
    private LongID<I> id;

But when I try to use it like this:

@Entity
@Table(name = Constants.TableNames.SELECTION_ENGINE_CONTEXT)
public class EntitySelectionEngineContext
    extends LongIDTimestampedEntity<SelectionEngineContext>
    implements SelectionEngineContext {

The generated query entity is trying to import I instead of using SelectionEngineContext.

So is this supported? If so, what am I doing wrong? If not, are there any plans to support it in the future?

Thank you in advance!

Rob Bygrave

unread,
May 18, 2023, 11:22:00 PM5/18/23
to eb...@googlegroups.com
It looks to me like the issue here is likely related to the generic type used with the AttributeConverter:

    @Convert(converter = LongIDAttributeConverter.class)
    @Column(name = "id", nullable = false, insertable = false, updatable = false)
    private LongID<I> id;

I don't believe AttributeConverter supports a generic type like LongID<I>.

You say "The generated query entity is trying to import I instead ..." ... which implies the generated query bean can't compile. You could try to use the entity bean without generating query beans in order to confirm if the AttributeConverter works as you intend it (but I'm not expecting it to support the generic LongID<I> type).




--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/596775bf-30e7-4934-b5bf-580f90ecf3c1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages