Hibernate version: 3.x - JPA support
Mapping documents:
I'm wondering if someone could give me a little advice on this situation.
I have a table, Users, that I defined as the following in Java:
Code:
private Long id;
private String username;
private String password;
private Date creationDate;
private String emailAddress;
private List<SecurityGroup> securityGroups;
private List<UserProperty> userProperties;
private List<UserConnection> myConnections;
private List<UserConnection> joinConnections;
private Profile profile;
And the other relevant structure is the UserConnection class:
Code:
private Long id;
private Date createdOn;
private UserConnectionType connectionType;
private User initiatingUser;
private User targetUser;
What I'm trying to generate, as you can probably guess, is a left side/right side referencing structure for showing user to user relationships. I'm using initiating user and target user as a way to track who created the relationship (initiating user). It should also be usable in parent/child structure (ie a Mother has a child..)
so I tried decorating the code with the following JoinTable annotation. I'm generating the schema from the Hibernate mappings using hbm2ddl, so my assumption is that my annotations are correct as long as it creates the schema that I expect.
Code:
@JoinTable(name="users", joinColumns=@JoinColumn(name="initiating_user",referencedColumnName="id"))
What I'm essentially expecting is that no new column is added to the users table, and a FK is created from user_connections.initiating_user to users.id. Instead, I'm getting a new column in the users table, and no column in the user_connections table.
I'm not really sure what I'm doing wrong with my mapping, if anyone has any comments what I've done wrong it would help me quite a bit.
Thanks,
John