Hi
I've got a problem when I'm trying to use the lazy property fetching.
Here is what I'm doing:
I've enhanced the Product class which I want to use and then, I try to test it. The problem is that the Configuration can't create any SessionFactory.
If I delete the lazy attribute in the mapping file or if I don't enhance the class, no exceptions are raised.
Thus I'm asking some help...
Hibernate version: 3.0 alpha
The exception happen when I'm creating the sessionFactory:
Configuration cfg = new Configuration()
.addClass(Product.class);
SessionFactory sf = cfg.buildSessionFactory();
Mapping documents:
Product
class:
package fr.digimind.jdo.hibernate;
public class Product {
private String id;
private String name;
private double price;
private int amount;
public int getAmount() {return amount;}
public String getId() {return id;}
public String getName() {return name;}
public double getPrice() {return price;}
public void setAmount(int i) {amount = i;}
public void setId(String string) {id = string;}
public void setName(String string) {name = string;}
public void setPrice(double d) {price = d;}
}
mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="fr.digimind.jdo.hibernate">
<class name="Product" table="products">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name" not-null="true" lazy="true"/>
<property name="price" not-null="false"/>
<property name="amount" not-null="false"/>
</class>
</hibernate-mapping>
Name and version of the database you are using:MS SQL 8.0
Debug level Hibernate log excerpt:
16:41:01,788 INFO [Environment] Hibernate 3.0 alpha
16:41:01,834 INFO [Environment] loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.microsoft.jdbc.sqlserver.SQLServerDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.SQLServerDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sa, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:microsoft:sqlserver://sumatra:1433;DatabaseName=Test_Hibernate;SelectMethod=Cursor, hibernate.connection.password=hu8ilmcp, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
16:41:01,834 INFO [Environment] using java.io streams to persist binary types
16:41:01,849 INFO [Environment] using CGLIB reflection optimizer
16:41:01,849 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
16:41:02,140 INFO [Configuration] Mapping resource: fr/digimind/jdo/hibernate/Product.hbm.xml
16:41:03,515 DEBUG [DTDEntityResolver] trying to locate
http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate/
16:41:03,531 DEBUG [DTDEntityResolver] found
http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
16:41:04,050 INFO [Binder] Mapping class: fr.digimind.jdo.hibernate.Product -> products
16:41:04,096 DEBUG [Binder] Mapped property: id -> id
16:41:04,218 DEBUG [Binder] Mapped property: name -> name
16:41:04,218 DEBUG [Binder] Mapped property: price -> price
16:41:04,218 DEBUG [Binder] Mapped property: amount -> amount
16:41:04,218 DEBUG [Configuration] Preparing to build session factory with filters : {}
16:41:04,218 INFO [Configuration] processing one-to-many association mappings
16:41:04,218 INFO [Configuration] processing one-to-one association property references
16:41:04,218 INFO [Configuration] processing foreign key constraints
16:41:04,524 INFO [Dialect] Using dialect: org.hibernate.dialect.SQLServerDialect
16:41:04,539 INFO [SettingsFactory] Maximum outer join fetch depth: 1
16:41:04,539 INFO [SettingsFactory] Generate SQL with comments: disabled
16:41:04,539 INFO [SettingsFactory] Query language substitutions: {no='N', true=1, yes='Y', false=0}
16:41:04,555 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
16:41:04,555 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 1
16:41:04,555 INFO [DriverManagerConnectionProvider] autocommit mode: false
16:41:05,457 INFO [DriverManagerConnectionProvider] using driver: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc:microsoft:sqlserver://sumatra:1433;DatabaseName=Test_Hibernate;SelectMethod=Cursor
16:41:05,457 INFO [DriverManagerConnectionProvider] connection properties: {user=sa, password=****}
16:41:05,457 DEBUG [DriverManagerConnectionProvider] total checked-out connections: 0
16:41:05,457 DEBUG [DriverManagerConnectionProvider] opening new JDBC connection
16:41:06,603 DEBUG [DriverManagerConnectionProvider] created connection to: jdbc:microsoft:sqlserver://sumatra:1433;DatabaseName=Test_Hibernate;SelectMethod=Cursor, Isolation Level: 2
16:41:06,664 DEBUG [DriverManagerConnectionProvider] returning connection to pool, pool size: 1
16:41:06,664 INFO [SettingsFactory] Scrollable result sets: enabled
16:41:06,664 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
16:41:06,680 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
16:41:06,695 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
16:41:06,695 INFO [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
16:41:06,710 INFO [SettingsFactory] Second-level cache: enabled
16:41:06,710 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
16:41:06,710 INFO [SettingsFactory] Cache region prefix: hibernate.test
16:41:06,710 INFO [SettingsFactory] Query cache: disabled
16:41:06,710 INFO [SettingsFactory] Statistics: disabled
16:41:06,710 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
16:41:07,138 INFO [SessionFactoryImpl] building session factory
16:41:07,138 DEBUG [SessionFactoryImpl] Session factory constructed with filter configurations : {}
16:41:07,138 DEBUG [SessionFactoryImpl] instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=hu8ilmcp, hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider, sun.boot.library.path=C:\JavaSoft\j2sdk1.4.2_05\jre\bin, java.vm.version=1.4.2_05-b04, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sa, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=FR, sun.os.patch.level=Service Pack 2, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\JavaSoft\eclipse\workspace\Hibernate, java.runtime.version=1.4.2_05-b04, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\JavaSoft\j2sdk1.4.2_05\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\jreboul\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.java2d.fontpath=, hibernate.jdbc.batch_versioned_data=true, hibernate.cache.region_prefix=hibernate.test, java.library.path=C:\JavaSoft\j2sdk1.4.2_05\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\Home\Programs\texmf\miktex\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\JavaSoft\ANT\bin;C:\JavaSoft\j2sdk1.4.2_05\bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;c:\cygwin\bin;c:\cygwin\usr\bin;c:\cygwin\usr\local\bin;c:\cygwin\usr\X11R6\bin;c:\cygwin\Home\gs\gs8.00\bin;:\cygwin\Home\gs\gs8.00\lib;C:\Program Files\JProbe Profiler 5.2.1\bin;C:\Program Files\Microsoft Visual Studio\VSS\netsetup.x86\VSS\win32, java.specification.name=Java Platform API Specification, java.class.version=48.0, hibernate.connection.pool_size=1, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.1, user.home=C:\Documents and Settings\jreboul, user.timezone=Europe/Paris, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=UTF-8, java.specification.version=1.4, hibernate.connection.driver_class=com.microsoft.jdbc.sqlserver.SQLServerDriver, java.class.path=C:\JavaSoft\eclipse\workspace\Hibernate\bin;C:\Home\Programs\hibernate-3.0alpha\hibernate3.jar;C:\Home\Programs\hibernate-3.0alpha\lib\ant-1.6.1.jar;C:\Home\Programs\hibernate-3.0alpha\lib\ant-antlr-1.6.1.jar;C:\Home\Programs\hibernate-3.0alpha\lib\ant-junit-1.6.1.jar;C:\Home\Programs\hibernate-3.0alpha\lib\ant-launcher-1.6.1.jar;C:\Home\Programs\hibernate-3.0alpha\lib\antlr-2.7.4.jar;C:\Home\Programs\hibernate-3.0alpha\lib\ant-swing-1.6.1.jar;C:\Home\Programs\hibernate-3.0alpha\lib\c3p0-0.8.4.5.jar;C:\Home\Programs\hibernate-3.0alpha\lib\cglib-full-2.0.2.jar;C:\Home\Programs\hibernate-3.0alpha\lib\cleanimports.jar;C:\Home\Programs\hibernate-3.0alpha\lib\commons-collections-2.1.1.jar;C:\Home\Programs\hibernate-3.0alpha\lib\commons-logging-1.0.4.jar;C:\Home\Programs\hibernate-3.0alpha\lib\concurrent-1.3.2.jar;C:\Home\Programs\hibernate-3.0alpha\lib\connector.jar;C:\Home\Programs\hibernate-3.0alpha\lib\dom4j-1.4.jar;C:\Home\Programs\hibernate-3.0alpha\lib\ehcache-0.9.jar;C:\Home\Programs\hibernate-3.0alpha\lib\jaas.jar;C:\Home\Programs\hibernate-3.0alpha\lib\jboss-cache.jar;C:\Home\Programs\hibernate-3.0alpha\lib\jboss-common.jar;C:\Home\Programs\hibernate-3.0alpha\lib\jboss-jmx.jar;C:\Home\Programs\hibernate-3.0alpha\lib\jboss-system.jar;C:\Home\Programs\hibernate-3.0alpha\lib\jdbc2_0-stdext.jar;C:\Home\Programs\hibernate-3.0alpha\lib\jgroups-2.2.1.jar;C:\Home\Programs\hibernate-3.0alpha\lib\jta.jar;C:\Home\Programs\hibernate-3.0alpha\lib\junit-3.8.1.jar;C:\Home\Programs\hibernate-3.0alpha\lib\log4j-1.2.8.jar;C:\Home\Programs\hibernate-3.0alpha\lib\proxool-0.8.3.jar;C:\Home\Programs\hibernate-3.0alpha\lib\swarmcache-1.0rc2.jar;C:\Home\Programs\hibernate-3.0alpha\lib\xalan-2.4.0.jar;C:\Home\Programs\hibernate-3.0alpha\lib\xerces-2.4.0.jar;C:\Home\Programs\hibernate-3.0alpha\lib\xml-apis.jar;C:\Home\Programs\hibernate-3.0alpha\lib\oscache-2.0.jar;C:\JavaSoft\eclipse\workspace\_Evolution\lib\ext\msbase.jar;C:\JavaSoft\eclipse\workspace\_Evolution\lib\ext\mssqlserver.jar;C:\JavaSoft\eclipse\workspace\_Evolution\lib\ext\msutil.jar;C:\JavaSoft\eclipse\workspace\Hibernate\etc, user.name=jreboul, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', java.vm.specification.version=1.0, java.home=C:\JavaSoft\j2sdk1.4.2_05\jre, sun.arch.data.model=32, hibernate.dialect=org.hibernate.dialect.SQLServerDialect, hibernate.connection.url=jdbc:microsoft:sqlserver://sumatra:1433;DatabaseName=Test_Hibernate;SelectMethod=Cursor, user.language=fr, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, hibernate.jdbc.use_streams_for_binary=true, java.version=1.4.2_05, java.ext.dirs=C:\JavaSoft\j2sdk1.4.2_05\jre\lib\ext, sun.boot.class.path=C:\JavaSoft\j2sdk1.4.2_05\jre\lib\rt.jar;C:\JavaSoft\j2sdk1.4.2_05\jre\lib\i18n.jar;C:\JavaSoft\j2sdk1.4.2_05\jre\lib\sunrsasign.jar;C:\JavaSoft\j2sdk1.4.2_05\jre\lib\jsse.jar;C:\JavaSoft\j2sdk1.4.2_05\jre\lib\jce.jar;C:\JavaSoft\j2sdk1.4.2_05\jre\lib\charsets.jar;C:\JavaSoft\j2sdk1.4.2_05\jre\classes, java.vendor=Sun Microsystems Inc., hibernate.jdbc.batch_size=0, file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, hibernate.max_fetch_depth=1, sun.cpu.isalist=pentium i486 i386}
java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.persister.BasicEntityPersister.createSelect(BasicEntityPersister.java:2022)
at org.hibernate.persister.BasicEntityPersister.renderSelect(BasicEntityPersister.java:2060)
at org.hibernate.persister.BasicEntityPersister.generateLazySelectString(BasicEntityPersister.java:551)
at org.hibernate.persister.BasicEntityPersister.postInstantiate(BasicEntityPersister.java:2118)
at org.hibernate.persister.SingleTableEntityPersister.postInstantiate(SingleTableEntityPersister.java:367)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:200)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:914)
at fr.digimind.jdo.hibernate.FindProductByName.main(FindProductByName.java:48)