首页 > 解决方案 > Spring Hibernate 没有将实体映射到 PostGres 中的现有表

问题描述

嗨,我有一个休眠问题,它没有将名为“summoners”的实体映射到 Postgre 中名为“summoners”的现有表

在此处输入图像描述

Postgre 版本:9.2

Sts 版本:4.4.2.RELEASE

召唤师.java

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

@Entity
@Table(name = "summoners")
public class summoners {
    @Id
    @Column(name = "SummonerName")
    private String SummonerName;
    @Column(name = "SummonerEncryptedID")
    private String SummonerEncryptedID;
}

SummonerRepository.java

package hello;
import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;


// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete

public interface SummonerRepository extends CrudRepository<summoners, Integer> {

}

GreetingController.java

package hello;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();
    @Autowired 
    private SummonerRepository summonerRepository;


    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return new Greeting(counter.incrementAndGet(),
                            String.format(template, name));
    }

    @RequestMapping("/summoners")
    public Iterable<summoners> summoners() {
        return summonerRepository.findAll();
    }


}

固定的

问题是 postgre 9.2.0 对以大写字符开头的列有问题......

标签: javaspringhibernate

解决方案


很高兴听到它的固定。

除此之外,我可以看到

public interface SummonerRepository extends CrudRepository<summoners, Integer> 

应该

public interface SummonerRepository extends CrudRepository<summoners, String>

推荐阅读