-->
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: GenericGenerator strategy foreign in orm.xml - HELP- URGENT?
PostPosted: Mon Mar 28, 2011 2:20 am 
Newbie

Joined: Sat Feb 18, 2006 1:44 am
Posts: 15
Hi,

In my JPA code I am trying to avoid using the annotations and just managing the same mapping inside orm.xml.
This has been working very nicely.
But I dont know how to implement in one scenario - one is to one relationship where in second table the primary key id is to be same as the id of the parent table through the foreign key.

How do I bring in hibernate extensions when using only orm.xml. Is there any thing available so that one does not need to use the annotations and yet the hibernate extensions can be used.

For example -What do I do about org.hibernate.annotations.GenericGenerator in the xml?


Skipping additional details - one can do one to one bi-directional using following annotations- How do you do this same configuration using only orm.xml also shown below:

Parent entity:
Code:
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
@javax.persistence.Column(name = "id", unique = true, nullable = false)
public Integer getId()
{
   return this.id;
}


@javax.persistence.OneToOne(fetch =javax.persistence.FetchType.LAZY, mappedBy = "user")
public Address getAddress()
{
   return this.address;
}


One is to one child entity:

Code:
[b]@org.hibernate.annotations.GenericGenerator(name = "generator", strategy = "foreign", parameters = @org.hibernate.annotations.Parameter(name = "property", value = "user"))[/b]
@javax.persistence.Id
@javax.persistence.GeneratedValue(generator = "generator")
@javax.persistence.Column(name = "id", unique = true, nullable = false)
public int getId()
{
   return this.id;
}


@javax.persistence.OneToOne(fetch = javax.persistence.FetchType.LAZY)
@javax.persistence.PrimaryKeyJoinColumn
public User getUser() {
   return this.user;
}



How can I write this in orm.xml?
Code:

<entity class="User">
   .......      
   <attributes>
   <id name="id"><column name="id" unique="true" nullable="false"/><generated-value strategy="IDENTITY"/></id>
         
   ......
   <one-to-one fetch="LAZY" name="address" mapped-by="user" ></one-to-one>
   </attributes>
</entity>


<entity class="Address">
   .....
   <attributes>
   <id name="id"><column name="id" unique="true" nullable="false"/>
   <generated-value generator="generator"/>   
   </id>
   ....
   <one-to-one   name="user"><primary-key-join-column/></one-to-one>
   .....
   
   </attributes>
   </entity>





What do I do about org.hibernate.annotations.GenericGenerator in the xml?


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.