• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot set the CMRs in ejbPostCreate()  RSS feed

 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going trough a big problem wich i cannot think of any solution wich will maintain my business logic. Here it goes...

I have 2 beans in my app that are called CompanyBean (CMP) and CompanyPhoneBean (CMP). This is a one(Company)-to-many(CompanyPhones) relation, tough i only want a UNI-Directional relation from Company to CompanyPhones. In other words, i only want to get the phones from the company and don't want to get the companies from the phones (it wouldn't make sense in my case).

As you see in my code, i can set all relations in my ebjPostCreate() perfectly, except the CompanyPhones one. I think this is because i cannot associate the companyID to the CompanyPhonesVO by the CompanyPhonesVO.setCompany(CompanyLocal comp) method, it probably happens because, as i said, i don't have a Direction from CompanhPhone to Company. So rigth at this line i get a exception.


So, can anybody give me a solution for that, please???

I'm posting, first, my exception, and after it, the create methods for the beans and the related setter/getters.
I also highlighted where i get the exception.

ERROR [LogInterceptor] TransactionRolledbackLocalException in method: public abstract ltcmelo.valueobjects.CompanyVO ltcmelo.localinterface.CompanyLocal.getCompanyVO(), causedBy:
javax.ejb.EJBException: Reentrant method call detected: Company 8
at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:106)
continues...

CompanyBean


The CompanyPhone bean.


//...

/**
*
* Returns the owner company of the phone.
*
* @return CompanyLocal
*
* @ejb.value-object
* aggregate-name="Company"
* aggregate="ltcmelo.valueobjects.CompanyVO"
* members-name="Company"
* members="ltcmelo.localinterface.CompanyLocal"
* relation="external"
*
*/
public abstract CompanyLocal getCompany();

/**
*
* Sets the owner company of the phone.
*
* @param companyLocal
*
*/
public abstract void setCompany(CompanyLocal companyLocal);[/code]


Thanks in advance,
ltcmelo
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In other words, i only want to get the phones from the company and don't want to get the companies from the phones

But you still have getCompany() on the PhoneLocal?

Anyways is company_id field a non-null foreign key column on the Phone table?
If not why dont you just create the phones in a loop(which you already are doing) without setting the company information.
Keep adding the PhoneLocal that the create() returns to a collection and in the end do a

this.setPhones(phoneCollection);

on the company bean.

 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't work because in companyPhone ejbPostCreate i need the companyID, co this information has to be set.

CompanyPhone ejbPostCreate (the same one i posted in the first post)



Any other idea?
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry! Now I notice that you are getting a re-entrant exception on company.
Ok why dont you move the creation of phones and setting of the company on that phone into the session bean that is acting as a facade?
I do understand that you need company id while creating phones.

I also assume that the session bean is actually executing this business logic.
Why dont you try this..
create() the company, and pass the companyLocal reference that you obtain as a result while creating the phones from within the session bean.



So, you dont have to do a findByPrimaryKey() on the company that you just created in the ejbCreate of Phone.

Am not sure why you are getting a re-entrant exeption though.
The following situation

Entity A --calls --> Entity B --calls--> A this will result in the exception you are referring to.

I guess you are not doing a companylocal.someMethod() within the Phone bean.

Either way try moving such logic to the session bean instead of doing it within the company bean. I'm sure a company can exist without phones . So why create phones from within the company? This dependency IMO is unnecessary.
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Either way try moving such logic to the session bean instead of doing it within the company bean. I'm sure a company can exist without phones . So why create phones from within the company? This dependency IMO is unnecessary.


I already solved the problem by changing the db schemma, anyway,
I agree with you, it's not necessary. Tough, i'll let the user creates phones in two ways:
- as soon as he/she register the company (the phone goes together)
- later (creating the phone whenever he/she likes to)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!