title: JPA, Hibernate, postgreSQL: Unable to build Hibernate SessionFactory
body: <p>Im trying to do some example app with EJB, JPA-Hibernate. </p>
  
  <p>I did a PostgreSQL database like this:</p>
  
  <pre><code>CREATE TABLE Klasa (
  idKlasa SERIAL,
  Profil VARCHAR NULL,
  Skrot VARCHAR NULL,
  PRIMARY KEY(idKlasa)
  );
  
  CREATE TABLE Przedmiot (
   idPrzedmiot SERIAL,
  idKlasa INTEGER  NOT NULL,
  Nazwa VARCHAR NULL,
  PRIMARY KEY(idPrzedmiot),
  FOREIGN KEY (idKlasa) REFERENCES Klasa(idKlasa)
  );
  
  CREATE TABLE Uczen (
   idUczen SERIAL,
   idKlasa INTEGER  NOT NULL,
  Imie VARCHAR NULL,
   Nazwisko VARCHAR NULL,
  PRIMARY KEY(idUczen),
  FOREIGN KEY (idKlasa) REFERENCES Klasa(idKlasa)
  );
  
  CREATE TABLE Ocena (
  idUczen INTEGER  NOT NULL,
  idPrzedmiot INTEGER  NOT NULL,
  Ocena INTEGER  NULL,
  PRIMARY KEY(idUczen, idPrzedmiot),
  FOREIGN KEY (idUczen) REFERENCES Uczen(idUczen),
  FOREIGN KEY (idPrzedmiot) REFERENCES Przedmiot(idPrzedmiot)
   );
  </code></pre>
  
  <p>Then i generate Entities with EclipseLink 2.5.</p>
  
  <p>Now, im trying to get any record from Klasa table. But i stuck on some errors while deploying on WildFly 8.2:</p>
  
  <pre><code> 20:38:11,089 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 50) MSC000001: Failed to start service jboss.persistenceunit."Lab1.war#Lab1": org.jboss.msc.service.StartException in service jboss.persistenceunit."Lab1.war#Lab1": javax.persistence.PersistenceException: [PersistenceUnit: Lab1] Unable to build Hibernate SessionFactory
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
  at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_40]
  at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_40]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_40]
  at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_40]
  at org.jboss.threads.JBossThread.run(JBossThread.java:122)
  Caused by: javax.persistence.PersistenceException: [PersistenceUnit: Lab1] Unable to build Hibernate SessionFactory 
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>20:38:11,089 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" =&gt; "Lab1.war")]) - failure description: {"JBAS014671: Failed services" =&gt; {"jboss.persistenceunit.\"Lab1.war#Lab1\"" =&gt; "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"Lab1.war#Lab1\": javax.persistence.PersistenceException: [PersistenceUnit: Lab1] Unable to build Hibernate SessionFactory
  Caused by: javax.persistence.PersistenceException: [PersistenceUnit: Lab1] Unable to build Hibernate SessionFactory
  Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: pl.edu.wat.model.Ocena column: idprzedmiot (should be mapped with insert=\"false\" update=\"false\")"}}
  20:38:11,089 WARN  [org.jboss.as.jpa] (Controller Boot Thread) JBAS011411: Unexpected problem gathering statistics: java.lang.IllegalStateException: JBAS011477: Persistence unit 'Lab1.war#Lab1' is not available
  </code></pre>
  
  <p>I have no idea what im doing wrong. I will post persistance.xml and Ocena Entity (becouse error point on it)</p>
  
  <p>persistance.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.1"
  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_1.xsd"&gt;
  &lt;persistence-unit name="Lab1" transaction-type="JTA"&gt;
      &lt;class&gt;pl.edu.wat.model.Klasa&lt;/class&gt;
      &lt;class&gt;pl.edu.wat.model.Ocena&lt;/class&gt;
      &lt;class&gt;pl.edu.wat.model.OcenaPK&lt;/class&gt;
      &lt;class&gt;pl.edu.wat.model.Przedmiot&lt;/class&gt;
      &lt;class&gt;pl.edu.wat.model.Uczen&lt;/class&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.connection.username" value="postgres" /&gt;
          &lt;property name="hibernate.connection.password" value="postgres" /&gt;
          &lt;property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/Lab1" /&gt;
          &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /&gt;
          &lt;property name="hibernate.show_sql" value="true" /&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="validate" /&gt;
  
      &lt;/properties&gt;
  
  &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Ocena.java</p>
  
  <pre><code>@Entity
  @NamedQuery(name="Ocena.findAll", query="SELECT o FROM Ocena o")
  public class Ocena implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @EmbeddedId
  private OcenaPK id;
  
  private Integer ocena;
  
  //bi-directional many-to-one association to Przedmiot
  @ManyToOne
  @JoinColumn(name="idprzedmiot")
  private Przedmiot przedmiot;
  
  //bi-directional many-to-one association to Uczen
  @ManyToOne
  @JoinColumn(name="iduczen")
  private Uczen uczen;
  
  public Ocena() {
  }
  
  public OcenaPK getId() {
      return this.id;
  }
  
  public void setId(OcenaPK id) {
      this.id = id;
  }
  
  public Integer getOcena() {
      return this.ocena;
  }
  
  public void setOcena(Integer ocena) {
      this.ocena = ocena;
  }
  
  public Przedmiot getPrzedmiot() {
      return this.przedmiot;
  }
  
  public void setPrzedmiot(Przedmiot przedmiot) {
      this.przedmiot = przedmiot;
  }
  
  public Uczen getUczen() {
      return this.uczen;
  }
  
  public void setUczen(Uczen uczen) {
      this.uczen = uczen;
  }
  
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>here are other ends of associations.</p>
  
  <p>Uczen.java</p>
  
  <pre><code>@Entity
  @NamedQuery(name="Uczen.findAll", query="SELECT u FROM Uczen u")
  public class Uczen implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private Integer iduczen;
  
  private String imie;
  
  private String nazwisko;
  
  //bi-directional many-to-one association to Ocena
  @OneToMany(mappedBy="uczen")
  private List&lt;Ocena&gt; ocenas;
  
  //bi-directional many-to-one association to Klasa
  @ManyToOne
  @JoinColumn(name="idklasa")
  private Klasa klasa;
  
  public Uczen() {
  }
  
  public Integer getIduczen() {
      return this.iduczen;
  }
  
  public void setIduczen(Integer iduczen) {
      this.iduczen = iduczen;
  }
  
  public String getImie() {
      return this.imie;
  }
  
  public void setImie(String imie) {
      this.imie = imie;
  }
  
  public String getNazwisko() {
      return this.nazwisko;
  }
  
  public void setNazwisko(String nazwisko) {
      this.nazwisko = nazwisko;
  }
  
  public List&lt;Ocena&gt; getOcenas() {
      return this.ocenas;
  }
  
  public void setOcenas(List&lt;Ocena&gt; ocenas) {
      this.ocenas = ocenas;
  }
  
  public Ocena addOcena(Ocena ocena) {
      getOcenas().add(ocena);
      ocena.setUczen(this);
  
      return ocena;
  }
  
  public Ocena removeOcena(Ocena ocena) {
      getOcenas().remove(ocena);
      ocena.setUczen(null);
  
      return ocena;
  }
  
  public Klasa getKlasa() {
      return this.klasa;
  }
  
  public void setKlasa(Klasa klasa) {
      this.klasa = klasa;
  }
  
  }
  </code></pre>
  
  <p>Przedmiot.java</p>
  
  <pre><code>@Entity
  @NamedQuery(name="Przedmiot.findAll", query="SELECT p FROM Przedmiot p")
  public class Przedmiot implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private Integer idprzedmiot;
  
  private String nazwa;
  
  //bi-directional many-to-one association to Ocena
  @OneToMany(mappedBy="przedmiot")
  private List&lt;Ocena&gt; ocenas;
  
  //bi-directional many-to-one association to Klasa
  @ManyToOne
  @JoinColumn(name="idklasa")
  private Klasa klasa;
  
  public Przedmiot() {
  }
  
  public Integer getIdprzedmiot() {
      return this.idprzedmiot;
  }
  
  public void setIdprzedmiot(Integer idprzedmiot) {
      this.idprzedmiot = idprzedmiot;
  }
  
  public String getNazwa() {
      return this.nazwa;
  }
  
  public void setNazwa(String nazwa) {
      this.nazwa = nazwa;
  }
  
  public List&lt;Ocena&gt; getOcenas() {
      return this.ocenas;
  }
  
  public void setOcenas(List&lt;Ocena&gt; ocenas) {
      this.ocenas = ocenas;
  }
  
  public Ocena addOcena(Ocena ocena) {
      getOcenas().add(ocena);
      ocena.setPrzedmiot(this);
  
      return ocena;
  }
  
  public Ocena removeOcena(Ocena ocena) {
      getOcenas().remove(ocena);
      ocena.setPrzedmiot(null);
  
      return ocena;
  }
  
  public Klasa getKlasa() {
      return this.klasa;
  }
  
  public void setKlasa(Klasa klasa) {
      this.klasa = klasa;
  }
  
  }
  </code></pre>