-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping a one-to-many relationship.
PostPosted: Thu May 19, 2011 1:29 am 
Newbie

Joined: Sat Jun 19, 2010 9:14 pm
Posts: 2
I have the following two database tables:

Create Cached Table Users (
Id Integer Generated By Default as Identity (Start With 1, Increment By 1) Primary Key,
Username VarChar(16) Default '' Not Null
);

Create Cached Table UserLogins (
Id Integer Generated By Default as Identity (Start With 1, Increment By 1) Primary Key,
UserId Integer Default 0 Not Null,
LoginTimestamp Timestamp Default Now Not Null,
IP VarChar(16) Default '' Not Null
);

I have the POJOs User and UserLogin.

I have the following Hibernate mappings:

<hibernate-mapping>
<class name="myapp.domain.entities.User" table="Users">
<id name="id" column="Id" access="field"><generator class="identity" /></id>
<property name="username" column="Username" not-null="true" length="16" />
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="myapp.domain.entities.UserLogin" table="UserLogins">
<id name="id" column="Id" access="field"><generator class="identity" /></id>
<property name="userId" column="UserId" not-null="true" />
<property name="loginTimestamp" column="LoginTimestamp" not-null="true" />
<property name="ip" column="IP" not-null="true" length="16" />
</hibernate-mapping>

Each User entity can reference 0..n UserLogin entities. Each UserLogin entity is referenced by exactly 1 User entity. What changes do I need to make to my xml mappings and my POJOs to configure a one-to-many relationship in Hibernate?

Cheers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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.