CDI injection in sleep mode devices

We use CDI (JSR 299) in our application (JSF2 / Seam3.0 / Hibernate 3.5.6 / GlassFish 3.1.1)

While we cannot inject resources (auxiliary POJOs) into our managed beans using @Inject, we cannot do the same in our Hibernate Entity classes.

We have a base entity class (@MappedSuperclass) from which all entity objects come from. In both classes, CDI crashes.

@MappedSuperclass
public class BaseBusinessObject implements Serializable
{     
    @Inject
    private TestClass testClass; //FAILS
}


@Entity
@NamedQueries({ @NamedQuery(name = "Account.findAll", query = "SELECT b FROM Account b") })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Account extends BaseBusinessObject
{
    @Inject
    private TestClass testClass; //FAILS

}

It looks like it could be a limitation with CDI. Can anyone confirm if CDI works with Hibernate objects.

Any inputs would be appreciated.

Thanks and Regards

+3
source share
2 answers

CDI, , . , , , .

, CDI //- ? , CDI , , " Entity()"?


Edit: , utty Date - - CDI , , , apache commons DateUtils?

Time Time utils , ( concurrency).

Time Time utils CDI beans ( ), , singleton CDI beans.

. , - , - - , -.

+3

JPA CDI bean ( , ). - "C" CDI: .

CDI - bean bean . JPA - (, Lazy Loading), - : !

: 5.

CDI bean, :

@Produces
@Named
@RequestScoped
private MyEntity produceMyEntity()
{
     return new MyEntity(); //or any JPA lookup you'll need
}

, CDI

+2

Source: https://habr.com/ru/post/1526659/


All Articles