• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on ejbCreate().  RSS feed

 
Mayuri Roi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two beans. Person and Address with one-to-many relation.

When I create Address using ejbCreate, I am setting all the address fields and in ejbPostCreate() I am setting setPerson(person).

My question is: can I set a field of Person in ejbCreate of Address bean?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is: can I set a field of Person in ejbCreate of Address bean


Since the Person bean is still not creted a refernce to Person EJB from Address bean cannot be obtained.
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you need to tune the relationship fields, let Person have an instance field that referers to an Address entity, instead of the Address entity having a instance field of a Person.
 
Mayuri Roi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradip, I already have persons created. And also, I am passing Person reference in ejbCreate of Address.

Daniel, Person has a relationship field of Address as 'addresses' that gives me person.getAdrressess() and person.setAddresses().
Also, Address has a relationship field of Person as 'person' that gives me address.getPerson() and address.setPerson().

What I am trying to do is...

in Address Bean...

ejbCreate(AddressDTO dto, Person parentPerson) ... {
//some business logic...
...
//Set address fields... ex:
setName(dto.getName());
setField2(dto.getField2());
...
...
//THE FOLLOWING LINE IS WHAT I WOULD LIKE TO DO... BUT NOT SURE OF ANY IMPLICATIONS
parentPerson.setSomeField(someValue);

//continue setting other address fields...
setField3(dto.getField3());
....
}
ejbPostCreate(AddressDTO dto, Person parentPerson) ... {
setPerson(parentPerson);
}
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mayuri

Yes , you can set the fields of the Person field.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!