markdown 春天 - JPA预测

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 春天 - JPA预测相关的知识,希望对你有一定的参考价值。

## Original Entity
``` java
@Entity
public class MyEntity {
  public Long id;
  public string name;
  public string description;
  public string other;
}
```

## Projection interface
Create an interface with the properties that you're interested on.
``` java
public interface SimpleEntity {
  Long getId();
  string getNome();
}
```

## Query result as projection
In the JPA repository, get de result as the projected interface.
``` java
public interface MyEntityRepo extends JpaRepository<MyEntity, Long> {
  
  SimpleEntity findById(Long id);
  
}
```
### Writing queries
To get projected results writing queries, you'll need to reference each entitie's property that you're interested on.
``` java
@Query("SELECT e.id as id, e.name as name FROM MyEntity AS e")
List<SimpleEntity> findAllSimplified();
```

以上是关于markdown 春天 - JPA预测的主要内容,如果未能解决你的问题,请参考以下文章

java 春天jpa dao样本

markdown 春天Teroia。 Ambientacion del equipo

markdown jdbc,jpa,spring data jpa,hibernate,mybatis区别

markdown JPA - DTO作为结果

markdown JPA - SequenceGenerator

markdown JPA。询问