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.  [ 6 posts ] 
Author Message
 Post subject: Mapping a BigInt Id to a String based ObjectID-Class
PostPosted: Wed Nov 29, 2006 8:55 am 
Newbie

Joined: Tue May 31, 2005 12:44 pm
Posts: 11
Hibernate version: 3.2.0

Name and version of the database you are using: MySQL 5.5

Table Item
oid BigInt
name String
createdat Date

Class Item
ObjectID oid
String Name
Date createdat

Hello,

i searched the forum but could not find anything related to my problem. As you can see i have a table 'Item' that should be mapped to the class item.

My Problem is now that i have a BigInt in DataBase and a String based ID-Object in my Pojos. How can i map this Integer-ID to the string based ID without changing the ID-generation to assigned?
The 'String-based-ObjectID' may simply takes the toString() from the Long which would be ok, but i do want to have a String as ID, not a Long and i want Hibernate to generate these IDs.

Is there a way to keep this as is and use a Hibernate build in Generator-Stategy may be by subclassing a Generator to produce this ObjectID class?

Any help appreciated.
Thx Joe


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 10:39 am 
Beginner
Beginner

Joined: Tue Nov 21, 2006 5:18 am
Posts: 31
Location: Bangalore, India
Hi,

I think you can creat your own type and you can use it,


The better way is you use Long, other than this its not safe to use.

_________________
persist_coder
--credit please if it helps you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 11:18 am 
Newbie

Joined: Tue May 31, 2005 12:44 pm
Posts: 11
hello persist_coder,

can you show me what you mean. I don't know how how to do this. Is it simply writing a Class that gets as contructor-param the value of the PK-Long
or what do i have to do? Is there an Interface to implement?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 5:19 am 
Beginner
Beginner

Joined: Tue Nov 21, 2006 5:18 am
Posts: 31
Location: Bangalore, India
Hi,

You can write class which implements Serializable interface,

Override the methods hashCode and equals methods, create a default constructor and a constructor with a single param as String. Assign this string into instance variable id,
And one more method which returns this id;
This id can be String and set as private variable.

But this works only for varchar or varchar2 type of db, for number or bigint wont work.

_________________
persist_coder
--credit please if it helps you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 5:20 am 
Beginner
Beginner

Joined: Tue Nov 21, 2006 5:18 am
Posts: 31
Location: Bangalore, India
Hi,

You can write class which implements Serializable interface,

Override the methods hashCode and equals methods, create a default constructor and a constructor with a single param as String. Assign this string into instance variable id,
And one more method which returns this id;
This id can be String and set as private variable.

But this works only for varchar or varchar2 type of db, for number or bigint wont work.

_________________
persist_coder
--credit please if it helps you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 5:51 am 
Newbie

Joined: Tue May 31, 2005 12:44 pm
Posts: 11
Hi

Thanks for your help. Meanwhile i found a way to do do what i want and i think i didn't explain it very well. My problem was as follows. My collegue wrote an ObjectID - class which wraps the ID of the table as a String Literal to prohibit ID-manipulation and i was wondering how i can Access this with a Long value. Your idea is great and thank you for your help. But we do want to have a Long-value as Pk in the Database.
We now do the access using the org.hibernate.property.PropertyAccessor in the Mapping. It seems to work pretty well. I did not knew about this extended mapping possibilities.

Thx, Joe


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.