spring-modulith
spring-modulith copied to clipboard
Table event_publication: value too long for type
When saving an Event in PostgreSQL I get the following error:
Caused by: org.hibernate.exception.DataException: could not execute statement [ERROR: value too long for type character varying(255)] [insert into event_publication (completion_date,event_type,listener_id,publication_date,serialized_event,id) values (?,?,?,?,?,?)]
So then I forced that column to be of type bytea by creating an orm.xml in META-INF. Then I got this error:
org.hibernate.exception.SQLGrammarException: could not execute statement [ERROR: column "serialized_event" is of type bytea but expression is of type character varying Hint: You will need to rewrite or cast the expression. Position: 129] [insert into event_publication (completion_date,event_type,listener_id,publication_date,serialized_event,id) values (?,?,?,?,?,?)]
How to solve this?
How do you create the schema for the event publications? We generally recommend to not let a JPA provider create the schema. The JDBC module recommends this for PostgreSQL.
Exactly, I am letting the JPA provider create the schema. I now fixed it by having it compliant with the documentation as provided with this orm.xml:
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
http://xmlns.jcp.org/xml/ns/persistence/orm_2_2.xsd"
version="2.2">
<package>org.springframework.modulith.events.jpa</package>
<entity class="JpaEventPublication">
<attributes>
<basic name="listenerId">
<column name="listener_id" column-definition="text"/>
</basic>
<basic name="eventType">
<column name="event_type" column-definition="text"/>
</basic>
<basic name="serializedEvent">
<column name="serialized_event" column-definition="text"/>
</basic>
</attributes>
</entity>
</entity-mappings>