What This Video Covers

ORM UUID v7 setup videos walk through the configuration for each major ORM — covering both application-layer generation (client-side UUID assigned before INSERT) and database-layer generation (server default function).

Skill level: Intermediate Best for: Developers migrating an existing project from UUID v4 to v7, or starting fresh with UUID v7 as the default

Key Concepts You Will Learn

1. Application-layer vs database-layer generation

Every ORM supports both approaches:

ApproachProsCons
App-layer (ORM generates)Works on any database versionUUID not available until ORM assigns it
DB-layer (DEFAULT uuidv7())Every insert path gets v7 — raw SQL tooRequires PostgreSQL 18+ or pg_uuidv7 extension

For greenfield projects on PostgreSQL 18, use database-layer generation. For portability or older DB versions, use application-layer.

2. Prisma (TypeScript / Node.js)

// schema.prisma
model Order {
  id     String @id @default(dbgenerated("uuidv7()")) @db.Uuid
  status String
}

For non-PostgreSQL or older PG:

model Order {
  id String @id @default(uuid()) // v4; override in TS with .$defaultFn
}
// Override default in application code
import { v7 as uuidv7 } from 'uuid';

const order = await prisma.order.create({
  data: { id: uuidv7(), status: 'pending' },
});

3. Drizzle ORM (TypeScript)

import { pgTable, uuid } from 'drizzle-orm/pg-core';
import { sql } from 'drizzle-orm';

export const orders = pgTable('orders', {
  id: uuid('id').primaryKey().default(sql`uuidv7()`),
  status: text('status').notNull(),
});

For app-layer: .$defaultFn(() => uuidv7()).

4. Hibernate (Java / Spring Boot)

@Entity
public class Order {
    @Id
    @UuidGenerator(style = UuidGenerator.Style.TIME) // Hibernate 6.5+ → UUID v7
    private UUID id;

    private String status;
}

For older Hibernate, use JUG:

@Id
@GenericGenerator(name = "uuid7", strategy = "com.fasterxml.uuid.impl.TimeBasedEpochGenerator")
@GeneratedValue(generator = "uuid7")
private UUID id;

See UUID in Java and Spring Boot.

5. SQLAlchemy (Python)

from sqlalchemy import Column, text
from sqlalchemy.dialects.postgresql import UUID
import uuid

class Order(Base):
    __tablename__ = 'orders'
    id = Column(
        UUID(as_uuid=True),
        primary_key=True,
        # App-layer: generates UUID v7 in Python 3.13+
        default=uuid.uuid7,
        # DB-layer (PostgreSQL 18): overrides default with server function
        server_default=text('uuidv7()'),
    )

6. Entity Framework Core (.NET)

// .NET 9 — Guid.CreateVersion7()
public class Order {
    public Guid Id { get; set; } = Guid.CreateVersion7();
    public string Status { get; set; } = "";
}

Note: SQL Server’s uniqueidentifier sorts GUIDs in a non-standard byte order. Use PostgreSQL or binary(16) for correct chronological ordering. See UUID in .NET and C#.

Watch on YouTube

Search for UUID v7 ORM setup tutorial videos on YouTube ↗

Generate and Verify

Frequently asked questions

Should UUID v7 be generated in the application or the database?

Both approaches work. Application-layer generation (using a library like the uuid npm package or Python's uuid.uuid7()) works across all database versions. Database-level generation (PostgreSQL 18's uuidv7() function as a column default) is more reliable when multiple clients or raw SQL can insert rows, since every insert path gets a v7 value automatically.

How do I use UUID v7 as a primary key in Java with Hibernate?

Hibernate 6.5+ supports UUID v7 via @UuidGenerator(style = UuidGenerator.Style.TIME). For older Hibernate versions, use the java-uuid-generator (JUG) library: Generators.timeBasedEpochGenerator().generate(). No schema migration is needed — the database uuid column type stores both v4 and v7 identically.

Do UUIDs hurt database index performance?

UUID v4 does — its randomness causes every insert to land at a different leaf page, leading to page splits and poor cache locality. UUID v7 embeds a millisecond timestamp so consecutive inserts cluster together, behaving like an auto-increment integer for B-tree purposes.

How do I configure UUID v7 as a primary key in Prisma?

In Prisma with PostgreSQL 18, use @default(dbgenerated("uuidv7()")) with @db.Uuid to generate v7 server-side. For other databases or older PostgreSQL, use @default(uuid()) for v4 or add a custom generator via .$defaultFn(() => uuidv7()) in TypeScript. See UUID v7 ORM Support in 2026.

How do I use UUID v7 with Hibernate in Java?

Hibernate 6.5+ supports UUID v7 directly via @UuidGenerator(style = UuidGenerator.Style.TIME) on an entity @Id field of type UUID. For older Hibernate, use the java-uuid-generator (JUG) library. See UUID in Java and Spring Boot.