【发布时间】:2019-06-24 22:03:21
【问题描述】:
我在 SQL 数据库中有一个表,其中包含重复条目(这意味着我无法创建复合键)并且没有主键。
我希望能够检索与特定列 accountRef 匹配的所有条目。
简而言之,我想执行以下查询:
SELECT * from table where accountRef='xyz'
其中“xyz”是用户输入。
我面临的问题是使用 @Entity 不允许我不指定 ID。有没有办法解决这个问题? 这是我的代码 BasicAccountAudit.java
@XmlRootElement
@Entity
//@Embeddable
@Table(name = "tb_Account_History", schema="dbo")
public class BasicAccountAudit implements Serializable{
private String accountRef;
private String client;
//getters and setters
BasicAccountAuditRepository.java
@Repository
public interface BasicAccountAuditRepository extends CrudRepository<BasicAccountAudit, Integer> {
List<BasicAccountAudit> findAll();
List<BasicAccountAudit> findByAccountRef(String accountRef);
}
我的尝试
我尝试使用@Embeddable,但它给了我这个错误:
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“basicAccountController”的bean时出错:通过方法“setBasicAccountDao”参数0表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“basicAccountDaoImpl”的 bean 时出错:通过方法“setBasicAccountAuditRepository”参数 0 表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“BasicAccountAuditRepository”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.IllegalArgumentException: Not a managed type:
【问题讨论】:
-
JPA 不是没有 ID 的选项。没有解决方法。如果您不能使用某种唯一标识符,则可能使用 mybatis 回退到 JDBC。
标签: java sql-server spring rest jpa