views:

174

answers:

1

I am using JPA annotations for these two classes:

@Entity
@RooJavaBean
@RooToString
@RooEntity
@MappedSuperclass
public abstract class BaseEntity {

  @Temporal(TemporalType.TIMESTAMP)
  @DateTimeFormat(style = "S-")
  private Calendar created;

  @Temporal(TemporalType.TIMESTAMP)
  @DateTimeFormat(style = "S-")
  private Calendar updated;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id")
  private Long id;

  @Version
  @Column(name = "version")
  protected Integer version;

  public Long getId() {
  return id;
  }

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

  public Integer getVersion() {
  return version;
  }

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

  @PrePersist
  protected void onCreate() {
  created = Calendar.getInstance();
  }

  @PreUpdate
  protected void onUpdate() {
  updated = Calendar.getInstance();
  }

}
@Entity
@RooJavaBean
@RooToString
@RooEntity
public class Event extends BaseEntity {

  private Score challenger;
  private Score defender;
  ...
}

@Entity
@RooJavaBean
@RooToString
@RooEntity
public class Score extends BaseEntity {

  @ManyToOne
  private Team team;
  private Event event;
  private Integer score;
  private Boolean accepted;
}

I get an exception though:

Caused by: org.hibernate.MappingException: Could not determine type for: edu.unlv.cs.ladders.entities.Score, at table: event, for columns: [org.hibernate.mapping.Column(challenger)]
 at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:269)
 at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
 at org.hibernate.mapping.Property.isValid(Property.java:185)
 at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
 at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
 at org.hibernate.cfg.Configuration.validate(Configuration.java:1108)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1293)
 at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
 at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)

Does this have to do with having two seperate fields that access the same class? Do I have to be more descriptive and specify column names or something? Any direction would be helpful. Thanks!

+2  A: 

You need to annotate the Score properties with ManyToOneor OneToOne.

Bozho
Thank you. I used OneToOne and it worked.
Matthew Sowders