2

I'm using JPA/Hibernate and postgres as my DB

I created a sequence in postgres like this:

CREATE SEQUENCE player_sequence
INCREMENT 20
START 1;

I want Hibernate to use the above sequence for primary key.

The id part of the entity is:

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "player_seq")
@SequenceGenerator(name = "player_seq", sequenceName = "player_sequence", allocationSize = 20)
private Integer id;

When I create a new player and try to save it via EntityManger.persist method I get the following error:

Hibernate: select next_val as id_val from player_sequence for update org.hibernate.id.enhanced.TableStructure$1$1 execute ERROR: could not read a hi value org.postgresql.util.PSQLException: ERROR: column "next_val" does not exist

I don't understand what I do wrong

EDIT:

Here is content of persistence.xml:

enter image description here

2
  • Could you please show your hibernate config. What hibernate version do you use? Commented Aug 29, 2020 at 20:36
  • I added the persistence.xml file content in question above Commented Aug 30, 2020 at 5:13

1 Answer 1

2

Try to correct your persistence.xml in this way:

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
             version="2.2">

    <persistence-unit name="my-persistence-unit">
        <description>...</description>
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>


        <properties>
            <!--  It was wrong !!!  -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL10Dialect" />

            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/basketball" />
            <property name="javax.persistence.jdbc.user" value="postgres" />
            <property name="javax.persistence.jdbc.password" value="1234" />
            
            <property name="hibernate.show_sql" value="true" />

        </properties>

    </persistence-unit>

</persistence>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.