-
1. Re: WELD-001408: Unsatisfied dependencies with parameterized type having dependencies
mkouba Mar 12, 2015 7:39 AM (in response to stessy.delcroix)Hi,
I think it should be possible. How does the injection point look like?
-
2. Re: WELD-001408: Unsatisfied dependencies with parameterized type having dependencies
stessy.delcroix Mar 12, 2015 7:46 AM (in response to mkouba)Hi Martin,
thanks for your reply.
Here is the service where the bean is injected and the entity used for testing
@Stateless
@LocalBean
@Local(TestService.class)
public class TestServiceImpl implements TestService {
@Inject
private TestDAO<TestEntity, Long> workingDAO;
@Override
public void testCdiRawType() {
this.workingDAO.findAll();
}
}
@Entity
@Table(name = "TEST_ENTITY")
public class TestEntity implements BaseEntity<Long> {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "STR")
private String str;
public String getStr() {
return this.str;
}
public void setStr(final String str) {
this.str = str;
}
}
-
3. Re: WELD-001408: Unsatisfied dependencies with parameterized type having dependencies
mkouba Mar 12, 2015 9:16 AM (in response to stessy.delcroix)Hm, it seems that it shouldn't work according to the spec and Weld 2.2.x is correct. Actually, it has nothing to do with the relation between the type variables. It's more related to how covariance works in Java. Let's go through the resolution process step by step:
Injection point:
@Inject private TestDAO<TestEntity, Long> workingDAO
Producer bean:
@Produces public <K extends BaseEntity<PK>, PK> TestDAO<K, PK> createDAO()
Now, we can identify the required type and the bean type which we would like to test:
Required type:
TestDAO<TestEntity, Long>
Bean type:
TestDAO<K extends BaseEntity<PK>, PK>
Here, the following bullet from 5.2.4. Assignability of raw and parameterized types applies:
- the required type parameter and the bean type parameter are actual types with identical raw type, and, if the type is parameterized, the bean type parameter is assignable to the required type parameter according to these rules, or
Let's test the first parameter:
Required type:
TestEntity
Bean type:
K extends BaseEntity<PK>
The spec rule:
- the required type parameter is an actual type, the bean type parameter is a type variable and the actual type is assignable to the upper bound, if any, of the type variable, or
And this rule does not match because in Java generic types are invariant, i.e. you can't assign
TesEntity
toBaseEntity<PK>
. -
4. Re: WELD-001408: Unsatisfied dependencies with parameterized type having dependencies
mkouba Mar 12, 2015 9:23 AM (in response to mkouba)Also note that wildcard types are covariant in their upper bounds.