I'm sorry for the lenghtly post, but I think i would clear things up
I'm using a foreign id generator but I'm experiencing problems. I'm getting the following exception: could not instantiate id generator.
Here's my mapping file:
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="epe.beans">
<class name="CuentaDeUsuario" table="USUARIOS">
<id name="idCuenta" type="string" unsaved-value="null">
<column name="ID" sql-type="varchar(32)" not-null="true" />
<generator class="foreign">
<param name="codigo">solicitante</param>
</generator>
</id>
<discriminator column="tipo" type="string" force="true" />
<property name="login">
<column name="LOGIN" sql-type="varchar(30)" not-null="true"/>
</property>
<property name="password">
<column name="PASSWORD" sql-type="varchar(30)" not-null="true"/>
</property>
<one-to-one name="solicitante" class="Solicitante" constrained="true" />
<subclass name="CuentaDeUsuarioImpl" />
</class>
</hibernate-mapping>
I checked the hibernate code in IdentifierGeneratorFactory and the code goes like this:
Code:
...
static {
GENERATORS.put("uuid.hex", UUIDHexGenerator.class);
GENERATORS.put("uuid.string", UUIDStringGenerator.class);
GENERATORS.put("hilo", TableHiLoGenerator.class);
GENERATORS.put("assigned", Assigned.class);
GENERATORS.put("identity", IdentityGenerator.class);
GENERATORS.put("sequence", SequenceGenerator.class);
GENERATORS.put("seqhilo", SequenceHiLoGenerator.class);
GENERATORS.put("vm", IncrementGenerator.class); //vm is deprecated
GENERATORS.put("increment", IncrementGenerator.class);
GENERATORS.put("foreign", ForeignGenerator.class);
}
...
public static IdentifierGenerator create(String strategy, Type type, Properties params, Dialect dialect) throws MappingException {
try {
//if ( "vm".equals(strategy) ) log.info("'vm' strategy is deprecated; use 'increment'");
Class clazz = (Class) GENERATORS.get(strategy);
if ( "native".equals(strategy) ) {
if ( dialect.supportsIdentityColumns() ) {
clazz = IdentityGenerator.class;
}
else if ( dialect.supportsSequences() ) {
clazz = SequenceGenerator.class;
}
else {
clazz = TableHiLoGenerator.class;
}
}
if (clazz==null) clazz = ReflectHelper.classForName(strategy);
IdentifierGenerator idgen = (IdentifierGenerator) clazz.newInstance();
if (idgen instanceof Configurable) ( (Configurable) idgen).configure(type, params, dialect);
return idgen;
}
catch (Exception e) {
throw new MappingException("could not instantiate id generator", e);
}
..
So, it appears to me that the strategy parameter is comming null even with the mapping file specifying <generator class="foreign">. I've also tried with <generator class="" net.sf.hibernate.id.ForeignGenerator> with the same result.
This is the full log
Code:
11:11:59,937 INFO Environment:432 - Hibernate 2.1.1
11:11:59,953 INFO Environment:461 - hibernate.properties not found
11:11:59,953 INFO Environment:481 - using CGLIB reflection optimizer
11:11:59,968 INFO Configuration:843 - configuring from resource: /hibernate.cfg.xml
11:11:59,968 INFO Configuration:815 - Configuration resource: /hibernate.cfg.xml
11:12:00,078 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd in classpath under net/sf/hibernate/
11:12:00,078 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd in classpath
11:12:00,140 DEBUG Configuration:801 - connection.datasource=java:comp/env/jdbc/epeDS
11:12:00,140 DEBUG Configuration:801 - show_sql=false
11:12:00,140 DEBUG Configuration:801 - dialect=net.sf.hibernate.dialect.MySQLDialect
11:12:00,140 DEBUG Configuration:801 - transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory
11:12:00,140 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@74f02c [Attribute: name resource value "Solicitante.hbm.xml"]
11:12:00,140 INFO Configuration:300 - Mapping resource: Solicitante.hbm.xml
11:12:00,140 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under net/sf/hibernate/
11:12:00,156 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath
11:12:00,328 INFO Binder:225 - Mapping class: epe.beans.Solicitante -> SOLICITANTES
11:12:00,500 DEBUG Binder:449 - Mapped property: codigo -> CODIGO, type: string
11:12:00,546 DEBUG Binder:449 - Mapped property: primerNombre -> NOMBRE1, type: string
11:12:00,546 DEBUG Binder:449 - Mapped property: segundoNombre -> NOMBRE2, type: string
11:12:00,546 DEBUG Binder:449 - Mapped property: primerApellido -> APELLIDO1, type: string
11:12:00,562 DEBUG Binder:449 - Mapped property: segundoApellido -> APELLIDO2, type: string
11:12:00,562 DEBUG Binder:449 - Mapped property: telefono -> TELEFONO, type: string
11:12:00,562 DEBUG Binder:449 - Mapped property: email -> EMAIL, type: string
11:12:00,562 DEBUG Binder:449 - Mapped property: direccionPostal -> DIRECCION_POSTAL, type: string
11:12:00,562 DEBUG Binder:449 - Mapped property: nombreOrganizacion -> NOMBRE_ORG, type: string
11:12:00,562 DEBUG Binder:449 - Mapped property: direccionOrganizacion -> DIRECCION_ORG, type: string
11:12:00,562 DEBUG Binder:449 - Mapped property: sectorEconomico -> SECTOR_ORG, type: string
11:12:00,593 DEBUG Binder:449 - Mapped property: requerimientos, type: java.util.Set
11:12:00,609 DEBUG Binder:449 - Mapped property: cuentaDeUsuario, type: epe.beans.CuentaDeUsuario
11:12:00,703 INFO Binder:169 - Mapping subclass: epe.beans.SolicitanteImpl -> SOLICITANTES
11:12:00,703 DEBUG Binder:1228 - Named query: epe.beans.Solicitante.ListarTodos -> from epe.beans.SolicitanteImpl
11:12:00,703 DEBUG Binder:1228 - Named query: epe.beans.Solicitante.ContarTodos -> select count(*) from epe.beans.SolicitanteImpl
11:12:00,703 DEBUG Binder:1228 - Named query: epe.beans.Solicitante.BuscarPorCodigo -> from epe.beans.SolicitanteImpl where codigo=?
11:12:00,703 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@1402c4 [Attribute: name resource value "CuentaDeUsuario.hbm.xml"]
11:12:00,703 INFO Configuration:300 - Mapping resource: CuentaDeUsuario.hbm.xml
11:12:00,703 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under net/sf/hibernate/
11:12:00,718 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath
11:12:00,734 INFO Binder:225 - Mapping class: epe.beans.CuentaDeUsuario -> USUARIOS
11:12:00,734 DEBUG Binder:449 - Mapped property: idCuenta -> ID, type: string
11:12:00,734 DEBUG Binder:449 - Mapped property: login -> LOGIN, type: string
11:12:00,734 DEBUG Binder:449 - Mapped property: password -> PASSWORD, type: string
11:12:00,734 DEBUG Binder:449 - Mapped property: solicitante, type: epe.beans.Solicitante
11:12:00,734 INFO Binder:169 - Mapping subclass: epe.beans.CuentaDeUsuarioImpl -> USUARIOS
11:12:00,734 DEBUG Binder:1228 - Named query: epe.beans.CuentaDeUsuario.ListarTodos -> from epe.beans.CuentaDeUsuarioImpl
11:12:00,734 DEBUG Binder:1228 - Named query: epe.beans.CuentaDeUsuario.ContarTodos -> select count(*) from epe.beans.CuentaDeUsuarioImpl
11:12:00,734 DEBUG Binder:1228 - Named query: epe.beans.CuentaDeUsuario.BuscarPorLogin -> from epe.beans.CuentaDeUsuarioImpl where login=?
11:12:00,734 DEBUG Binder:1228 - Named query: epe.beans.CuentaDeUsuario.ValidarLogin -> from epe.beans.CuentaDeUsuario where login=? and password=?
11:12:00,750 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@63e563 [Attribute: name resource value "RequerimientoEvaluacion.hbm.xml"]
11:12:00,750 INFO Configuration:300 - Mapping resource: RequerimientoEvaluacion.hbm.xml
11:12:00,750 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under net/sf/hibernate/
11:12:00,765 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath
11:12:00,781 INFO Binder:225 - Mapping class: epe.beans.RequerimientoEvaluacion -> REQS_EVALUACION
11:12:00,781 DEBUG Binder:449 - Mapped property: codigo -> CODIGO, type: string
11:12:00,781 DEBUG Binder:449 - Mapped property: fecha -> FECHA, type: timestamp
11:12:00,781 DEBUG Binder:449 - Mapped property: objetivo -> OBJETIVO_GENERAL, type: string
11:12:00,796 DEBUG Binder:449 - Mapped property: solicitante -> cdsolicitante, type: epe.beans.Solicitante
11:12:00,796 INFO Binder:169 - Mapping subclass: epe.beans.RequerimientoEvaluacionImpl -> REQS_EVALUACION
11:12:00,796 INFO Configuration:998 - Configured SessionFactory: null
11:12:00,796 DEBUG Configuration:999 - properties: {java.vendor=Sun Microsystems Inc., show_sql=false, oracle.j2ee.container.version=9.0.4.0.0, connection.datasource=java:comp/env/jdbc/epeDS, oracle.jms.j2eeCompliant=true, os.name=Windows 2000, sun.boot.class.path=c:\jdk1.4.0\jre\lib\rt.jar;c:\jdk1.4.0\jre\lib\i18n.jar;c:\jdk1.4.0\jre\lib\sunrsasign.jar;c:\jdk1.4.0\jre\lib\jsse.jar;c:\jdk1.4.0\jre\lib\jce.jar;c:\jdk1.4.0\jre\lib\charsets.jar;c:\jdk1.4.0\jre\classes, oracle.xdkjava.compatibility.version=9.0.3, sun.java2d.fontpath=, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.4.0-b92, user.name=andrbube, user.language=es, java.naming.factory.initial=com.evermind.server.ApplicationInitialContextFactory, sun.boot.library.path=c:\jdk1.4.0\jre\bin, dialect=net.sf.hibernate.dialect.MySQLDialect, java.version=1.4.0, user.timezone=GMT-05:00, java.net.preferIPv4Stack=true, sun.arch.data.model=32, java.endorsed.dirs=c:\jdk1.4.0\jre\lib\endorsed, sun.cpu.isalist=pentium i486 i386, file.encoding.pkg=sun.io, file.separator=\, java.specification.name=Java Platform API Specification, oracle.jms.stronglyTypedSelectors=true, hibernate.cglib.use_reflection_optimizer=true, java.class.version=48.0, user.country=CO, java.home=c:\jdk1.4.0\jre, java.vm.info=mixed mode, os.version=5.0, transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, hibernate.connection.datasource=java:comp/env/jdbc/epeDS, path.separator=;, java.vm.version=1.4.0-b92, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, user.variant=, java.protocol.handler.pkgs=com.evermind.protocol, java.awt.printerjob=sun.awt.windows.WPrinterJob, sun.io.unicode.encoding=UnicodeLittle, awt.toolkit=sun.awt.windows.WToolkit, user.home=C:\Documents and Settings\andrbube, java.specification.vendor=Sun Microsystems Inc., oracle.dms.sensors=5, java.library.path=c:\jdk1.4.0\bin;.;C:\WINNT\system32;C:\WINNT;c:\jdk1.4.0\bin;C:\FORMS6I\bin;c:\ids\bin;c:\ids\jdk\jre\bin\classic;c:\ids\jdk\jre\bin;c:\ids\jlib;C:\Archivos de programa\Oracle\jre\1.1.8\bin;C:\Archivos de programa\Oracle\jre\1.3.1\bin;C:\pb8ent\Jaguar CTS 3.5\client\dll;C:\pb8ent\Shared\PowerBuilder;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\WINNT\system32\nls;C:\WINNT\system32\nls\English;C:\FORMS6I\jdk\bin;C:\pb8ent\SQL Anywhere 7\win32;C:\pb8ent\Shared\win32;C:\pb8ent\Shared\Web Targets;C:\Archivos de programa\Novell\ZENworks\;D:\cvs;C:\des_817\bin;;C:\Archivos de programa\rksupport;Z:.;, java.vendor.url=http://java.sun.com/, java.vm.vendor=Sun Microsystems Inc., hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, oracle.jdbc.J2EE13Compliant=true, java.class.path=oc4j.jar, oracle.j2ee.home=D:\oc4j_10g\j2ee\home, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, sun.cpu.endian=little, oracle.j2ee.container.name=Oracle Application Server Containers for J2EE 10g (9.0.4.0.0), sun.os.patch.level=Service Pack 4, oracle.vector.deepCopy=false, java.io.tmpdir=C:\DOCUME~1\andrbube\CONFIG~1\Temp\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, os.arch=x86, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.ext.dirs=c:\jdk1.4.0\jre\lib\ext, user.dir=D:\oc4j_10g\j2ee\home, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, javax.management.builder.initial=oracle.oc4j.admin.jmx.server.Oc4jMBeanServerBuilder, file.encoding=Cp1252, java.specification.version=1.4, hibernate.show_sql=false}
11:12:00,796 INFO Configuration:584 - processing one-to-many association mappings
11:12:00,796 DEBUG Binder:1301 - Second pass for collection: epe.beans.Solicitante.requerimientos
11:12:00,796 INFO Binder:1139 - Mapping collection: epe.beans.Solicitante.requerimientos -> REQS_EVALUACION
11:12:00,796 DEBUG Binder:1316 - Mapped collection key: cdsolicitante, one-to-many: epe.beans.RequerimientoEvaluacion
11:12:00,796 INFO Configuration:593 - processing one-to-one association property references
11:12:00,796 INFO Configuration:618 - processing foreign key constraints
11:12:00,796 DEBUG Configuration:628 - resolving reference to class: epe.beans.Solicitante
11:12:00,796 DEBUG Configuration:628 - resolving reference to class: epe.beans.Solicitante
11:12:00,843 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
11:12:00,843 INFO SettingsFactory:62 - Use outer join fetching: true
11:12:00,859 INFO NamingHelper:26 - JNDI InitialContext properties:{}
11:12:00,875 INFO DatasourceConnectionProvider:51 - Using datasource: java:comp/env/jdbc/epeDS
11:12:00,875 INFO TransactionFactoryFactory:31 - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
11:12:00,890 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
11:12:00,890 INFO SettingsFactory:89 - Use scrollable result sets: true
11:12:00,890 INFO SettingsFactory:90 - JDBC 2 max batch size: 15
11:12:00,906 INFO SettingsFactory:99 - Query language substitutions: {}
11:12:00,906 INFO SettingsFactory:110 - cache provider: net.sf.ehcache.hibernate.Provider
11:12:00,906 INFO Configuration:1057 - instantiating and configuring caches
11:12:01,140 INFO SessionFactoryImpl:119 - building session factory
11:12:01,140 DEBUG SessionFactoryImpl:125 - instantiating session factory with properties: {java.vendor=Sun Microsystems Inc., show_sql=false, oracle.j2ee.container.version=9.0.4.0.0, connection.datasource=java:comp/env/jdbc/epeDS, oracle.jms.j2eeCompliant=true, os.name=Windows 2000, sun.boot.class.path=c:\jdk1.4.0\jre\lib\rt.jar;c:\jdk1.4.0\jre\lib\i18n.jar;c:\jdk1.4.0\jre\lib\sunrsasign.jar;c:\jdk1.4.0\jre\lib\jsse.jar;c:\jdk1.4.0\jre\lib\jce.jar;c:\jdk1.4.0\jre\lib\charsets.jar;c:\jdk1.4.0\jre\classes, oracle.xdkjava.compatibility.version=9.0.3, sun.java2d.fontpath=, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.4.0-b92, user.name=andrbube, user.language=es, java.naming.factory.initial=com.evermind.server.ApplicationInitialContextFactory, sun.boot.library.path=c:\jdk1.4.0\jre\bin, dialect=net.sf.hibernate.dialect.MySQLDialect, java.version=1.4.0, user.timezone=GMT-05:00, java.net.preferIPv4Stack=true, sun.arch.data.model=32, java.endorsed.dirs=c:\jdk1.4.0\jre\lib\endorsed, sun.cpu.isalist=pentium i486 i386, file.encoding.pkg=sun.io, file.separator=\, java.specification.name=Java Platform API Specification, oracle.jms.stronglyTypedSelectors=true, hibernate.cglib.use_reflection_optimizer=true, java.class.version=48.0, user.country=CO, java.home=c:\jdk1.4.0\jre, java.vm.info=mixed mode, os.version=5.0, transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, hibernate.connection.datasource=java:comp/env/jdbc/epeDS, path.separator=;, java.vm.version=1.4.0-b92, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, user.variant=, java.protocol.handler.pkgs=com.evermind.protocol, java.awt.printerjob=sun.awt.windows.WPrinterJob, sun.io.unicode.encoding=UnicodeLittle, awt.toolkit=sun.awt.windows.WToolkit, user.home=C:\Documents and Settings\andrbube, java.specification.vendor=Sun Microsystems Inc., oracle.dms.sensors=5, java.library.path=c:\jdk1.4.0\bin;.;C:\WINNT\system32;C:\WINNT;c:\jdk1.4.0\bin;C:\FORMS6I\bin;c:\ids\bin;c:\ids\jdk\jre\bin\classic;c:\ids\jdk\jre\bin;c:\ids\jlib;C:\Archivos de programa\Oracle\jre\1.1.8\bin;C:\Archivos de programa\Oracle\jre\1.3.1\bin;C:\pb8ent\Jaguar CTS 3.5\client\dll;C:\pb8ent\Shared\PowerBuilder;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\WINNT\system32\nls;C:\WINNT\system32\nls\English;C:\FORMS6I\jdk\bin;C:\pb8ent\SQL Anywhere 7\win32;C:\pb8ent\Shared\win32;C:\pb8ent\Shared\Web Targets;C:\Archivos de programa\Novell\ZENworks\;D:\cvs;C:\des_817\bin;;C:\Archivos de programa\rksupport;Z:.;, java.vendor.url=http://java.sun.com/, java.vm.vendor=Sun Microsystems Inc., hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, oracle.jdbc.J2EE13Compliant=true, java.class.path=oc4j.jar, oracle.j2ee.home=D:\oc4j_10g\j2ee\home, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, sun.cpu.endian=little, oracle.j2ee.container.name=Oracle Application Server Containers for J2EE 10g (9.0.4.0.0), sun.os.patch.level=Service Pack 4, oracle.vector.deepCopy=false, java.io.tmpdir=C:\DOCUME~1\andrbube\CONFIG~1\Temp\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, os.arch=x86, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.ext.dirs=c:\jdk1.4.0\jre\lib\ext, user.dir=D:\oc4j_10g\j2ee\home, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, javax.management.builder.initial=oracle.oc4j.admin.jmx.server.Oc4jMBeanServerBuilder, file.encoding=Cp1252, java.specification.version=1.4, hibernate.show_sql=false}
[/quote]