Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

When do ejb 3 entity bean get/set methods get called

 
john lazeraski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am trying to get a little deeper understanding of when the managed entity bean methods are called. I am using method annotations on my entity beans as I use a DTO model that I have the entity beans delegate to.

What I am not clear on is when does a getXxx() method get called.. and when does the setXxx() method get called. I would assume that when I do a query, the container will call setXxx() methods with the data from the database to store it in the entity bean. As well, I would assume when I persist an entity, the container would call the getXxx() method to pull the data from the entity bean to store it. Is this correct?

I am having some sort of issue where I try to persist one entity that has an ORM to another entity (onetomany), and it just seems to crash glassfish 3.1 with no exception output. It's difficult to track down. So I am trying to put some System.out stuff in some methods to see if the ORM method is null or not when the container tries to persist it.

Thanks.
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to log the context around your errors in EJB3/JPA you can use the life cycle annotations
JPA : @PrePersist, @PreUpdate, @PreRemove, @PostPersist, @PostUpdate, @PostRemove
EJB : @PostConstruct, @PreDestroy
 
Valery Lezhebokov
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you have two ways of reading/updating the entity fields: property access and filed access. EJB 3.0 implies JPA 2.0 in which you can define the access by @Access annotation. The default is FIELD. That means that even though you have your getters and setters the persistence provider will access the fields directly (via reflection) bypassing these methods.
Sorry, didn't see that you use method annotations. Then yes you thoughts about when these methods are invoked are correct.
 
john lazeraski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your replies. I will look at those annotations to help debug my issue.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!