I am using hibernate. When I try to insert values into my db I am getting error.
Here is the stack trace
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'postalCode' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
Here is a overview of my Pojo class
@Entity
public class HeadOffice implements java.io.Serializable
{
private Long officeId;
private String name;
private String addr1;
private String addr2;
private String postalCode;
private String country;
private String email;
private String tel1;
private String tel2;
public HeadOffice() { }
public String getPostalCode()
{
return this.postalCode;
}
public void setPostalCode(String postalCode)
{
this.postalCode = postalCode;
}
}
And this is the corresponding entry for the postal code property in the hbm.xml file
<property name="postalCode" type="string">
<column name="postal_code" length="24" not-null="true" />
</property>
during sql query exceqution the field name is taken as postalCode instead of postal_code
How can I correct this?
Thanks
You seem to be mixing up annotation-style configuration and XML-style configuration. While this is possible, it’s rarely the intention.
I suspect that your configuration is simply ignoring the
.hbm.xmlfile and taking the config from your annotated class instead.Try either:
@Entityfrom your class, or@Column(name="postal_code")to thegetPostalCode()method.