qrstvw
qrstvw

Reputation: 13

JPA/Hibernate Could not determine type

I am struggling with this problem for quite a long time now, i really hope i can find some help here.

I use a composite primary key class, AssociationKey, which is used by class Association. The id's in the key class are also custom classes. When i try to run the code i get the error message:

"Could not determine type for: IClassB, at table: Association, for columns: [org.hibernate.mapping.Column(ClassB)]"

I also tried to use ManyToOne and OneToMany annotations in Class Association and ClassB. But then i get the error that the tpyes are incorrect:

The attribute matching the ID class attribute ClassB does not have the correct type IClassB

Is it not possible to use a custom class as Id in a composite primary key?

@Entity
@IdClass(AssociationKey.class)
public class Association implements IAssociation {

    @Id
    private IClassA classA;
    @Id
    private IClassB classB;
    ...
}


public class AssociationKey implements IAssociationKey, Serializable {

    public IClassA classA;
    public IClassB classB;

    public boolean equals() {..}
    public int hashCode() {..}
}


@Entity
public class ClassB implements IClassA {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private List<IAssociation> associations;
}

Upvotes: 1

Views: 794

Answers (1)

ujulu
ujulu

Reputation: 3309

I think your problem lies in your primary key definition. Your compound primary key consists of custom Java classes. But the JPA specification states the following:

A simple primary key or a field or property of a composite primary key should be one of the following types: any Java primitive type; any primitive wrapper type; java.lang.String; java.util.Date; java.sql.Date; java.math.BigDecimal; java.math.BigInteger.

Upvotes: 1

Related Questions