-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate table design
PostPosted: Wed Jan 07, 2009 9:43 am 
Newbie

Joined: Wed Jan 07, 2009 9:22 am
Posts: 1
Hi,

I am new to hibernate and I am migrating a custom mysql-application to hibernate.

I have a Table called SHA1Table (which is used for storing vast amounts of SHA1 hashes). The custom SQL statement for creating this table is:
CREATE TABLE SHA1Table ( SHA1ID integer AUTO_INCREMENT, SHA1VAL VARCHAR (40) not null, PRIMARY KEY (SHA1ID), UNIQUE INDEX (SHA1VAL(40)))

Using Hibernate I created the class
<class name="events.SHA1Hash" table="SHA1Table">
<id name="id" column="HASH_ID">
<generator class="native"/>
</id>
<property name="hashvalue" unique="true"/>
</class>

As the hashvalue is unique, I'd like to insert a hashvalue only if it's different from the existing ones.

SHA1Hash theHash = new SHA1Hash();
theHash.setHashvalue(hashvalue);
session.save(theHash);

This clearly fails if an entry is saved a second time, because the unique constraint is violated.

Is the correct way to insert the newly created "theHash" into the database by first querying whether the value "hashvalue" is already present in SHA1Hash and then to decide upon the result whether to insert or not? If yes this is a problem as I have to insert at least 46000000 entries.

It would be a nice feature to have the database do this and just return a SHA1ID (i.e. to have the database ensure that there is a certain hash entry stored and assigned an ID).

Jasper


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 10:14 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
u may use DB based hash algorithm with triggers. i.e., that means write trigger that monitors hashValue if it is unique from others or not, if it's value already present call ur hash algorithm and save that value.

Or u may be use own/pre-defined generator for hashValue column.

_________________
If u feel it will help you, don't forget to rate me....


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