【发布时间】:2014-07-12 16:34:02
【问题描述】:
从版本 1.4.3 升级到 1.5+ 或 1.6.0 时出现错误; 我正在使用休眠 4.3.5
例外情况是: org.springframework.beans.factory.BeanCreationException:创建名为“IAccountRepository”的bean时出错:调用init方法失败;嵌套异常是 java.lang.IllegalArgumentException:此类 [class com.model.entities.BaseEntity] 未定义 IdClass
和实体:
@MappedSuperclass
@EntityListeners(EntityAuditListener.class)
public abstract class BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Audited
@Basic(optional = false)
@Column(name = "isactive", nullable = false, columnDefinition = "BOOLEAN DEFAULT TRUE")
private boolean isActive = true;
protected BaseEntity() {
}
protected BaseEntity(boolean isActive) {
this.isActive = isActive;
}
........... more attributes and getters and setters
}
@Entity
@Table(name = "accounts", schema = "public")
@SequenceGenerator(name = "seq_account", sequenceName = "seq_account", initialValue = 1, allocationSize = 1)
@Audited
public class Account extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_account")
@Column(name = "accountid")
private Long accountId;
---- more attributes and getters and setters
}
在我看来,Spring-data-jpa 以与 Hibernate 相同的方式检查层次结构,但将超类视为一个实体。
你知道这是我的错误还是错误以及任何解决方法?
非常感谢。
编辑
我的仓库如下:
@Transactional(propagation = Propagation.MANDATORY)
@NoRepositoryBean
public interface IBaseRepository<T extends BaseEntity, ID extends Serializable> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
public Page<T> findByIsActiveTrue(Pageable pageable);
public List<T> findByIsActiveTrue();
}
@Transactional(propagation = Propagation.MANDATORY)
public interface IAccountRepository extends IBaseRepository<Account, Long> {
-- mix of queries by method name like:
public Account findByAccountIdAndIsActiveTrue(Long accountId);
-- and @Query like:
@Query(value = "SELECT COALESCE(SUM(a.accountCreditLimit), 0) FROM Account a WHERE a.name = :name")
public BigDecimal readAccountCreditLimits(@Param("name") String accountName);
}
------ and many more repositories as above
【问题讨论】:
-
你在persistence.xml中声明了BaseEntity吗?
-
不在persistence.xml中,而是在app-context.xml中:
.... AND ....com.model -
因为你没有注释为
@Entity这应该不是问题。那我现在和你一样一无所知;o)
标签: java spring hibernate jpa spring-data-jpa