【发布时间】:2016-01-02 16:22:39
【问题描述】:
我有以下模型类
@Entity
@Table(name = "tests")
public class Test implements Serializable {
@Column(nullable = false)
private String prop1;
@Column(nullable = false)
private String prop2;
@Id
@Column(nullable = false)
private String prop3;
@Column(nullable = false)
private String prop4;
public Test(final String prop1, final String prop2, final String prop3, final String prop4) {
this.prop1 = prop1;
this.prop2 = prop2;
this.prop3 = prop3;
this.prop4 = prop4;
}
我创建了以下扩展CrudRepository的接口
public interface TestRepository extends CrudRepository<Test, String> {
// blank
}
在我的控制器中,我有以下代码:
@Controller
@RequestMapping("/test")
public class TestController {
@Autowired
private TestRepository testRepository;
@RequestMapping(method = GET)
@ResponseBody
public Iterable<Test> fetchTests() {
return testRepository.findAll();
}
问题在于,当运行fetchTests 方法时,生成的查询类似于:
select test0_.prop1 as prop11_0_, test0_.prop2 as prop22_0_, test0_.prop3 as prop33_0_, test0_.prop4 as prop44_0_ from tests test0_
应该只是
select tests.prop1 as prop11_0_, tests.prop2 as prop22_0_, tests.prop3 as prop33_0_, tests.prop4 as prop44_0_ from tests
我不明白额外的tests0_ 引用来自哪里?关于什么是错的任何想法?我正在使用 postgre 作为 dbms。
【问题讨论】:
-
"test0_" 是表“tests”的别名。 SQL 中足够常见的功能。
-
当我使用 pgAdmin 运行相同的查询时它给了我一个错误 - 它可能是 postgresql 特定的东西吗? - 好像没有创建别名
-
然后向我们显示错误。
-
这个错误会是一个秘密吗?
标签: java sql spring hibernate jpa