0

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.

phanin
  • 5,327
  • 5
  • 32
  • 50
  • 1
    I think the your entity `ChildXyz` is trying to map an `id` column, because there is a `getId()` method. Try to put `@Transient` in `getId()` of `ChildXyz`. – Dherik Mar 16 '16 at 03:00
  • Did you declared column named id in parent entity? you are trying to get id from parent and also define in child. make one of the id column in either parent or child transient. – Sai prateek Mar 16 '16 at 04:19
  • thanks guys. Would Hibernate recognize the annotations associated with Parent.getId() if I added @Transient to ChildXyz.getId()? – phanin Mar 16 '16 at 16:10

1 Answers1

0

Few references to help you out

Haripriya
  • 822
  • 1
  • 14
  • 27