I'm trying to use hibernate tools in order to generate some POJOs from my database. Our goal is to create a highly maintainable solution. This means both automated code generation from the database at will as well as automated serialization with no maintenance. In order to achieve these goals, we want to include both foreign keys as well as the relationships they represent in our POJOs. For example:
Code:
public class User(){
private String name;
private Integer uid;
private Integer addressId;
private Address address;
}
Note that we have both a reference to the Address object as well as the addressId itself (the foreign key). This is what we want, but we can't figure out how to do it. By default hibernate seems to create the relationship "address" but it appears not to create the "addressId" field. We have discovered that certain modifications to our custom reverse engineering strategy (http://stackoverflow.com/questions/23739937/lazy-mapping-with-hibernate-tools) could result in showing foreign keys on the object. Unfortunately, if we do this, it does not show the relationships! We need both!
Does anyone know how we might go about auto generating code using hibernate tools which includes both the foreign key values and the relationships they represent on the pojo?