私はクラスに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;
}
}