Search code examples
hibernatekotlinvert.x

Hibernate: Collection is declared with a raw type and has an explicit 'targetEntity'


I am using hibernate reactive in a Kotlin vert.x project and I when I try to build, I get the following error: Collection 'com.chaluchukwu.drone_system.entities.Delivery.cargoes' is declared with a raw type and has an explicit 'targetEntity' Here is my Delivery entity class:


@jakarta.persistence.Entity(name = "deliveries")
@Table(name = "deliveries")
open class Delivery(
  @Column(name = "user_name")
  open var userName: String? = null,


  @Column(name= "reference")
  open var reference: String? = UUID.randomUUID().toString().substring(0,10),

  @ManyToOne
  open var drone: Drone? = null,

  @OneToMany
  open var cargoes: List<Cargo>? = listOf(),

  @CreationTimestamp(source = SourceType.DB)
  @Column(name = "created_at")
  open var createdAt: Date? = null,

  @UpdateTimestamp(source = SourceType.DB)
  @Column(name = "updated_at")
  open var updatedAt: Date? = null,

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  open var id: Long? = null
  ) {}

What could be the problem?


Solution

  • In Delivery class specify the targetEntity attribute for the @OneToMany annotation to remove any ambiguity and let Hibernate determine the target entity type for the elements in the collection.

    @OneToMany(targetEntity = Cargo::class)
    open var cargoes: List<Cargo>? = listOf()