-->
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: org.hibernate.MappingException: could not instantiate id gen
PostPosted: Fri Jun 03, 2005 11:58 pm 
Newbie

Joined: Mon Feb 21, 2005 3:49 am
Posts: 15
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

had no clue what that mean "org.hibernate.MappingException: could not instantiate id gen"

Hibernate version: 3.0.5

Mapping documents:
////////////////////////////// Cat.hbm.xml //////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.cfreecom.club.model">
<class name="Cat" table="cat">
<id
column="cat_id"
name="id"
type="string"
>
<generator class="vm" />
</id>
<property
column="sex"
length="1"
name="sex"
not-null="false"
type="string"
/>
<property
column="name"
length="16"
name="name"
not-null="true"
type="string"
/>
<property
column="weight"
length="10"
name="weight"
not-null="false"
type="big_decimal"
/>
</class>
</hibernate-mapping>
//////////////////////////// hibernate.cfg.xml //////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- local connection properties -->
<property name="connection.url">
jdbc:mysql://localhost/club?useUnicode=true&amp;characterEncoding=utf8
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.username">club</property>
<property name="connection.password">club</property>

<!-- dialect for MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<!--property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property-->

<!--property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property-->
<!--property name="jta.UserTransaction">java:comp/UserTransaction</property-->

<!-- Use the C3P0 connection pool. -->
<!--property name="c3p0.min_size">2</property-->
<!--property name="c3p0.max_size">5</property-->
<!--property name="c3p0.timeout">900</property-->

<mapping resource="com/cfreecom/club/model/Cat.hbm.xml" />
<!--mapping resource="com/cfreecom/club/model/User.hbm.xml" /-->
<!--mapping resource="com/cfreecom/club/model/Role.hbm.xml" /-->
<!--mapping resource="com/cfreecom/club/model/Photo.hbm.xml" /-->
</session-factory>
</hibernate-configuration>


Code between sessionFactory.openSession() and session.close():
//////////////////////////// CatAction.java //////////////////////////////
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;

import com.cfreecom.club.util.*;
import com.cfreecom.club.model.*;
import com.cfreecom.club.model.dao.*;

public class CatAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

Log log = LogFactory.getLog(CatAction.class);

System.out.println("Hibernate - CatAction ...");

Session session = null;

try {
System.out.println("ActAction ... try ");

session = HibernateUtil.getSession();
System.out.println("HibernateUtil.getSession(): "+session.toString());
Transaction tx = session.beginTransaction();
System.out.println("Transaction: "+tx.toString());
// do your job here ...

Cat cat = new Cat();
cat.setId("Cat1");
cat.setName("Cat1");
cat.setWeight(new java.math.BigDecimal(7.4f));

session.save(cat, session);
System.out.println("session save ");
tx.commit();
System.out.println("trans commit ");

session.close();
} catch (HibernateException e) {
System.out.println("HibernateException: "+e.getMessage());
e.printStackTrace();
} finally {
if(session != null) {
try {
session.close();
System.out.println("session close ");
} catch (HibernateException e) {
System.out.println("HibernateException: "+e.getMessage());
e.printStackTrace();
}
}
}

return (mapping.getInputForward());
}

public void printCol(String str) {
System.out.print(str);
System.out.print(" | ");
}
}
////////////////////////////// HibernateUtil.java /////////////////////////////////
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.HibernateException;

public class HibernateUtil {

private static Log log = LogFactory.getLog(HibernateUtil.class);

private static SessionFactory sessionFactory = null;

static {
try {
/*
* Use the mappings and properties specified in
* an application resource named hibernate.cfg.xml.
*/
Configuration cfg = new Configuration();
sessionFactory = cfg.configure().buildSessionFactory();
System.out.println("HibernateUtil: "+sessionFactory.toString());
} catch (Throwable t) {
t.printStackTrace();
throw new ExceptionInInitializerError(t);
}

}

public static Session getSession() throws HibernateException {
return sessionFactory.openSession();
}
}
Full stack trace of any exception that occurs:

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

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Hibernate - CatAction ...
ActAction ... try
11:46:51,806 INFO Environment:464 - Hibernate 3.0.5
11:46:51,807 INFO Environment:477 - hibernate.properties not found
11:46:51,809 INFO Environment:510 - using CGLIB reflection optimizer
11:46:51,812 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
11:46:51,929 INFO Configuration:1110 - configuring from resource: /hibernate.cf g.xml
11:46:51,930 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.x ml
11:46:53,296 INFO Configuration:444 - Mapping resource: com/cfreecom/club/model /Cat.hbm.xml
11:46:55,391 INFO HbmBinder:260 - Mapping class: com.cfreecom.club.model.Cat -> cat
11:46:55,412 INFO Configuration:1222 - Configured SessionFactory: null
11:46:55,416 INFO Configuration:875 - processing extends queue
11:46:55,417 INFO Configuration:879 - processing collection mappings
11:46:55,423 INFO Configuration:888 - processing association property reference s
11:46:55,423 INFO Configuration:917 - processing foreign key constraints
11:46:55,528 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
11:46:55,528 INFO DriverManagerConnectionProvider:42 - Hibernate connection poo l size: 1
11:46:55,531 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
11:46:55,553 INFO DriverManagerConnectionProvider:80 - using driver: com.mysql. jdbc.Driver at URL: jdbc:mysql://localhost/club?useUnicode=true&characterEncodin g=utf8
11:46:55,554 INFO DriverManagerConnectionProvider:86 - connection properties: { user=club, password=****}
11:46:55,828 INFO SettingsFactory:77 - RDBMS: MySQL, version: 4.1.11-Debian_1-log
11:46:55,829 INFO SettingsFactory:78 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.8 ( $Date: 2005/04/14 20:36:13 $, $Revision: 1.27.4.64 $ )
11:46:55,867 INFO Dialect:92 - Using dialect: org.hibernate.dialect.MySQLDialect
11:46:55,876 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
11:46:55,879 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
11:46:55,883 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
11:46:55,887 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
11:46:55,887 INFO SettingsFactory:136 - JDBC batch size: 15
11:46:55,888 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled
11:46:55,889 INFO SettingsFactory:144 - Scrollable result sets: enabled
11:46:55,890 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): enabled
11:46:55,890 INFO SettingsFactory:160 - Connection release mode: null
11:46:55,896 INFO SettingsFactory:184 - Maximum outer join fetch depth: 2
11:46:55,897 INFO SettingsFactory:187 - Default batch fetch size: 1
11:46:55,897 INFO SettingsFactory:191 - Generate SQL with comments: disabled
11:46:55,898 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
11:46:55,898 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
11:46:55,903 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
11:46:55,904 INFO SettingsFactory:203 - Query language substitutions: {}
11:46:55,905 INFO SettingsFactory:209 - Second-level cache: disabled
11:46:55,905 INFO SettingsFactory:213 - Query cache: disabled
11:46:55,908 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
11:46:55,909 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
11:46:55,920 INFO SettingsFactory:257 - Echoing all SQL to stdout
11:46:55,925 INFO SettingsFactory:261 - Statistics: disabled
11:46:55,926 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled
11:46:55,927 INFO SettingsFactory:279 - Default entity-mode: pojo
11:46:56,248 INFO SessionFactoryImpl:152 - building session factory
org.hibernate.MappingException: could not instantiate id generator
at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:92)
at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:151)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:178)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
at com.cfreecom.club.util.HibernateUtil.<clinit>(HibernateUtil.java:24)
at com.cfreecom.club.action.CatAction.execute(CatAction.java:40)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.MappingException: could not interpret id generator strategy: vm
at org.hibernate.id.IdentifierGeneratorFactory.getIdentifierGeneratorClass(IdentifierGeneratorFactory.java:103)
at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:86)
... 35 more


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 6:19 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
<generator class="vm" />
vm is not a regular strategy nor a class implementing IdentifierGenerator

_________________
Emmanuel


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.