File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Mapping for id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Mapping for id " Watch "Hibernate Mapping for id " New topic
Author

Hibernate Mapping for id

Jayaraj Jaganathan
Ranch Hand

Joined: Jun 29, 2009
Posts: 70
I have configuration doubt in hibernate.

please look into my configuration


according to above configuration whenever i save CreditCard.java , next sequence id is generated
now , i tried to set id manually by setting



but still it generate next sequence id and getting saved.
please let me know how to configure it accordingly ?

thanks for all your help in advance...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What configuration do you want to use? You can either use a generator and delegate to something else to create an id or you can define the id as "assigned" and assign it yourself, you can't do both.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jayaraj Jaganathan
Ranch Hand

Joined: Jun 29, 2009
Posts: 70
Paul Sturrock wrote:What configuration do you want to use? You can either use a generator and delegate to something else to create an id or you can define the id as "assigned" and assign it yourself, you can't do both.


thanks for your reply

so i planned to have two hbm files
1. sequence
2. assigned

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Two mappings for the same entity so you can use two different id generation strategies? Why?
Jayaraj Jaganathan
Ranch Hand

Joined: Jun 29, 2009
Posts: 70
Paul Sturrock wrote:Two mappings for the same entity so you can use two different id generation strategies? Why?


its complected to explain, let me try

existing design (shopping cart)
-----------------
when user submit order we store client credit card information in database, here we no need to assign an id, so we used sequence

new requirement (new shopping cart)
--------------------
when user submit order we need to call fraud web service after that we store client credit card information in database,
here fraud web service need credit card id as the request, so we are going to use assigned


Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So, your CC fraud service needs the surrogate key of your credit card entity? Not sure I understand why; but I'll take your word for it (though if your CC fraud service returns a value with business meaning you probably don't want that as your key).

Sounds like you just can't use a generated key. I'd swap to assigned; its just asking for bugs to have two entities and calling different ones dependent on where in your code you persist.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Mapping for id