Reputation: 95
I have a entity user
@Entity
@Table(name="user")
public class User{
@Id
@Column(name="id")
private int id;
@Column(name="reward")
private double reward;
@Column(name="reward_id")
private double rewardId;
//Getter & Setters
}
Now what i need is to get reward and rewardId from @Query annotation from other table in DB at once.
I have tried using
@Query(value="SELECT reward,reward_id from Table_name")
public List getRewards();
but when run it says no property associated with bean. And when i Select only single column it give in my query it runs perfectly
Please help as i am new to JPA and Hibernate Thanks in advance!!
Upvotes: 0
Views: 1228
Reputation: 30449
Just use Projection:
public interface RewardProjection {
Double getReward();
Double getRewardId();
}
@Query(value = "select t.reward as reward, t.reward_id as rewardId from table_name t", nativeQuery = true)
public List<RewardProjection> getRewards();
Upvotes: 2