1

I have an existing Table in SQL Server.

CREATE TABLE [dbo].[STUDENTS](
    [ID] [int] NOT NULL,
    [FIRSTNAME] [varchar](50) NOT NULL,
    [LASTNAME] [varchar](50) NOT NULL,
    [EMAIL] [varchar](100) NOT NULL,
    [AGE] [int] NOT NULL,
    [ADDRESS] [varchar](3000) NOT NULL,
    PRIMARY KEY (ID)
);

I have created this entity in JAVA to me able to extract data using Hibernate.

package com.My_task_be.spring.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "STUDENTS")
public class Student {

    @Id
    @Column(name = "ID")
    public int id;
    @Column(name = "FISRTNAME")
    public String firstName;
    @Column(name = "LASTNAME")
    public String lastName;
    @Column(name = "EMAIL")
    public String email;
    @Column(name = "AGE")
    public int Age;
    @Column(name = "ADDRESS")
    public String Address;
    
    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public int getAge() {
        return Age;
    }
    public void setAge(int age) {
        Age = age;
    }
    public String getAddress() {
        return Address;
    }
    public void setAddress(String address) {
        Address = address;
    }
    
    
}

This is the repository

@Repository
public interface StudentRepository extends CrudRepository<Student, Integer>{
    List<Student> findAll();
    
}

This is the controller

@RestController
public class AppController {

    @Autowired
    private StudentRepository studentRpository;
    
    @GetMapping("/getAllStudents")
    public List<Student> getAllStudents(){
        return studentRpository.findAll();
    }
    
    @GetMapping("/helloWorld")
    public String helloWorld(){
        return "Hello World!";
    }
    
}

When i run http://localhost:8080/getAllStudents

I get Invalid column name 'fisrtname'.

I dont want hibernate to create a new table I just want it to read from an existing table. And I have specified the Column names but still it did not work.

Any ideas?

2
  • 1
    typo: fisrtname should be firstname Commented Dec 3, 2020 at 14:44
  • Oh My bad!!!! Thank you !! Commented Dec 3, 2020 at 14:50

1 Answer 1

1

You have a typo in FISRTNAME. It is FIRSTNAME, change as below

@Column(name = "FIRSTNAME")
public String firstName;
Sign up to request clarification or add additional context in comments.

1 Comment

Ah my bad!! I've been coding for 10 hours my eyes got ruined hahaha

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.