我在课堂上有 AbstractJpaDao 方法
@Override
public EntityManager getEntityManager() {
return em;
}
现在它没有被使用,我想删除它,但我收到错误:
该类型必须实现类JpaAclIdentityDao
中继承的抽象方法。IJpaDao.getEntityManager()
JpaAclIdentityDao
那个吸气剂是必要的吗?如果不是如何删除它
我的代码:
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;
}
}