It might sound a bit strange (or dirty) but I need to do some logic in an entity bean.
Due to a legacy data model which is not normalized (of course) I was asked to check if it is possible to load data from different tables in a property of an entity when its getter is called the first time.
I thought about using the annotation @Postload which would be the right time to fill the property but I don't know how to inject an entity manager to do my database queries because @PersistanceContext works only with session and message driven beans.
Of course it's a similar problem with persisting the data. At the moment I use a special persist()-method in the entity bean with an entity manager as parameter so the entity bean can persist itself and than save the additional data of the different tables.
Of course this method hast to be called explicitly by a session bean instead of a normal entityManager.persist(myEntity) but I think this is more intuitive than calling explicitly a load() method after getting the entity.
Of course there are better alternatives like DAOs but maybe there is an possibilty to do it directly in the entity bean which would hide the complexity "near" the persistence tier. ;)