-->
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: net.sf.hibernate.MappingException: could not instantiate id
PostPosted: Tue Dec 14, 2004 4:31 am 
Newbie

Joined: Tue Dec 14, 2004 4:10 am
Posts: 2
I follows examples of :
http://www.hibernate.org.cn:8000/65.html
And just can't run with "net.sf.hibernate.MappingException: could not instantiate id generator", I search the web and google forum, and got no luck, I am new to hibernate and not know what 's going on, wish you
could help.


Hibernate version:
hibernate-2.1.7c

Mapping documents:
file:///C:/hibernate-mapping-2.0.dtd is extracted from hibernate-2.1.7c .zip released
---------------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"file:///C:/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.javamodel.hibernate.Person" table="person">
<id name="id">
<generator class="vm.long"/>
</id>
<property name="email"/>
<property name="name"/>
</class>

</hibernate-mapping>
<!-- parsed in 0ms -->
---------------------------------------------------------------------------------

Code between sessionFactory.openSession() and session.close():
---------------------------------------------------------------------------------
package com.javamodel.hibernate;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;

public class Example
{

private static SessionFactory _sessions = null;
private static Properties pops = new Properties();

static {
try
{

InputStream stream = Thread.currentThread().getContextClassLoader().getResource("hibernate.properties").openStream();//Example.class.getResourceAsStream("hibernate.properties");
try
{
pops.load(stream);
}
catch (IOException e1)
{
e1.printStackTrace();
}
Configuration cfg = new Configuration();
cfg.addClass(Person.class);
cfg.setProperties(pops);
_sessions = cfg.buildSessionFactory();
if (_sessions == null)
{
System.out.println("This _session is nULLL");
}
}
catch (MappingException e)
{
e.printStackTrace();
}
catch (HibernateException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}

}

public static void main(String[] args) throws HibernateException
{

Person person = new Person();
person.setName("smallduzi");
person.setEmail("smallduzi@sohu.com");

Session session = _sessions.openSession();

Transaction tx = null;
try
{
tx = session.beginTransaction();
session.save(person);
tx.commit();
}
catch (HibernateException he)
{
if (tx != null)
tx.rollback();
throw he;
}
finally
{
session.close();
}

}

}

---------------------------------------------------------------------------------

Full stack trace of any exception that occurs:
---------------------------------------------------------------------------------
net.sf.hibernate.MappingException: could not instantiate id generator
at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:82)
at net.sf.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:82)
at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:645)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:692)
at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:42)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:796)
at com.javamodel.hibernate.Example.<clinit>(Example.java:37)
Caused by: net.sf.hibernate.MappingException: Dialect does not support sequences
at net.sf.hibernate.dialect.Dialect.getSequenceNextValString(Dialect.java:327)
at net.sf.hibernate.id.SequenceGenerator.configure(SequenceGenerator.java:57)
at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:78)
... 7 more
java.lang.NullPointerException
at com.javamodel.hibernate.Example.main(Example.java:65)
Exception in thread "main"
---------------------------------------------------------------------------------

Name and version of the database you are using:
IBM DB2 with Websphere

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Thank you


Top
 Profile  
 
 Post subject: Sorry my mistake...........
PostPosted: Tue Dec 14, 2004 4:42 am 
Newbie

Joined: Tue Dec 14, 2004 4:10 am
Posts: 2
I change:

<id name="id">
<generator class="vm.long"/>
</id>
or
<id name="id">
<generator class="sequence"/>
</id>

in mapping file into:

<id name="id" type="string">
<generator class="vm"/>
</id>

and everything goes OK now.

Sorry but thank you.


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.