-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to inexplicitly mapping identity column?
PostPosted: Wed Mar 14, 2007 2:43 pm 
Newbie

Joined: Wed Mar 14, 2007 2:14 pm
Posts: 8
Hi,
I am new to using Hibernate(v3.2.0) and try to find a fix for this mapping problem:

-Assuming a class Person with *only* a SSN field in it, along with a Person table with columns ID and SSN. ID column is the primary key, and SSN column is also unique.
-Assuming the class and table can NOT be changed, is there a way to create a mapping that inexplicitly populate the ID column in the Person table in this operation:

Person p = new Person();
p.setSSN('123-45-9999');
session.save(p)

Also when the object is fetched, the ID column is automatically ignored.

Your help is greatly appreciated!

-Herbert


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 4:22 pm 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Why don't you want to have an ID field in your Person table. The accessors for this field can be protected if you don't want it to be accessible from outside the class

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 5:21 pm 
Newbie

Joined: Wed Mar 14, 2007 2:14 pm
Posts: 8
I assume you mean an ID field in Person class. In my application, the Person class is a Legacy class and under different contexts it was mapped to different tables in different data bases where SSN is enough.
-Herbert


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 4:03 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
But if the ID attribute has protected setters, it would be invisible from outside the class.
In context where it is not required, it would not be assigned : where is the problem ?
I think JDO takes care of this kind of transparent ID but it has other drawbacks

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 10:30 am 
Newbie

Joined: Wed Mar 14, 2007 2:14 pm
Posts: 8
If there is no way to avoid addding the ID field, I will add it then. Even though I prefer not to do it to keep the class as "clean" as possible.
-Herbert


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.