实体图打破了阿奎利安未满足的依赖关系



using JBoss EAP7.1

我试图用 EntityGrap 替换我实体上的 FetchType.EAGER

 @Entity
@NamedQueries({
    @NamedQuery(name=Customer.FIND_ALL, query="SELECT DISTINCT c FROM Customer c"),
    @NamedQuery(name=Customer.DELETE_ALL, query="DELETE FROM Customer c")
})
@NamedEntityGraphs({
    @NamedEntityGraph(name=Customer.GRAPH_ALL, attributeNodes=
            {@NamedAttributeNode("addresses"), @NamedAttributeNode("communications")})
})
public class Customer implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 8179417957630809071L;
    public final static String FIND_ALL = "Customer.findAll";
    public final static String DELETE_ALL = "Customer.deleteAll";
    public final static String GRAPH_ALL = "Customer.graph.all";
    @Id
    @GeneratedValue
    private Long id;
    @Version
    private Timestamp version;
    @NotNull
    @Size(min=1, max=50)
    private String firstName;
    @NotNull
    @Size(min=2, max=100)
    private String lastName;
    @Enumerated(EnumType.STRING)
    private Gender gender;
    private Relationship relationship;
    private Date birthday;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval=true) 
    @JoinColumn(name="customer_id")
    private Set<Address> addresses;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
    @JoinColumn(name="customer_id")
    private Set<Communication> communications;
@Stateless
public class CustomerDAOBean extends AbstractDAOBean<Long, Customer> implements CustomerDAO {
    @Override
    public List<Customer> findAll() {
        EntityGraph<?> entityGraph = em.createEntityGraph(Customer.GRAPH_ALL);
        TypedQuery<Customer> query = em.createNamedQuery(Customer.FIND_ALL, Customer.class);
        query.setHint("javax.persistence.loadgraph", entityGraph);
        return query.getResultList();
    }
}

我的Arquillian测试以前在Eager Fetching中工作过

@RunWith(Arquillian.class)
public class CustomerTest {
    @Deployment
    public static Archive<?> createTestArchive() {
        return ShrinkWrap.create(WebArchive.class, "test.war")
                .addClasses(AbstractDAO.class, AbstractDAOBean.class, CustomerDAO.class, CustomerDAOBean.class, Customer.class, Gender.class, Relationship.class, Address.class, Communication.class, CommunicationType.class, Kind.class)
                .addAsResource("META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    }
    @Inject
    CustomerDAO customerDAO;
    @Before
    public void init() {
        customerDAO.deleteAll();
    }

    @Test
    public void testRegister() throws Exception {
        Customer customer = new Customer();
        customer.setFirstName("Hans");
        customer.setLastName("Rupp");
        customer.setGender(Gender.MALE);
        Address address = new Address();
        address.setCity("Stuttgart");
        address.setStreet("Fraubronnstr. 57a");
        address.setZip("70599");
        address.setCountry("Deutschland");
        customer.addAddress(address);
        Communication communication = new Communication();
        communication.setCommunicationType(CommunicationType.Email);
        communication.setValue("hansrupp@aol.com");
        customer.addCommunication(communication);
        customerDAO.save(customer);
        List<Customer> customers = customerDAO.findAll();
        assertEquals(1, customers.size());
        Customer customerPersistent = customers.get(0);
        assertEquals(1, customerPersistent.getAddresses().size());
        assertEquals(1, customerPersistent.getCommunications().size());
    }

现在我得到

2018-04-05 10:34:37,209 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."test.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."test.war".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1978)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CustomerDAO with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject de.rupp.test.CustomerTest.customerDAO
  at de.rupp.test.CustomerTest.customerDAO(CustomerTest.java:0)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:362)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:284)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:137)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:158)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:501)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:61)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:59)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jboss.threads.JBossThread.run(JBossThread.java:320)
2018-04-05 10:34:37,219 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) WFLYCTL0013: Operation ("deploy") fehlgeschlagen - Adresse: ([("deployment" => "test.war")]) - Fehlerbeschreibung: {"WFLYCTL0080: Fehlgeschlagene Dienste" => {"jboss.deployment.unit."test.war".WeldStartService" => "Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CustomerDAO with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject de.rupp.test.CustomerTest.customerDAO
  at de.rupp.test.CustomerTest.customerDAO(CustomerTest.java:0)
"}}
2018-04-05 10:34:37,219 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy von Deployment "test.war" wurde mit folgender Fehlermeldung zurückgesetzt: 
{"WFLYCTL0080: Fehlgeschlagene Dienste" => {"jboss.deployment.unit."test.war".WeldStartService" => "Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CustomerDAO with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject de.rupp.test.CustomerTest.customerDAO
  at de.rupp.test.CustomerTest.customerDAO(CustomerTest.java:0)
"}} 

我不知道要将哪些类添加到测试存档中。我没有添加任何内容,我只修改了实体和 DAO

非常感谢您的任何想法,

汉斯

我忘记了我也把CustomerDAO界面从@Local改为@Remote。切换回@Local测试现在有效。

相关内容

最新更新