CHAPTER 7 Advanced entity association mappings instead if you map with composite primary keys. In a JPA XML descriptor, a one-toone mapping looks like this: …
The JPA specification doesn t include a standardized method to deal with the problem of shared primary key generation, which means you re responsible for setting the identifier value of an Address instance correctly before you save it (to the identifier value of the linked User instance). Hibernate has an extension annotation for custom identifier generators which you can use with the Address entity (just like in XML): @Entity @Table(name = “ADDRESS”) public class Address { @Id @GeneratedValue(generator = “myForeignGenerator”) @org.hibernate.annotations.GenericGenerator( name = “myForeignGenerator”, strategy = “foreign”, parameters = @Parameter(name = “property”, value = “user”) ) @Column(name = “ADDRESS_ID”) private Long id; … private User user; } Shared primary key one-to-one associations aren t uncommon but are relatively rare. In many schemas, a to-one association is represented with a foreign key field and a unique constraint. 7.1.2 One-to-one foreign key associations Instead of sharing a primary key, two rows can have a foreign key relationship. One table has a foreign key column that references the primary key of the associated table. (The source and target of this foreign key constraint can even be the same table: This is called a self-referencing relationship.)
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.
This entry was posted
on Thursday, January 31st, 2008 at 9:12 am and is filed under PHP5.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.