Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Include both foreign key fields and relationships on pojo
PostPosted: Thu Dec 17, 2015 1:17 am 
Newbie

Joined: Thu Dec 17, 2015 1:11 am
Posts: 1
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.