「必須實現繼承的抽象方法」我在我的類AbstractJpaDao方法
@Override
public EntityManager getEntityManager() {
return em;
}
現在是不是在使用,我想刪除它,但我得到的錯誤:
類型JpaAclIdentityDao
必須在類JpaAclIdentityDao
中實施繼承的抽象方法IJpaDao.getEntityManager()
。
是必要的getter?如果不是如何刪除它
我的代碼:
public abstract class AbstractJpaDao implements IJpaDao {
protected final IApplicationConfig config;
protected final EntityManager em;
private final SingletonEventBus eventBus;
public AbstractJpaDao(EntityManager entityManager, IApplicationConfig config, SingletonEventBus eventBus) {
checkArgument(entityManager != null);
checkArgument(config != null);
checkArgument(eventBus != null);
this.em = entityManager;
this.config = config;
this.eventBus = eventBus;
}
protected void saveEntity(IEntity entity) {
boolean isNew = entity.getId() == 0;
em.getTransaction().begin();
try {
em.persist(entity);
em.getTransaction().commit();
if (isNew) {
eventBus.post(new EntityCreatedEvent(entity));
}
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
}
}
@Repository
public class JpaAclIdentityDao extends AbstractJpaDao implements IAclIdentityDao {
public static final String GROUP_NAME_PATTERN = "GROUP_%d";
private static final String GROUP_TEMP_NAME = "TEMP_GROUP_NAME";
@Inject
public JpaAclIdentityDao(EntityManager entityManager, IApplicationConfig config, SingletonEventBus eventBus) {
super(entityManager, config, eventBus);
}
@Override
public AclIdentity findById(Object id) throws EntityNotFoundException {
return em.find(AclIdentity.class, id);
}
@Override
public List<AclIdentity> findAll() {
return findAllByType(AclIdentity.class);
}
@Override
public void delete(AclIdentity entity) {
// TODO Auto-generated method stub
}
@Override
public void save(AclIdentity entity) {
saveEntity(entity);
}
@Override
public AclIdentity createNew(String sid, boolean principal) {
AclIdentity identity = new AclIdentity(sid, principal);
save(identity);
return identity;
}
@Override
public AclIdentity createNew(User entity) {
return createNew(entity.getEmail(), true);
}
@Override
public AclIdentity createNew(Group entity) {
AclIdentity identity = createNew(GROUP_TEMP_NAME, false);
identity.setSid(String.format(GROUP_NAME_PATTERN, identity.getId()));
save(identity);
return identity;
}
}
這麼愚蠢的錯誤...非常感謝您的快速回答 – akuzma