Sam Kilanoff
Sam Kilanoff

Reputation: 188

Hibernate can't resolve column

I have a problem with resolving a column "name". So I assing data source and another classes resolved columns. Also i tried to refresh data. And I can't understand what's wrong.

MeteoStation entity

@Table(appliesTo = "meteo_station")
public class MeteoStation {

    @Id
    @GeneratedValue
    private int id;

    @Column(name = "name")
    private String name;

    public MeteoStation() {
    }

    //getters,setter, hashcode and equals.

}

Hibernate config file:

<?xml version="1.0" encoding="UTF-8" ?>
<hibernate-configuration>
    <session-factory>
        <property name="connection.url">jdbc:postgresql://localhost:5432/meteoreports</property>
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">root</property>
        <property name="dialect">org.hibernate.dialect.PostgreSQL94Dialect</property>
        <property name="show_sql">true</property>
        <property name="hibernate.enable_lazy_load_no_trans">true</property>

        <mapping class="ru.skilanov.model.Users"/>
        <mapping class="ru.skilanov.model.Role"/>
        <mapping class="ru.skilanov.model.MeteoStation"/>
        <mapping class="ru.skilanov.model.MeteoStationData"/>
        <mapping class="ru.skilanov.model.Reports"/>
        <mapping class="ru.skilanov.model.ReportColumns"/>
        <mapping class="ru.skilanov.model.ReportRows"/>
        <mapping class="ru.skilanov.model.MeteoStationDataPk"/>

    </session-factory>
</hibernate-configuration>

DDL script for meteo_station table:

CREATE TABLE meteo_station (
  id   SERIAL PRIMARY KEY NOT NULL,
  name TEXT
);

Upvotes: 1

Views: 343

Answers (1)

NiVeR
NiVeR

Reputation: 9786

It seems that @Table annotation that you are using is from Hibenate. Try changing the import to use the javax.persistence.Table and then @Table(name="meteo_station"). Also entity should come from javax.persistance in this case.

Upvotes: 3

Related Questions