Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPA-based event publications created by JPA provider using wrong column definition in PostgreSQL #1057

Open
kalwinskidawid opened this issue Feb 19, 2025 · 2 comments
Assignees
Labels
in: event publication registry Event publication registry meta: waiting for feedback Waiting for feedback of the original reporter

Comments

@kalwinskidawid
Copy link

kalwinskidawid commented Feb 19, 2025

Hey @odrotbohm, I found a strange aberration. I created a simple application with JPA + PostgreSQL, I let JPA create the schema (I know, I know you recommend creating it yourself). However, documentation says that the columns should be TEXT, but when JPA initializes the default schema, it defines a varchar(255), which is quite small for serialized_event.

Image

Definition from documentation:

CREATE TABLE IF NOT EXISTS event_publication
(
  id               UUID NOT NULL,
  listener_id      TEXT NOT NULL,
  event_type       TEXT NOT NULL,
  serialized_event TEXT NOT NULL,
  publication_date TIMESTAMP WITH TIME ZONE NOT NULL,
  completion_date  TIMESTAMP WITH TIME ZONE,
  PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS event_publication_serialized_event_hash_idx ON event_publication USING hash(serialized_event);
CREATE INDEX IF NOT EXISTS event_publication_by_completion_date_idx ON event_publication (completion_date);

Is the documentation outdated, or is something wrong with the spring-modulith-starter-jpa package ?

@odrotbohm
Copy link
Member

That's precisely why we don't recommend letting the JPA provider create the database schema in the first place. As you can see from the different schemas we have listed for the JDBC-based implementation, the column type for the serialized event varies from database to database. The translation from the JPA entity to the database column is entirely in the hands of the JPA provider, and the JPA annotations don't allow us to express “use whatever text column type is appropriate for the database vendor you're running on”.

We generally recommend to simply stick with the JDBC-based event publication registry implementation, even for JPA deployments, as the database interactions required for the publication management does not really benefit from JPA. It should be a slight bit faster even.

So I don't think we have anything actionable here, as the documentation is indeed correct, talking about the schemas used for the JDBC-based registry (opening of the first sentence).

@odrotbohm odrotbohm self-assigned this Feb 23, 2025
@odrotbohm odrotbohm changed the title Spring-Modulith-JPA wrong column definition in PostgreSQL JPA-based event publications created by JPA provider using wrong column definition in PostgreSQL Feb 23, 2025
@odrotbohm odrotbohm added in: event publication registry Event publication registry meta: waiting for feedback Waiting for feedback of the original reporter labels Feb 23, 2025
@kalwinskidawid
Copy link
Author

So it comes out that org.springframework.modulith:spring-modulith-starter-jpa is useless?

I moved to org.springframework.modulith:spring-modulith-starter-jdbc as you said and everything works fine, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: event publication registry Event publication registry meta: waiting for feedback Waiting for feedback of the original reporter
Projects
None yet
Development

No branches or pull requests

2 participants