Hi,
I have a class with a composite primary key that I want to map in a manytomany association. Before I had only a single primary key and everything was fine. Now I get a MappingException:
Code:
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Area, for columns: [org.hibernate.mapping.Column(belongsTo)]
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:435)
at org.hibernate.mapping.JoinedSubclass.validate(JoinedSubclass.java:40)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1112)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1297)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:854)
at de.iac_leipzig.alkis.persistence.HibernateInheritanceTest.main(HibernateInheritanceTest.java:66)
Area extends the class Versioned which includes the composite primary key VersionedPK:
Code:
@MappedSuperclass
public abstract class Versioned implements JDBCPersistable {
@Embeddable
public static class VersionedPK implements Serializable {
private static final long serialVersionUID = 1L;
protected String guid = GUIDGenerator.newGUID();
protected String branch_ID;
protected Date valid_from;
@Override
public String toString() {
return guid + branch_ID + valid_from.toString();
}
public String getBranch_ID() {
return branch_ID;
}
void setBranch_ID( String branch_ID ) {
this.branch_ID = branch_ID;
}
public Date getValid_from() {
return valid_from;
}
public void setValid_from( Date valid_from ) {
this.valid_from = valid_from;
}
public boolean equals( Object o ) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
VersionedPK that = (VersionedPK) o;
if (valid_from != null ? !valid_from.equals( that.valid_from )
: that.valid_from != null)
return false;
if (branch_ID != null ? !branch_ID.equals( that.branch_ID )
: that.branch_ID != null)
return false;
if (this.guid != null ? !this.guid.equals( that.guid )
: that.guid != null)
return false;
return true;
}
public int hashCode() {
int result;
result = (valid_from != null ? valid_from.hashCode() : 0);
result = 31 * result
+ (branch_ID != null ? branch_ID.hashCode() : 0);
result = 17 * result + (guid != null ? guid.hashCode() : 0);
return result;
}
}
public static final String PROP_ID = "id";
@EmbeddedId
VersionedPK id = new VersionedPK();
@Transient
public String getId() {
return id.toString();
}
public void setId( VersionedPK id ) {
this.id = id;
}
public void setId( String id ) {
this.id.guid = id;
}
private Date valid_until;
private String author_from;
private String author_until;
private String externalId = null;
public Date getValid_until() {
return valid_until;
}
public void setValid_until( Date valid_until ) {
this.valid_until = valid_until;
}
public String getAuthor_from() {
return author_from;
}
public void setAuthor_from( String author_from ) {
this.author_from = author_from;
}
public String getAuthor_until() {
return author_until;
}
public void setAuthor_until( String author_until ) {
this.author_until = author_until;
}
public void insert( JDBCPersister persister ) throws Exception {
}
public String getExternalId() {
return externalId;
}
public void setExternalId( String externalId ) {
this.externalId = externalId;
}
}
The offending class "Area" is similar to this:
Code:
@Entity
public class Area
extends Versioned
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public static final String PROP_BELONGS_TO = "belongsTo";
private java.util.Set<Area> belongsTo = new java.util.HashSet<Area>();
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "Area_belongsTo")
public java.util.Set<Area> getBelongsTo() {
return belongsTo;
}
public void setBelongsTo(
java.util.Set<Area> belongsTo) {
this.belongsTo = belongsTo;
}
Thans a lot for any comments