-->
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: Custom Identifiers
PostPosted: Wed Jan 09, 2008 10:44 am 
Newbie

Joined: Tue Dec 18, 2007 9:15 am
Posts: 14
I am implementing IdentifierGenerator interface for custom identifiers.

When I execute the main class at first time (database is clear, no objects, and execute DDL). The CreateID class generate IDs as well.

When I execute again the main class (without drop database tables and maintainning rows) the application raise up error saying duplicade keys were generated and tried to be commited.

But when I see all keys generated all keys are completally differents at runtime and at database, I cannot understand why app throws this exception.

Thanks all!

Code:
import java.io.Serializable;
import java.util.Random;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.IdentifierGenerator;

/**
*
* @date 09/01/2008
* @since 1.0
* @version 1.0
* por InocĂȘncio T. de Oliveira
*/
public class CreateID implements IdentifierGenerator {
   
    public Serializable generate(SessionImplementor pSession, Object pObj) throws HibernateException {
       
        Serializable lPkValue = null;
        Long lId = 0l;
        String lTemp = "";
       
        if (JPASyncUtil.getMode() == JPASyncUtil.DB_STATUS_DEFAULT) {
           
            //temporariamente usada
            lTemp = String.valueOf((Math.abs(new Random().nextInt())) / 1000) +
                    String.valueOf(new java.util.Date().getTime() / 100);
           
            lId = Long.valueOf(lTemp);
           
            lPkValue = lId;
           
        }
        return lPkValue;
    }

}


Erro:

Code:
Caused by: java.sql.SQLException: Violation of UNIQUE KEY constraint 'UQ__ADT_AUDITORIA__7D39791C'. Cannot insert duplicate key in object 'ADT_AUDITORIA'.

_________________
-= DUNKELHEIT =-


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.