我有两个表的数据库:春库查询两个表
1)NumberEntity
|------|-------|--------|
| id |numero | volume |
|------|-------|--------|
| 1 | 1 | 1 |
|------|-------|--------|
| 2 | 1 | 2 |
|------|-------|--------|
| 3 | 2 | 1 |
|------|-------|--------|
2)ArticleEntity
|------|-------|------------|
| id |Article| numbers_id |
|------|-------|------------|
| 5 | 7 | 1 |
|------|-------|------------|
| 6 | 5 | 2 |
|------|-------|------------|
| 7 | 6 | 3 |
|------|-------|------------|
哪里numbers_id是第一个表的关系。 我想解压缩通过第一个 表,文章desc订购的文章。 我不知道我该怎么办呢,我开始与此查询:
public List<NumberEntity> findByVolumeAndNumero(String volume, String number);
我的文章的列表中,但首先是文章数7,而不是我想萃取,如第一篇文章数字5,6和7
这是我的模型:
@Entity
public class NumberEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String volume;
private String numero;
@OneToMany(mappedBy="numbers", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ArticleEntity> articles = new ArrayList<ArticleEntity>();
另:
@Entity
public class ArticleEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String article;
@ManyToOne
private NumberEntity numbers;
所以我需要这样一个查询(即使itsn't纠正,但它只能是伪代码):
public List<NumberEntity> findByVolumeAndNumeroOrderByArticleDesc(String volume, String number);
的问题是,我不知道如何加入其他表用使用弹簧的单个查询
https://stackoverflow.com/questions/43891571/crudrepository-join-single-field-from-other-table-to-entity-as-readonly.please检查此链接。 – Ram