views:

679

answers:

3

Using JPA, and Hibernate as the provideer, I have a class defined like:

@Entity
@Table(name="partyrole")
public class PartyRole extends BaseDateRangeModel {
  private static final long serialVersionUID = 1L;
  private Party roleFor;

  public void setRoleFor(Party roleFor) {
    this.roleFor = roleFor;
  }

  @ManyToOne
  public Party getRoleFor() {
    return roleFor;
  }
}

And I get the error in title of the question. I've tried adding public void setType(Object type) but that doesn't work either. The persistence.xml file is normal. There are two classes that reference this one, but neither of them attempts to invoke setType either. I'd apprecaite any help!!!! This happens at deployment time. The stack trace is at the bottom.

The Parent Class:

package com.nsfw.bmp.common.jpa;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.validator.AssertTrue;
import org.hibernate.validator.NotNull;

/**
 * Several models are date range sensitive, this base class provides that basic
 * functionality.
 * 
 * @author jim
 * 
 */
@MappedSuperclass
public abstract class BaseDateRangeModel extends BasePersistentModel {
private static final long serialVersionUID = 1L;
private Date from;
private Date thru;

/**
 * Determines if a model is active. A model is active if now is after or
 * equal to from , and thru is either null, or after now, or equal to now.
 */
@Transient
public boolean isActive() {
 Date now = new Date();
 boolean afterFrom = from.before(now) || from.equals(now);
 boolean beforeThru = thru == null || thru.after(now)
   || thru.equals(now);
 return afterFrom && beforeThru;
}

@AssertTrue(message = "Dates are not valid the thru date must be empty, or after the fromdate.")
public boolean areDatesValid() {
 if (thru == null) {
  return true;
 } else {
  return thru.after(from);
 }
}


@Temporal(TemporalType.TIMESTAMP)
@NotNull
@Column(name = "fromDate")
public Date getFrom() {
 return from;
}

public void setFrom(Date from) {
 this.from = from;
}

@Temporal(TemporalType.TIMESTAMP)
public Date getThru() {
 return thru;
}

public void setThru(Date thru) {
 this.thru = thru;
}

}

Its parent:

package com.nsfw.bmp.common.jpa;

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@MappedSuperclass
public abstract class BasePersistentModel implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;

protected Long id;

protected Long version = 0l;

@Override
public boolean equals(Object obj) {
 if (this == obj)
  return true;
 if (obj == null)
  return false;
 if (getClass() != obj.getClass())
  return false;
 BasePersistentModel other = (BasePersistentModel) obj;
 if (id == null) {
  if (other.id != null)
   return false;
 } else if (!id.equals(other.id))
  return false;
 if (version == null) {
  if (other.version != null)
   return false;
 } else if (!version.equals(other.version))
  return false;
 return true;
}

@Id
@GeneratedValue
public Long getId() {
 return id;
}

@Version
public Long getVersion() {
 return version;
}

@Override
public int hashCode() {
 final int prime = 31;
 int result = 1;
 result = prime * result + ((id == null) ? 0 : id.hashCode());
 result = prime * result + ((version == null) ? 0 : version.hashCode());
 return result;
}

public void setId(Long id) {
 this.id = id;
}

public void setVersion(Long version) {
 this.version = version;
}

}

The Party class is fairly large, with a lot of mappings. This is the one asked for:

/**
 * @return the actingAs
 */
@OneToMany(mappedBy="roleFor", targetEntity=com.nsfw.bmp.party.entity.association.PartyRole.class)
@OrderBy("from")
public List<PartyRole> getActingAs() {
 return actingAs;
}

Here's the stack trace:

Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property type in class com.nsfw.bmp.party.entity.association.PartyRole
at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:240)
at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:233)
at org.hibernate.mapping.Property.getSetter(Property.java:299)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:272)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:149)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:76)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:325)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:457)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
A: 

You problem might be linked to the BaseDateRangeModel class, because PartyRole extends it. can you show us that class?

Luzifer42
A: 

Can you post your party class? I have a suspicion that this has to do with your manytoone mapping. Is there a type column in the partyRole table?

Gren
I added that, it's not helping at all.. *SIGH* thought that was it too..
Jim Barrows
That was the answer, I had another issue that resulted in the same error (old code lying around)
Jim Barrows
A: 

If you're getting this during startup, it means you have a class somewhere referencing PartyRole via inverse relationship, e.g. something along the lines of

@OneToMany(targetEntity=PartyRole.class, inverse=true")

in some other entity. Set hibernate logging level to DEBUG - it should help you to narrow the problem.

ChssPly76