spring-modulith icon indicating copy to clipboard operation
spring-modulith copied to clipboard

Table event_publication: value too long for type

Open ivanfryda opened this issue 1 year ago • 4 comments
trafficstars

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?

ivanfryda avatar Jan 19 '24 09:01 ivanfryda

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.

odrotbohm avatar Jan 19 '24 11:01 odrotbohm

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>

ivanfryda avatar Jan 19 '24 12:01 ivanfryda