-->
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.  [ 8 posts ] 
Author Message
 Post subject: many-to-one returning null on Hibernate3
PostPosted: Sat Apr 02, 2005 5:03 am 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Hello everyone,

I've got a rather basic problem with Hibernate3: When loading an entity with session.load(), the many-to-one association to another entitiy is initialized with "null".

In my case, I've got a Markt (market) that has a masterSprache (master language). The following code fragment outputs

Quote:
class Markt[id=6]
null


I have triple checked that there is sensible data in my database tables.

I know that session.load can only return a proxy instead of the "real" entity. It is my understanding that if the session is still open, the proxy is 100% transparent. It should not return null on a many-to-one property.

The strange thing is that when I add a Markt with a masterSprache programmatically via Hibernate, it is correctly persisted.

The same example worked fine on Hibernate 2.1.8, as far as I can remember. I have carefully read the migration guide (and the forums), but did not find any clue.

What am I doing wrong?

(I can provide an isolated eclipse project demonstrating my problem)

Best regards,

Andreas

Hibernate version:
3.0 final

Mapping documents:
Markt.hbm.xml:
Code:
<hibernate-mapping>

   <class name="Markt" table="markt">

      <id name="id" type="integer" column="id" unsaved-value="null">
         <generator class="identity" />
      </id>

      <many-to-one name="masterSprache" column="master_sprache_id"
         not-null="true" />

   </class>

</hibernate-mapping>


Sprache.hbm.xml:
Code:
<hibernate-mapping>

   <class name="Sprache" table="sprache">

      <id name="id" type="integer" column="id" unsaved-value="null">
         <generator class="identity" />
      </id>

   </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
        Session session = sf.openSession();
        // System.out.println(session.createCriteria(Markt.class).list());
        Markt markt = (Markt) session.load(Markt.class, new Integer(6));
        System.out.println(markt);
        Sprache sprache = (Sprache) markt.getMasterSprache();
        System.out.println(sprache);
        session.close();


Full stack trace of any exception that occurs:
No exceptions

Name and version of the database you are using:
MySQL 4.1.10 (same Problem on Oracle 8)

The generated SQL (show_sql=true):
Quote:
select markt0_.id as id0_, markt0_.master_sprache_id as master2_0_0_ from markt markt0_ where markt0_.id=?


Debug level Hibernate log excerpt:
Quote:
02.04.2005 10:49:04 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0
02.04.2005 10:49:04 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
02.04.2005 10:49:04 org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
02.04.2005 10:49:04 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
02.04.2005 10:49:04 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
02.04.2005 10:49:04 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
02.04.2005 10:49:05 org.hibernate.util.DTDEntityResolver resolveEntity
FEIN: trying to locate http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
02.04.2005 10:49:05 org.hibernate.util.DTDEntityResolver resolveEntity
FEIN: found http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
02.04.2005 10:49:05 org.hibernate.cfg.Configuration addProperties
FEIN: show_sql=true
02.04.2005 10:49:05 org.hibernate.cfg.Configuration addProperties
FEIN: dialect=org.hibernate.dialect.MySQLDialect
02.04.2005 10:49:05 org.hibernate.cfg.Configuration addProperties
FEIN: connection.url=jdbc:mysql://localhost:3306/bmw-textwerk2?autoReconnect=true
02.04.2005 10:49:05 org.hibernate.cfg.Configuration addProperties
FEIN: connection.driver_class=com.mysql.jdbc.Driver
02.04.2005 10:49:05 org.hibernate.cfg.Configuration parseMappingElement
FEIN: null<-org.dom4j.tree.DefaultAttribute@1befab0 [Attribute: name resource value "Markt.hbm.xml"]
02.04.2005 10:49:05 org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Markt.hbm.xml
02.04.2005 10:49:05 org.hibernate.util.DTDEntityResolver resolveEntity
FEIN: trying to locate http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate/
02.04.2005 10:49:05 org.hibernate.util.DTDEntityResolver resolveEntity
FEIN: found http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
02.04.2005 10:49:05 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: Markt -> markt
02.04.2005 10:49:05 org.hibernate.cfg.HbmBinder bindProperty
FEIN: Mapped property: id -> id
02.04.2005 10:49:05 org.hibernate.cfg.HbmBinder bindProperty
FEIN: Mapped property: masterSprache -> master_sprache_id
02.04.2005 10:49:05 org.hibernate.cfg.Configuration parseMappingElement
FEIN: null<-org.dom4j.tree.DefaultAttribute@16672d6 [Attribute: name resource value "Sprache.hbm.xml"]
02.04.2005 10:49:05 org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Sprache.hbm.xml
02.04.2005 10:49:05 org.hibernate.util.DTDEntityResolver resolveEntity
FEIN: trying to locate http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate/
02.04.2005 10:49:05 org.hibernate.util.DTDEntityResolver resolveEntity
FEIN: found http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
02.04.2005 10:49:05 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: Sprache -> sprache
02.04.2005 10:49:05 org.hibernate.cfg.HbmBinder bindProperty
FEIN: Mapped property: id -> id
02.04.2005 10:49:05 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
02.04.2005 10:49:05 org.hibernate.cfg.Configuration doConfigure
FEIN: properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\Program Files\Java\jdk1.5.0\jre\bin, java.vm.version=1.5.0_02-b09, 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=DE, sun.os.patch.level=Service Pack 2, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\eclipse-3.1M5\workspace\hibernateTest, java.runtime.version=1.5.0_02-b09, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\jdk1.5.0\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.jnu.encoding=Cp1252, java.library.path=C:\Program Files\Java\jdk1.5.0\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\bin;C:\cygwin\bin;C:\Program Files\Subversion\bin;C:\Perl\bin\;C:\Program Files\Intuwave\Shared\mRouterRuntime;C:\Program Files\Java\jdk1.5.0\bin;C:\texmf\miktex\bin;C:\Program Files\SSH Communications Security\SSH Secure Shell;C:\Program Files\Subversion\bin, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Documents and Settings\Administrator, user.timezone=Europe/Berlin, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.5, hibernate.connection.driver_class=com.mysql.jdbc.Driver, show_sql=true, user.name=Administrator, java.class.path=C:\eclipse-3.1M5\workspace\hibernateTest\bin;C:\eclipse-3.1M5\workspace\hibernateTest\lib\commons-collections-2.1.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\dom4j-1.5.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ehcache-1.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jta.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\mysql-connector-java-3.1.7-bin.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\hibernate3.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-antlr-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-junit-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-launcher-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\antlr-2.7.5H3.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-swing-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\asm.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\asm-attrs.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\c3p0-0.8.5.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\cglib-2.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\cleanimports.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\commons-logging-1.0.4.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\concurrent-1.3.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\connector.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jaas.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jacc-1_0-fr.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jaxen-1.1-beta-4.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jboss-cache.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jboss-common.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jboss-jmx.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jboss-system.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jdbc2_0-stdext.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jgroups-2.2.7.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\junit-3.8.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\oscache-2.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\proxool-0.8.3.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\swarmcache-1.0rc2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\versioncheck.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\xerces-2.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\xml-apis.jar, hibernate.show_sql=true, java.vm.specification.version=1.0, java.home=C:\Program Files\Java\jdk1.5.0\jre, sun.arch.data.model=32, hibernate.connection.url=jdbc:mysql://localhost:3306/xxx?autoReconnect=true, hibernate.dialect=org.hibernate.dialect.MySQLDialect, user.language=de, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, sharing, java.version=1.5.0_02, java.ext.dirs=C:\Program Files\Java\jdk1.5.0\jre\lib\ext, sun.boot.class.path=C:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\i18n.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\jce.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.5.0\jre\classes, java.vendor=Sun Microsystems Inc., connection.driver_class=com.mysql.jdbc.Driver, file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, connection.url=jdbc:mysql://localhost:3306/xxx?autoReconnect=true, dialect=org.hibernate.dialect.MySQLDialect, sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86}
02.04.2005 10:49:05 org.hibernate.cfg.Configuration buildSessionFactory
FEIN: Preparing to build session factory with filters : {}
02.04.2005 10:49:05 org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
02.04.2005 10:49:05 org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
02.04.2005 10:49:05 org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
02.04.2005 10:49:05 org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
02.04.2005 10:49:05 org.hibernate.cfg.Configuration secondPassCompileForeignKeys
FEIN: resolving reference to class: Sprache
02.04.2005 10:49:06 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
02.04.2005 10:49:06 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
02.04.2005 10:49:06 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
02.04.2005 10:49:06 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
02.04.2005 10:49:06 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
02.04.2005 10:49:06 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/bmw-textwerk2?autoReconnect=true
02.04.2005 10:49:06 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {}
02.04.2005 10:49:06 org.hibernate.connection.DriverManagerConnectionProvider getConnection
FEIN: opening new JDBC connection
02.04.2005 10:49:06 org.hibernate.connection.DriverManagerConnectionProvider getConnection
FEIN: created connection to: jdbc:mysql://localhost:3306/bmw-textwerk2?autoReconnect=true, Isolation Level: 4
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
FEIN: Wrap result sets: disabled
02.04.2005 10:49:06 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
02.04.2005 10:49:07 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
02.04.2005 10:49:07 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: enabled
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
02.04.2005 10:49:07 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
02.04.2005 10:49:07 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
02.04.2005 10:49:07 org.hibernate.impl.SessionFactoryImpl <init>
FEIN: Session factory constructed with filter configurations : {}
02.04.2005 10:49:07 org.hibernate.impl.SessionFactoryImpl <init>
FEIN: instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\Program Files\Java\jdk1.5.0\jre\bin, java.vm.version=1.5.0_02-b09, 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=DE, sun.os.patch.level=Service Pack 2, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\eclipse-3.1M5\workspace\hibernateTest, java.runtime.version=1.5.0_02-b09, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\jdk1.5.0\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.jnu.encoding=Cp1252, java.library.path=C:\Program Files\Java\jdk1.5.0\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\bin;C:\cygwin\bin;C:\Program Files\Subversion\bin;C:\Perl\bin\;C:\Program Files\Intuwave\Shared\mRouterRuntime;C:\Program Files\Java\jdk1.5.0\bin;C:\texmf\miktex\bin;C:\Program Files\SSH Communications Security\SSH Secure Shell;C:\Program Files\Subversion\bin, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Documents and Settings\Administrator, user.timezone=Europe/Berlin, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.5, hibernate.connection.driver_class=com.mysql.jdbc.Driver, show_sql=true, user.name=Administrator, java.class.path=C:\eclipse-3.1M5\workspace\hibernateTest\bin;C:\eclipse-3.1M5\workspace\hibernateTest\lib\commons-collections-2.1.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\dom4j-1.5.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ehcache-1.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jta.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\mysql-connector-java-3.1.7-bin.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\hibernate3.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-antlr-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-junit-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-launcher-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\antlr-2.7.5H3.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\ant-swing-1.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\asm.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\asm-attrs.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\c3p0-0.8.5.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\cglib-2.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\cleanimports.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\commons-logging-1.0.4.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\concurrent-1.3.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\connector.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jaas.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jacc-1_0-fr.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jaxen-1.1-beta-4.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jboss-cache.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jboss-common.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jboss-jmx.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jboss-system.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jdbc2_0-stdext.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\jgroups-2.2.7.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\junit-3.8.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\oscache-2.1.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\proxool-0.8.3.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\swarmcache-1.0rc2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\versioncheck.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\xerces-2.6.2.jar;C:\eclipse-3.1M5\workspace\hibernateTest\lib\xml-apis.jar, hibernate.show_sql=true, java.vm.specification.version=1.0, java.home=C:\Program Files\Java\jdk1.5.0\jre, sun.arch.data.model=32, hibernate.connection.url=jdbc:mysql://localhost:3306/xxx?autoReconnect=true, hibernate.dialect=org.hibernate.dialect.MySQLDialect, user.language=de, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, sharing, java.version=1.5.0_02, java.ext.dirs=C:\Program Files\Java\jdk1.5.0\jre\lib\ext, sun.boot.class.path=C:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\i18n.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\jce.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.5.0\jre\classes, java.vendor=Sun Microsystems Inc., connection.driver_class=com.mysql.jdbc.Driver, file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, connection.url=jdbc:mysql://localhost:3306/xxx?autoReconnect=true, dialect=org.hibernate.dialect.MySQLDialect, sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86}
02.04.2005 10:49:07 net.sf.ehcache.CacheManager create
FEIN: Creating new CacheManager with default config
02.04.2005 10:49:07 net.sf.ehcache.CacheManager configure
FEIN: Configuring ehcache from classpath.
02.04.2005 10:49:07 net.sf.ehcache.config.Configurator configure
WARNUNG: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/eclipse-3.1M5/workspace/hibernateTest/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
02.04.2005 10:49:07 net.sf.ehcache.config.Configuration$DiskStore setPath
FEIN: Disk Store Path: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\
02.04.2005 10:49:07 org.hibernate.util.ReflectHelper getBulkBean
FEIN: reflection optimizer disabled for: Markt, IllegalArgumentException: Cannot find matching method/constructor
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Static SQL for entity: Markt
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Version select: select id from markt where id =?
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Snapshot select: select markt_.id, markt_.master_sprache_id as master2_0_ from markt markt_ where markt_.id=?
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Insert 0: insert into markt (master_sprache_id, id) values (?, ?)
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Update 0: update markt set master_sprache_id=? where id=?
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Delete 0: delete from markt where id=?
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Identity insert: insert into markt (master_sprache_id) values (?)
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Static SQL for entity: Sprache
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Version select: select id from sprache where id =?
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Snapshot select: select sprache_.id from sprache sprache_ where sprache_.id=?
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Insert 0: insert into sprache (id) values (?)
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Update 0: null
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Delete 0: delete from sprache where id=?
02.04.2005 10:49:07 org.hibernate.persister.entity.BasicEntityPersister logStaticSQL
FEIN: Identity insert: insert into sprache values ( )
02.04.2005 10:49:08 org.hibernate.loader.entity.EntityLoader <init>
FEIN: Static select for entity Markt: select markt0_.id as id0_, markt0_.master_sprache_id as master2_0_0_ from markt markt0_ where markt0_.id=?
02.04.2005 10:49:08 org.hibernate.loader.entity.EntityLoader <init>
FEIN: Static select for entity Markt: select markt0_.id as id0_, markt0_.master_sprache_id as master2_0_0_ from markt markt0_ where markt0_.id=?
02.04.2005 10:49:08 org.hibernate.loader.entity.EntityLoader <init>
FEIN: Static select for entity Markt: select markt0_.id as id0_, markt0_.master_sprache_id as master2_0_0_ from markt markt0_ where markt0_.id=? for update
02.04.2005 10:49:08 org.hibernate.loader.entity.EntityLoader <init>
FEIN: Static select for entity Markt: select markt0_.id as id0_, markt0_.master_sprache_id as master2_0_0_ from markt markt0_ where markt0_.id=? for update
02.04.2005 10:49:08 org.hibernate.loader.entity.EntityLoader <init>
FEIN: Static select for entity Sprache: select sprache0_.id as id0_ from sprache sprache0_ where sprache0_.id=?
02.04.2005 10:49:08 org.hibernate.loader.entity.EntityLoader <init>
FEIN: Static select for entity Sprache: select sprache0_.id as id0_ from sprache sprache0_ where sprache0_.id=?
02.04.2005 10:49:08 org.hibernate.loader.entity.EntityLoader <init>
FEIN: Static select for entity Sprache: select sprache0_.id as id0_ from sprache sprache0_ where sprache0_.id=? for update
02.04.2005 10:49:08 org.hibernate.loader.entity.EntityLoader <init>
FEIN: Static select for entity Sprache: select sprache0_.id as id0_ from sprache sprache0_ where sprache0_.id=? for update
02.04.2005 10:49:08 org.hibernate.impl.SessionFactoryObjectFactory <clinit>
FEIN: initializing class SessionFactoryObjectFactory
02.04.2005 10:49:08 org.hibernate.impl.SessionFactoryObjectFactory addInstance
FEIN: registered: 402880a00302195f0103021963d10000 (unnamed)
02.04.2005 10:49:08 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
02.04.2005 10:49:08 org.hibernate.impl.SessionFactoryImpl <init>
FEIN: instantiated session factory
02.04.2005 10:49:08 org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
02.04.2005 10:49:08 org.hibernate.impl.SessionImpl <init>
FEIN: opened session at timestamp: 4556520440090624
02.04.2005 10:49:08 org.hibernate.impl.SessionImpl immediateLoad
FEIN: initializing proxy: [Markt#6]
02.04.2005 10:49:08 org.hibernate.loader.Loader loadEntity
FEIN: loading entity: [Markt#6]
02.04.2005 10:49:08 org.hibernate.jdbc.AbstractBatcher logOpenPreparedStatement
FEIN: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
02.04.2005 10:49:08 org.hibernate.jdbc.AbstractBatcher openConnection
FEIN: opening JDBC connection
02.04.2005 10:49:08 org.hibernate.jdbc.AbstractBatcher log
FEIN: select markt0_.id as id0_, markt0_.master_sprache_id as master2_0_0_ from markt markt0_ where markt0_.id=?
Hibernate: select markt0_.id as id0_, markt0_.master_sprache_id as master2_0_0_ from markt markt0_ where markt0_.id=?
02.04.2005 10:49:08 org.hibernate.jdbc.AbstractBatcher logOpenResults
FEIN: about to open ResultSet (open ResultSets: 0, globally: 0)
02.04.2005 10:49:08 org.hibernate.loader.Loader getRow
FEIN: result row: EntityKey[Markt#6]
02.04.2005 10:49:08 org.hibernate.jdbc.AbstractBatcher logCloseResults
FEIN: about to close ResultSet (open ResultSets: 1, globally: 1)
02.04.2005 10:49:08 org.hibernate.jdbc.AbstractBatcher logClosePreparedStatement
FEIN: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
02.04.2005 10:49:08 org.hibernate.engine.TwoPhaseLoad initializeEntity
FEIN: resolving associations for [Markt#6]
02.04.2005 10:49:08 org.hibernate.engine.TwoPhaseLoad initializeEntity
FEIN: done materializing entity [Markt#6]
02.04.2005 10:49:08 org.hibernate.engine.PersistenceContext initializeNonLazyCollections
FEIN: initializing non-lazy collections
class Markt[id=6]
null
02.04.2005 10:49:08 org.hibernate.loader.Loader loadEntity
FEIN: done entity load
02.04.2005 10:49:08 org.hibernate.jdbc.AbstractBatcher closeConnection
FEIN: closing JDBC connection (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)
02.04.2005 10:49:08 org.hibernate.impl.SessionFactoryImpl close
INFO: closing
02.04.2005 10:49:08 org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost:3306/bmw-textwerk2?autoReconnect=true


MySQL schema:
Code:
CREATE TABLE `markt` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `master_sprache_id` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `FK_markt_master_sprache` (`master_sprache_id`),
  CONSTRAINT `FK_markt_master_sprache` FOREIGN KEY (`master_sprache_id`) REFERENCES `sprache` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `sprache` (
  `id` int(10) unsigned NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED;


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 02, 2005 8:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
to debug, change
Code:
      <many-to-one name="masterSprache" column="master_sprache_id"
         not-null="true" />


to
Code:
      <many-to-one name="masterSprache" fetch="join" column="master_sprache_id"
         not-null="true" />


then copy paste generated sql to your db client and check what's happening

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 02, 2005 12:19 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Hello Anthony!

Thanks for your suggestion. I changed the mapping, here is the generated SQL:

select markt0_.id as id1_, markt0_.master_sprache_id as master2_0_1_, sprache1_.id as id0_ from markt markt0_ inner join sprache sprache1_ on markt0_.master_sprache_id=sprache1_.id where markt0_.id=?

When I replace the "?" with my id (6), I get the following result:

"id1_","master2_0_1_","id0_"
6, 12, 12

I can see nothing wrong. However, masterSprache is still "null".

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 02, 2005 12:21 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
There is one thing I forgot to tell:

When I uncomment the line

Code:
System.out.println(session.createCriteria(Markt.class).list());


in my previous code, I afterwards get the correct value for masterSprache (because it is fetched from level 1 cache, I think).

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 03, 2005 4:49 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
I have now read all frequent problems, searched every forum and the wiki.

If no one has got any objections, I will file a bug report (although I can't believe that Hibernate3 contains trivial bugs like this).

Regards,

Andreas


Top
 Profile  
 
 Post subject: many-to-one returning null on Hibernate3 [solved]
PostPosted: Sun Apr 03, 2005 5:13 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
I just found the cause of my problem: I had defined the accessors of my persistant objects as final.

Is this behaviour really intentional (without warning and all)?

Shall I still file a bug report against Hibernate3?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 03, 2005 5:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Of course you should not. This is incredibly well-documented.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 2:20 am 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Could you point me to where it is documented (in the reference manual), please?

I only found

4.1.4. Prefer non-final classes (optional)

which does not match my mistake.

4.1.1. Declare accessors and mutators for persistent fields

does not mention it either (I think a novice would expect it there because it talks about the other method modifiers).

Regards,

Andreas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.