I'm using Java 7 and Hibernate 3.6.10.Final. Following code uses JPA annotations.
I'm working on refactoring a class to change its id from int to long. There are a ton of references and a complicated superclass hierarchy which can't be fixed at one shot. So I created a temporary getLongId method and deprecated existing getId method so that clients can make the transition.
Here's my parent class
public class Parent{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "PK_id")
public int getId() {
return id;
}
// ..
}
Here's the child class for which the id has to be updated to long.
public class ChildXyz extends Parent{
@Override
@Deprecated // more details in the description at the start of this question
public int getId() {
return super.getId();
}
}
Above code is resulting in
Caused by: java.sql.SQLException: Invalid column name 'id'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:3052)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2473)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:680)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:613)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:572)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:739)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:93)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:56)
... 48 more
Doesn't hibernate recognize the annotations from method in the superclass?
Repeating @Id, etc. annotations in the child class doesn't work as Hibernate gets confused.