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.
|