IllegalAccessError при использовании закрытого пакета - PullRequest
0 голосов
/ 03 мая 2019

У меня есть закрытый пакет @Entity class:

package org.github.saphyra.skyxplore.community.blockedcharacter.repository;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Data
@Builder
@Table(name = "blocked_character")
@Entity
@NoArgsConstructor
@AllArgsConstructor
class BlockedCharacterEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "blocked_character_entity_id")
    private Long blockedCharacterEntityId;

    @Column(name = "character_id")
    private String characterId;

    @Column(name = "blocked_character_id")
    private String blockedCharacterId;
}

При наличии закрытого пакета Jpa-репозитория:

package org.github.saphyra.skyxplore.community.blockedcharacter.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
//TODO unit test
public interface BlockedCharacterRepository extends JpaRepository<BlockedCharacterEntity, Long> {
    @Modifying
    @Transactional
    @Query("DELETE BlockedCharacterEntity b WHERE b.characterId = :characterId OR b.blockedCharacterId = :characterId")
    void deleteByCharacterId(@Param("characterId") String characterId);

    List<BlockedCharacterEntity> findByCharacterId(@Param("characterId") String characterId);

    BlockedCharacterEntity findByCharacterIdAndBlockedCharacterId(String characterId, String blockedCharacterId);

    @Query("SELECT b FROM BlockedCharacterEntity b WHERE " +
        "(b.characterId = :characterId AND b.blockedCharacterId = :blockedCharacterId)" +
        " OR " +
        "(b.characterId = :blockedCharacterId AND b.blockedCharacterId = :characterId)")
    List<BlockedCharacterEntity> findByCharacterIdOrBlockedCharacterId(@Param("characterId") String characterId, @Param("blockedCharacterId") String blockedCharacterId);
}

Имеет класс DAO, который обеспечивает доступ к хранилищу и обрабатывает преобразование между сущностью и dto:

package org.github.saphyra.skyxplore.community.blockedcharacter.repository;

import java.util.List;

import org.springframework.stereotype.Component;

import com.github.saphyra.converter.Converter;
import com.github.saphyra.dao.AbstractDao;
import lombok.extern.slf4j.Slf4j;
import org.github.saphyra.skyxplore.community.blockedcharacter.domain.BlockedCharacter;

@Component
@Slf4j
public class BlockedCharacterDao extends AbstractDao<BlockedCharacterEntity, BlockedCharacter, Long, BlockedCharacterRepository> {
    public BlockedCharacterDao(Converter<BlockedCharacterEntity, BlockedCharacter> converter, BlockedCharacterRepository repository) {
        super(converter, repository);
    }

    public void deleteByCharacterId(String characterId) {
        repository.deleteByCharacterId(characterId);
    }

    public BlockedCharacter findByCharacterIdAndBlockedCharacterId(String characterId, String blockedCharacterId) {
        return converter.convertEntity(repository.findByCharacterIdAndBlockedCharacterId(characterId, blockedCharacterId));
    }

    public List<BlockedCharacter> findByCharacterIdOrBlockedCharacterId(String characterId, String blockedCharacterId) {
        return converter.convertEntity(repository.findByCharacterIdOrBlockedCharacterId(characterId, blockedCharacterId));
    }

    public List<BlockedCharacter> getBlockedCharactersOf(String characterId) {
        return converter.convertEntity(repository.findByCharacterId(characterId));
    }
}

Я могу сохранить новую сущность, я могу запросить список сущностей, но когда я вызываю repository.findByCharacterIdAndBlockedCharacterId(characterId, blockedCharacterId), я получаю IllegalAccessError:

Caused by: java.lang.IllegalAccessError: tried to access class org.github.saphyra.skyxplore.community.blockedcharacter.repository.BlockedCharacterEntity from class com.sun.proxy.$Proxy105
    at com.sun.proxy.$Proxy105.findByCharacterIdAndBlockedCharacterId(Unknown Source)
    at org.github.saphyra.skyxplore.community.blockedcharacter.repository.BlockedCharacterDao.findByCharacterIdAndBlockedCharacterId(BlockedCharacterDao.java:24)
    at org.github.saphyra.skyxplore.community.blockedcharacter.BlockedCharacterQueryService.findByCharacterIdAndBlockedCharacterId(BlockedCharacterQueryService.java:19)
    at org.github.saphyra.skyxplore.community.blockedcharacter.BlockCharacterService.allowBlockedCharacter(BlockCharacterService.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
    at org.github.saphyra.skyxplore.community.blockedcharacter.BlockCharacterService$$EnhancerBySpringCGLIB$$bf4b60be.allowBlockedCharacter(<generated>)
    at org.github.saphyra.skyxplore.community.blockedcharacter.BlockedCharacterFacade.allowBlockedCharacter(BlockedCharacterFacade.java:19)
    at org.github.saphyra.skyxplore.community.blockedcharacter.BlockedCharacterController.allowBlockedCharacter(BlockedCharacterController.java:39)

Исключение не выдается, когда я устанавливаю видимость объекта для общего доступа. У меня также есть 10 других классов закрытых сущностей, и все они работают отлично. Единственное отличие в том, что другие сущности не имеют автоматически генерируемого первичного ключа с типом Long, они используют String PK-ы.

Почему я получаю это исключение?

...