I'm sure this is strongly related to this question but the op on that question has a bit of a scenario that I'm not sure even makes sense for DI. So here's what I understand, it's generally not a good idea to try to mix a JPA Entity with a CDI Bean because both are generally done by creating proxy objects. Here's what I envisioned, but from what I've read this is not possible.
@Entity
public class MyUniqueObject implements Serializable {
@Inject
private transient Logger log;
@Inject
private transient Event<MyUniqueObjectEvent> events;
@Id
private long id;
@NotNull
private String text;
public void setText( final String text ) {
log.debug( "updating text {}", this );
this.text = text;
events.fire( new MyUniqueObjectEvent( this ) ); // consumed by an @Observes method
}
}
What's the best way to do what I'm trying to accomplish? which is fundamentally things like events firing from within JPA persisted entities, access to log objects. Code examples helpful.