java - 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 对以大写字符开头的列有问题......
解决方案
很高兴听到它的固定。
除此之外,我可以看到
public interface SummonerRepository extends CrudRepository<summoners, Integer>
应该
public interface SummonerRepository extends CrudRepository<summoners, String>
推荐阅读
- python - 为什么我的 VS Code 没有使用我选择的当前 Python 环境,而使用 IPython 交互窗口?
- c# - 字典中的 C# 自动更新变量是可能的吗?
- django - django中的语言cookie
- javascript - 如何在 Vue 组件中操作一段动态 HTML
- database - 如何计算 R/W 到 HDD 的数量
- javascript - 如何获得正常的照片?
- python - 为什么混淆矩阵在其计算度量中不显示准确性
- r - 如何在我的分布中为每个最大值放置一条平均线
- python - 当我运行服务器时,如何让我的 Django 应用程序*做*一些事情?
- bigbluebutton - BigBlueButton 2-3-dev html5client 显示“404 not found”nginx 错误