-->
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.  [ 3 posts ] 
Author Message
 Post subject: unable to generate identifier using custom generator
PostPosted: Wed Feb 14, 2007 8:40 am 
Newbie

Joined: Wed Feb 14, 2007 8:36 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject: Re: unable to generate identifier using custom generator
PostPosted: Wed Feb 14, 2007 8:42 am 
Newbie

Joined: Wed Feb 14, 2007 8:36 am
Posts: 3
[quote="jitendra_agrawal"]Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

public class GeneratedIdentifierGenerator implements IdentifierGenerator, Configurable
{

public GeneratedIdentifierGenerator()
{
super();
}

/**
* The delegate parameter specifies the underlying ID generator to use.
*/
public static final String DELEGATE = "delegate";

private IdentifierGenerator assignedGenerator;
private IdentifierGenerator delegateGenerator;

public Serializable generate(SessionImplementor session, Object object) throws HibernateException, SQLException {
AbstractDomainObject abstractDomainObject = (AbstractDomainObject) object;
if (abstractDomainObject.getId() != null) {
return assignedGenerator.generate(session, object);
} else {
return delegateGenerator.generate(session, object);
}
}

public void configure(Type type, Properties params, Dialect d) throws MappingException {
String generatorName = params.getProperty(DELEGATE);
if (generatorName == null) throw new MappingException("param named "delegate" is required for object generation strategy");

// Create the delegate and assigned ID generators
delegateGenerator = IdentifierGeneratorFactory.create(generatorName, type, params, d);
assignedGenerator = IdentifierGeneratorFactory.create("assigned", type, params, d);
}
}


Top
 Profile  
 
 Post subject: Re: unable to generate identifier using custom generator
PostPosted: Wed Feb 14, 2007 8:49 am 
Newbie

Joined: Wed Feb 14, 2007 8:36 am
Posts: 3
I am using mysql 4.0. If I set the identifier to the object, then it is working fine. In this case, it is creating an instance of AssignedGenerator and returns proper identifier which was set earlier. But when I do not set any identifier, then in this case it is creating an instance of IdentityGenerator, but return null or empty string instead of proper identifier.

Following is mapping in hbm.

<id name="id"
column="IDENTIFIER"
type="long"
length="30"
unsaved-value="null"
>
<generator class="edu.wustl.catissuecore.test.GeneratedIdentifierGenerator">
<param name="delegate">native</param>
<param name="sequence">CATISSUE_DEPARTMENT_SEQ</param>
</generator>
</id>


Can somebody help me out?


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