开发者

JPA Entity Persisting another entity

I have a "sale" entity, before the entity is persisted, I'd like to create an "Income" entity. I could do this in a session bean but I'd like it better if it was encapsulated inside the Sale entity. So I could do:

em.persist(sale);

And it'd automatically create an Income entity and persist it as well.

I don't want Sale to have an association with Income because I could associate them and do a cascade persist.

It's like if the sale entity would create an instance of the Income entity and then call the persist method on the EntityManager, since this is neither posible nor a good idea I am beginni开发者_运维问答ng to think that it should be performed by the EJB. Opinions?


Have you tried the @PrePersist annotation?

JPA prepersist

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜