Hi,
I am attempting to use annotations in my spring-hibernate application. I am having some difficulties with the primary key.
The problem is with the MyKey which represent the id of the object. The database field which is bankaccountID is of type int but i cant get it to retrieve the data, it fails with the following error.
Quote:
[JDBCExceptionReporter] Unknown column 'this_.primaryKey' in 'field list'
I have found that the problem is with
Code:
@Column(name = "BankAccountID")
public MyKey getPrimaryKey() {
return primaryKey;
}
Changing it so it uses int works.
Code:
@Column(name = "BankAccountID")
public Integer getPrimaryKey() {
return primaryKey;
}
I have enclosed the full code listing below.
The following is the Entity class
Code:
@SuppressWarnings("serial")
@Entity
@Table(name = "bankaccount")
public class BankTOAnonImpl implements Serializable {
MyKey primaryKey;
String description;
Date transactionDate;
public BankTOAnonImpl() {
}
@Column(name = "description")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Column(name = "transactionDate")
public Date getTransactionDate() {
return transactionDate;
}
public void setTransactionDate(Date transactionDate) {
this.transactionDate = transactionDate;
}
[b]
@Id
@Column(name = "BankAccountID")
public MyKey getPrimaryKey() {
return primaryKey;
}
[/b]
/**
* @param primaryKey the primaryKey to set
*/
public void setPrimaryKey(MyKey primaryKey) {
this.primaryKey = primaryKey;
}
}
The primary key object is defined as
Code:
@Embeddable
public class MyKey implements Serializable {
private int primaryKey;
/**
* @return the primaryKey
*/
public int getPrimaryKey() {
return primaryKey;
}
/**
* @param primaryKey the primaryKey to set
*/
public void setPrimaryKey(int primaryKey) {
this.primaryKey = primaryKey;
}
}
The hibernate config file mapping is specified as
<mapping class="MyKey"/>
<mapping class="BankTOAnonImpl"/>
Thanks in advance