0
@Entity
@Table(name = "TAX_CATEGORY")
public class TaxCategory {
@Id
@GeneratedValue
@Column(name = "ID", nullable = false)
private long id;
@Column(name = "CATEGORY", nullable = false)
private String category;
@Column(name = "TAX", nullable = false)
private Double tax;
@Entity
@Table(name = "PRODUCT")
public class Product {
@Id
@GeneratedValue
@Column(name = "ID", nullable = false)
private long id;
@Column(name = "PRICE", nullable = false)
private Double price;
@Column(name = "NAME", nullable = false)
private String name;
@OneToOne
@JoinColumn(name = "TAX_CATEGORY_ID")
private TaxCategory taxCategory;
现在我想查询
"Select p.name, p.price, t.tax from Product p, TaxCategory t join p.taxCategory.id=t.id"
所以列出它将返回是 产品名称ProductPrice税
,但我不能够从两个得到这个数据表。单表数据工作正常。
public interface CustomRepositoryCustom {
public void customMethod();
}
public interface CustomRepository
extends JpaRepository<Account, Long>, CustomRepositoryCustom { }
public class CustomRepositoryImpl implements CustomRepositoryCustom {
public void customMethod() {
Query nativeQuery = entityManager.createNativeQuery("Select p.name, p.price, t.tax from Product p, TaxCategory t join p.taxCategory.id=t.id");
return query.getResultList();
}
}
这引发异常,该对象不是托管bean。如果我创建自定义对象,那么它也会给出类似的问题。
你是怎么查询的?你使用JPARepository吗?如果s把该代码以及 – pvpkiran
添加更多细节。 – user1298426
用'@ Service'注释来注释你的类'CustomRepositoryImpl'。 –