【发布时间】:2012-09-21 07:33:24
【问题描述】:
背景
数据表item:
+---------+---------+--------+
| field | type | index |
+---------+---------+--------+
| id_item | INT | PK |
| name | VARCHAR | UNIQUE |
+---------+---------+--------+
ItemRepository.java:
public interface ItemRepository extends CustomRepository<Item, Integer> {
public Item getByName(String name); // because of the unique index
}
CustomRepository.java:
@NoRepositoryBean
public interface CustomRepository<E, PK extends Serializable> extends PagingAndSortingRepository<E, PK>, JpaSpecificationExecutor<E> {
// common methods
}
CustomRepositoryImpl.java:
public class CustomRepositoryImpl<E, PK extends Serializable> extends SimpleJpaRepository<E, PK> implements CustomRepository<E, PK> {
// common methods implementations
}
问题
如您所见,接口ItemRepository 没有实现。这意味着,getByName 方法只有一个签名,永远不会在任何地方实现。但它有效。怎么样?
附言
对于持怀疑态度的人,使用 Eclipse,当按住 Ctrl 并将鼠标悬停在 getByName 签名上时,单击 Open Implementation 根本不会打开任何 JAVA 文件。
【问题讨论】:
标签: java spring jpa repository unique-index