Programming
comments 3

ERROR: column notation .id applied to type name, which is not a composite type

Note to Self:

If you are using PostgreSQL with Hibernate and got this error, make sure that the entity names are not in the PostgreSQL’s reserved keywords. So the table name(or the Entity name) “User” is going to give the error in the title!

3 Comments

  1. jivkoto says

    Very useful. Let me share an workaround if you still want your entity/table to be named User.
    Background: Hibernate creates a query like this:
    select
    user0_.id as id0_,
    user0_.first_name as first2_0_,
    user0_.last_name as last3_0_,
    from
    user user0_
    This user in the from clause messes the things.
    The work around is to specify your schema. Can be done in two ways

    1. By specifying the schema in the table in the @Table annotation. In case of schema public, will look like this.

    @Entity
    @Table(schema=”public”, name = “user”)

    2. By specifying the schema in the schema in the persistence.xml

    This will crate a query that works:
    select
    user0_.id as id0_,
    user0_.first_name as first2_0_,
    user0_.last_name as last3_0_,
    from
    public.user user0_

    Note that public.user

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">