gpt4 book ai didi

java - "must implement the inherited abstract method"

转载 作者:行者123 更新时间:2023-12-01 06:54:51 25 4
gpt4 key购买 nike

我的类中有 AbstractJpaDao 方法

@Override
public EntityManager getEntityManager() {
return em;
}

现在它不在使用中,我想删除它,但我收到错误:

类型JpaAclIdentityDao必须实现类JpaAclIdentityDao中继承的抽象方法IJpaDao.getEntityManager()

那个 setter/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;
}

}

最佳答案

是的,您必须实现已实现的接口(interface)中定义的所有方法。我能想到的唯一可能的解决方案是实现该方法并将其留空,或者不实现该接口(interface)。或者,正如 ben75 所说,如果您不需要(任何地方),只需删除接口(interface)“IJpaDao”声明中的方法即可。

关于java - "must implement the inherited abstract method",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14500655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com