Hello everybody.
I have a number of POJOs auto-generated with the Hibernate reverse engineering feature. They look like:
Code:
package db;
/**
* Pojo generated by hbm2java
*/
public class Pojo implements java.io.Serializable
{
private int id;
public Pojo() {
}
public Pojo(int id) {
this.id = id;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
}
I need to do various things with some of these POJOs and thus created derived classes, such as:
Code:
package input;
public class Pojo extends db.Pojo
{
public Pojo()
{
// TODO Auto-generated constructor stub
super();
}
public void doSomething()
{}
}
At some point I need to store new instances of these POJOs using a Session object:
Quote:
input.Pojo pj = new input.Pojo();
pj.doSomething();
session.save((db.Pojo) pj);
Even though the POJO instance is being cast to the generated parent class, Hibernate gets upset and spits out the familiar exception:
Quote:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: input.Pojo
Naturally, I could created new methods in the generated POJOs, but I would prefer to leave them unchanged (particularly since the database is expected to evolve). Is it possible to avoid this exception? Say, by "forcing" Hibernate to recognise the cast? Or can this be achieved some other way?
Thank you.