0
私は2つのテーブルを持っています。 私もSQLでこのアクションのパラメータの最大日付スプリングデータ。休止状態。 1対多の関係のときに結合テーブルの結果を制限する
create table user(
id int,
name char(5)
);
create table action(
id int,
user_id int,
action char(5),
rep_date date
);
として送信する可能性を追加し、それは私がエンティティクラスを作成すること
select t1.*, t2* from user t1
left join action t2 on (t1.id = t2.user_id)
join (select t3.user_id, max(t3.rep_date) as max_date
from action t3
group by t3.user_id) t4 on (t2.user_id=t4.user_id and t2.rep_date=t4.max_date)
ようになり、ユーザーによって作られたよりも最後のアクションを見つけたいですユーザーにリポジトリ内
リストに @OneToManyを持っている
@Repository
public interface StudyMatherialRepository extends CrudRepository<User, Long> {
@Query(value="select distinct u from User u left join fetch sm.action a1 join (select a2.user_id, max(a2.rep_date) max_date from sm.history a2
group by a2.user_id) a3 on (a1.user_id = a2.user_id and a1.rep_date= a2.max_date)
")
public List<StudyMaterial> findAllwithNative();
}
私は を取得しましたorg.hibernate.hql.internal.ast.QuerySyntaxException:予期しないトークン と私はそれを修正することができません。私は私たちがすることができ、User
に@ManyToOne
関係を持つことができUserAction
エンティティから来ることによって、これを達成するために容易になるだろうと信じて