0

I have problem with my web application. I need to display in Listthings from 4 tables. My main table is "umowienia" "appointment" and it have connection one to many with klienci AS "clients", pracownik AS "employee", usługi AS "services", and stanowiska AS "positions"

I want to connect this tables to display it on List on one of the application pages.

When I connect tables program say to me error like this

Error creating bean with name 'realizacjeRepository' defined in figura.zaklad_fryzjerski_v3.repository.RealizacjeRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, at table: klienci, for columns: [org.hibernate.mapping.Column(umowienia)]

My application look like this: construction of the application

Data base is on secodn screen screen of database

And my files:

Umowienia.java

package figura.zaklad_fryzjerski_v3.model;


import javax.persistence.*;
import java.sql.Time;
import java.util.Date;

@Entity
@Table(name = "umowienia")
public class Umowienia {


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_umowienia")
    private Integer id_umowienia;

    @Column
    private Date data_umowienia;

    @Column
    private Time czas_trwania;

    @Column
    private String komentarz;

    @ManyToOne()
    @JoinColumn(name = "id_klienta", referencedColumnName = "id_klienta", insertable = false, updatable = false)
    private Klienci klienci;




    public Klienci getKlienci() {
        return klienci;
    }

    public void setKlienci(Klienci klienci) {
        this.klienci = klienci;
    }

    public Integer getId_umowienia() {
        return id_umowienia;
    }

    public void setId_umowienia(Integer id_umowienia) {
        this.id_umowienia = id_umowienia;
    }

    public Date getData_umowienia() {
        return data_umowienia;
    }

    public void setData_umowienia(Date data_umowienia) {
        this.data_umowienia = data_umowienia;
    }

    public Time getCzas_trwania() {
        return czas_trwania;
    }

    public void setCzas_trwania(Time czas_trwania) {
        this.czas_trwania = czas_trwania;
    }

    public String getKomentarz() {
        return komentarz;
    }

    public void setKomentarz(String komentarz) {
        this.komentarz = komentarz;
    }
}

Klienci.java

package figura.zaklad_fryzjerski_v3.model;


import javax.persistence.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Entity
@Table(name = "klienci")
public class Klienci {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_klienta")
    private Integer id_klienta;

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

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

    @Column(name = "nr_telefonu_klienta")
    private Integer nrTelefonuKlienta;

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

    private List<Umowienia> umowienia;

    @OneToMany(targetEntity = Umowienia.class, mappedBy = "klienci",cascade=CascadeType.ALL, fetch = FetchType.LAZY)
    public List<Umowienia> getUmowienia() {
        return umowienia;
    }








    public void setUmowienia(List<Umowienia> umowienia) {
        this.umowienia = umowienia;
    }

    public Klienci(){
    }

    public Integer getId_klienta() {
        return id_klienta;
    }

    public void setId_klienta(Integer id_klienta) {
        this.id_klienta = id_klienta;
    }

    public String getImieKlienta() {
        return imieKlienta;
    }

    public void setImieKlienta(String imieKlienta) {
        this.imieKlienta = imieKlienta;
    }

    public String getNazwiskoKlienta() {
        return nazwiskoKlienta;
    }

    public void setNazwiskoKlienta(String nazwiskoKlienta) {
        this.nazwiskoKlienta = nazwiskoKlienta;
    }

    public Integer getNrTelefonuKlienta() {
        return nrTelefonuKlienta;
    }

    public void setNrTelefonuKlienta(Integer nrTelefonuKlienta) {
        this.nrTelefonuKlienta = nrTelefonuKlienta;
    }

    public String getAdresEmailKlienta() {
        return adresEmailKlienta;
    }

    public void setAdresEmailKlienta(String adresEmailKlienta) {
        this.adresEmailKlienta = adresEmailKlienta;
    }
}

Pracownicy.java

package figura.zaklad_fryzjerski_v3.model;


import javax.persistence.*;

@Entity
@Table(name = "pracownik")
public class Pracownicy {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_pracownika")
    private Integer id_pracownika;

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

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

    @Column(name = "nr_tele_pracownika")
    private Integer nrTelefonuPracownika;

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


+getters and setters

Stanowiska.java

package figura.zaklad_fryzjerski_v3.model;


import javax.persistence.*;

@Entity
@Table(name = "stanowiska")
public class Stanowiska {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_stanowiska")
    private Integer id_stanowiska;

    @Column(name = "numer_stanowiska")
    private Integer numerStanowiska;
+getters and setters

Uslugi.java

package figura.zaklad_fryzjerski_v3.model;


import javax.persistence.*;

@Entity
@Table(name = "uslugi")
public class Uslugi {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_uslugi")
    private Integer id_uslugi;

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

    @Column(name = "cena_uslugi")
    private Integer cenaUslugi;

FILE TO DISPLAY LIST UmowieniaRepository

package figura.zaklad_fryzjerski_v3.repository;


import figura.zaklad_fryzjerski_v3.model.Umowienia;
import org.springframework.data.jpa.repository.JpaRepository;


import org.springframework.stereotype.Repository;




@Repository
public interface UmowieniaRepository  extends JpaRepository<Umowienia, Integer> {
}

UmowieniaService

package figura.zaklad_fryzjerski_v3.service.umowienia;

import figura.zaklad_fryzjerski_v3.model.Umowienia;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public interface UmowieniaService {


    List<Umowienia> getAllUmowienia();
    void saveUmowienia(Umowienia umowienia);
}

UmowieniaServiceImpl

package figura.zaklad_fryzjerski_v3.service.umowienia;


import figura.zaklad_fryzjerski_v3.model.Umowienia;
import figura.zaklad_fryzjerski_v3.repository.UmowieniaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UmowieniaServiceImpl implements UmowieniaService {

    @Autowired
    private UmowieniaRepository umowieniaRepository;

  
    @Override
    public List<Umowienia> getAllUmowienia() {
        return umowieniaRepository.findAll();
    }

    @Override
    public void saveUmowienia(Umowienia umowienia) {
        this.umowieniaRepository.save(umowienia);
    }


}

If you need more code just write and I'll add it

1
  • 1
    Have you tried putting the annotations above the field instead of the getter method? Commented Jan 11, 2021 at 18:56

1 Answer 1

3

You are using field access strategy (determined by @Id annotation). Put any JPA related annotation right above each field instead of getter property like this in your kilenci entity

@OneToMany(targetEntity = Umowienia.class, mappedBy = "klienci",cascade=CascadeType.ALL, fetch = FetchType.LAZY)

public List<Umowienia> umowienias;
Sign up to request clarification or add additional context in comments.

3 Comments

I make what you write ` @OneToMany(targetEntity = Umowienia.class, mappedBy = "klienci",cascade=CascadeType.ALL, fetch = FetchType.LAZY) public List<Umowienia> umowienias; public List<Umowienia> getUmowienias() { return umowienias; } public void setUmowienias(List<Umowienia> umowienias) { this.umowienias = umowienias; } ` And error disapear
yes it works, try tommorow add rest of tables. I write if it gona work. When i waiting i make it by using Query :D
Thanks man, if anything else comes up reply in this comment, i will try to help you :D

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.