[jboss-user] [EJB 3.0] - Trying to map two fields to the same class

jim.barrows do-not-reply at jboss.com
Wed Jun 4 00:55:29 EDT 2008


I have a class that keeps track of relationship data between two parties., so part of it looks like:
Entity
  | @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  | public class PartyRelationship extends BasePersistentModel{
  | 
  | 	@Temporal(TemporalType.DATE)
  | 	private Date fromDate;
  | 
  | 	@Temporal(TemporalType.DATE)
  | 	private Date thruDate;
  | 
  | 	@Lob
  | 	private String comment;
  | 
  | 	@ManyToOne
  | 	private PartyRole relationshipTo;
  | 
  | 	@ManyToOne
  | 	private PartyRole relationshipFrom;

When I persist this, it goes to the database correctly.  However when I retrieve the relationshipFrom field by itself, it doesn't get retrieved.  I've looked at the code and can't see where it's mapping wrong.
I force the bi-directional relationships here:

  | @Override
  | 	public String persist() {
  | 		PartyRole relationshipFrom = getInstance().getRelationshipFrom();
  | 		if( ! relationshipFrom.getInvolvedIn().contains( getInstance())){
  | 				relationshipFrom.getInvolvedIn().add(getInstance());
  | 		}
  | 		PartyRole relationshipTo = getInstance().getRelationshipTo();
  | 		if( ! relationshipTo.getInvolvedIn().contains( getInstance())){
  | 				relationshipTo.getInvolvedIn().add(getInstance());
  | 		}
  | 		return super.persist();
  | 	}
And this works.  Both the from and to are correct.  When I pull the relationship class itself, all the fields are correct.  It's only the PartyRole on the from side that doesn't get populated on retrieval, the to side works just fine.
Any ideas on what I'm doing wrong?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4155540#4155540

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4155540



More information about the jboss-user mailing list