Hibernate OneToOne with different key types

Trying to establish a relationship between two entities: Channel (PK is Long) and AudioFile(PK is UUID).

File entity:


@Table(name = "files")

public class AudioFileEntity {


@GeneratedValue(strategy = GenerationType.AUTO)

private UUID id;

@Column(nullable = false)

private String name;


private ChannelEntity channel;

Channel entity:


@Table(name = "channels")

public class ChannelEntity {


private Long id;


@JoinColumn(name = "file_id")

private AudioFileEntity file;

When trying to generate schema from this mapping I get the following:

Caused by: org.postgresql.util.PSQLException: ERROR: foreign key constraint "fkinsmed1f8n71uyist9i0wxe8x" cannot be implemented

Detail: Key columns "file_id" and "id" are of incompatible types: uuid and bigint.

What am I doing wrong? Why is Hibernate trying to create channels.file_id field as...

Read More »

By: StackOverFlow - Tuesday, 20 November

Related Posts

  • Older News
  • Hibernate LazyInitialization @OneToOne StackOverFlow (Yesterday) - I have a problem to eagerly load through a join fetch a relation marked as lazy.@ManyToOne(fetch=FetchType.LAZY)@LazyToOne(LazyToOneOption.NO_PROXY)@JoinColumn(name = "type_id")private TypeEntity type;Because of performance issue we are currently moving all properties which...