-->
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: cascaded saves are more flexible than direct saves.
PostPosted: Tue Feb 22, 2005 11:06 pm 
Newbie

Joined: Fri Jan 21, 2005 2:30 pm
Posts: 5
Hi there

I have run across an inconsistency in save behavior. If I try to save an object of XMLPropertyType class (extends PropertyTypeInst) I get a mapping exception.

However, it will get saved correctly if the XMLPropertyType needs to be saved to satisfy a cascade="save-update" definition.

See info below. Is this a bug or expected behavior?

Hibernate version: 3.0beta4

Mapping documents:
?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.sworddance.hypernormalize.dao">

<class name="ClassInst" table="HYPER_CLASSES" batch-size="100">
<!-- begin BaseTypeSuper definition-->
<id name="id" column="databaseId" type="integer">
<generator class="native"/>
</id>
<!-- end BaseTypeSuper definition -->

<map name="classProperties" cascade="all-delete-orphan" >
<key column="CLASS_ID"/>
<index-many-to-many column="PROPERTY_TYPE_ID" class="PropertyTypeInst"/>
<one-to-many class="ClassPropertyInst"/>
</map>
</class>
<class name="ClassPropertyInst" table="HYPER_CLASSPROP_DEF" >
<id name="id" column="databaseId" type="integer">
<generator class="native"/>
</id>
<!-- BasePropertyInstSuper -->
<many-to-one name="owner" class="ClassInst" column="OWNER_CLASS_ID" access="field" not-null="true"/>
<many-to-one name="propertyType" class="PropertyTypeInst" column="PROPERTY_TYPE" not-null="true" access="field" cascade="save-update"/>
<property name="description" type="string" length="2000"/>
<property name="identityRank" type="com.sworddance.hypernormalize.dao.types.IdentityRankUserType" column="RANK"/>
<property name="cardinality" type="com.sworddance.hypernormalize.dao.types.CardinalityCheckerUserType" />
<property name="scope" type="com.sworddance.hypernormalize.dao.types.ScopingUserType"/>
<property name="obsolete" type="com.sworddance.hypernormalize.dao.types.ObsoleteUserType">
<column name="IS_OBSOLETE" not-null="true"/>
<column name="REPLACEMENT"/>
</property>
</class>
<!-- PROPERTIES -->
<class name="PropertyTypeInst" table="HYPER_PROPDEF" batch-size="100">
<!-- begin BaseTypeSuper definition-->
<id name="id" column="databaseId" type="integer">
<generator class="native"/>
</id>
<property name="name" type="string" length="100" not-null="true"/>
<property name="description" type="string" length="2000"/>
<!-- end BaseTypeSuper definition -->

<property name="dataType" type="string" length="100"/>
</class>
<hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
[XMLPropertyType extends PropertyTypeInst]
session.save(xmlPropertyType); (doesn't work)

But this will result in the XMLPropertyType being saved:
cp = new ClassPropertyInst();
cp.setPropertyType(xmlPropertyType);
aclassInst.getClassProperties().put(xmlProperty.getURI(), cp);
session.save(aclassInst);

Full stack trace of any exception that occurs (only when trying to directly save the XMLPropertyType):
org.hibernate.MappingException: Unknown entity: com.sworddance.hypernormalize.dao.xml.XMLPropertyType
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:484)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1034)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:174)
at org.hibernate.event.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:400)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:78)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:65)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:466)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:461)
at com.sworddance.hypernormalize.persistence.DatabasePersister$HConnectionImpl.save(DatabasePersister.java:130)
at com.sworddance.hypernormalize.persistence.DatabasePersister$HConnectionImpl.save(DatabasePersister.java:144)
at com.sworddance.hypernormalize.persistence.HypernormalizeClassManager.loadDefinitionsFromFileInPath(HypernormalizeClassManager.java:53)
at test.hibernate.TestSaveAndLoadOfHibernatePrimitives.testLoadOfBaseDefinitions(TestSaveAndLoadOfHibernatePrimitives.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)


Name and version of the database you are using:

mysql 4.x
The generated SQL (show_sql=true):
Hibernate: insert into UserInst (userName, externalId) values (?, ?)
Hibernate: insert into HYPER_REVISIONS (owner, commitTime, description) values (?, ?, ?)
Hibernate: insert into HYPER_CLASSES (URI, NAME, IS_ABSTRACT, IS_OBSOLETE, REPLACEMENT, DESCRIPTION, extendedClass) values (?, ?, ?, ?, ?, ?, ?)
[ERROR] DatabasePersister - Could not persist com.sworddance.hypernormalize.dao.xml.XMLPropertyType(DataType: )
Debug level Hibernate log excerpt:

[INFO] Environment - Hibernate 3.0 beta 4
[INFO] Environment - loaded properties from resource hibernate.properties: {hibernate.connection.username=test, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.use_outer_join=true, hibernate.show_sql=true, hibernate.connection.driver_class=com.mysql.jdbc.Driver}
[INFO] Environment - using CGLIB reflection optimizer
[INFO] Environment - using JDK 1.4 java.sql.Timestamp handling
[INFO] Configuration - configuring from resource: /test-hibernate.cfg.xml
[INFO] Configuration - Configuration resource: /test-hibernate.cfg.xml
[INFO] Configuration - Mapping resource: hypernormalize.hbm.xml
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.ClassInst -> HYPER_CLASSES
[INFO] HbmBinder - Mapping collection: com.sworddance.hypernormalize.dao.ClassInst.hierarchy -> HYPER_CLASS_HIERARCHY
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.ClassRelationshipInst -> HYPER_CLASSREL_DEF
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.ClassPropertyInst -> HYPER_CLASSPROP_DEF
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.PropertyTypeInst -> HYPER_PROPDEF
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.RelationshipTypeInst -> HYPER_RELTYPE_DEF
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.RelationshipPropertyInst -> HYPER_RELPROP_DEF
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.ObjectInst -> HYPER_OBJS
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.PropertyInst -> HYPER_OBJPROPS
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.RelationshipInst -> HYPER_OBJRELS
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.RelPropertyInst -> HYPER_OBJRELPROPS
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.RevisionRecordInst -> HYPER_REVISIONS
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.TagInst -> HYPER_TAGS
[INFO] HbmBinder - Mapping class: com.sworddance.hypernormalize.dao.UserInst -> UserInst
[INFO] Configuration - Configured SessionFactory: null
[INFO] Configuration - processing extends queue
[INFO] Configuration - processing collection mappings
[INFO] HbmBinder - Mapping collection: com.sworddance.hypernormalize.dao.ClassInst.classRelationships -> HYPER_CLASSREL_DEF
[INFO] HbmBinder - Mapping collection: com.sworddance.hypernormalize.dao.ClassInst.classProperties -> HYPER_CLASSPROP_DEF
[INFO] Configuration - processing association property references
[INFO] Configuration - processing foreign key constraints
[INFO] Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
[INFO] SettingsFactory - Maximum outer join fetch depth: 2
[INFO] SettingsFactory - Default batch fetch size: 1
[INFO] SettingsFactory - Generate SQL with comments: disabled
[INFO] SettingsFactory - Order SQL updates by primary key: disabled
[INFO] SettingsFactory - Query translator: org.hibernate.hql.classic.ClassicQueryTranslatorFactory
[INFO] SettingsFactory - Query language substitutions: {}
[INFO] DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
[INFO] DriverManagerConnectionProvider - Hibernate connection pool size: 20
[INFO] DriverManagerConnectionProvider - autocommit mode: false
[INFO] DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/test
[INFO] DriverManagerConnectionProvider - connection properties: {user=Test, password=****}
[INFO] SettingsFactory - JDBC batch size: 15
[INFO] SettingsFactory - JDBC batch updates for versioned data: disabled
[INFO] SettingsFactory - Scrollable result sets: enabled
[INFO] SettingsFactory - JDBC3 getGeneratedKeys(): enabled
[INFO] TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
[INFO] TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[INFO] SettingsFactory - Automatic flush during beforeCompletion(): disabled
[INFO] SettingsFactory - Automatic session close at end of transaction: disabled
[INFO] SettingsFactory - Cache provider: org.hibernate.cache.EhCacheProvider
[INFO] SettingsFactory - Second-level cache: enabled
[INFO] SettingsFactory - Optimize cache for minimal puts: disabled
[INFO] SettingsFactory - Structured second-level cache entries: enabled
[INFO] SettingsFactory - Query cache: disabled
[INFO] SettingsFactory - Echoing all SQL to stdout
[INFO] SettingsFactory - Statistics: disabled
[INFO] SettingsFactory - Deleted entity synthetic identifier rollback: disabled
[INFO] SessionFactoryImpl - building session factory
[WARN] Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/usr/local/ehcache-1.1/ehcache-1.1.jar!/ehcache-failsafe.xml
[INFO] SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
[INFO] SessionFactoryImpl - Checking 0 named queries
Hibernate: insert into UserInst (userName, externalId) values (?, ?)
Hibernate: insert into HYPER_REVISIONS (owner, commitTime, description) values (?, ?, ?)
Hibernate: insert into HYPER_CLASSES (URI, NAME, IS_ABSTRACT, IS_OBSOLETE, REPLACEMENT, DESCRIPTION, extendedClass) values (?, ?, ?, ?, ?, ?, ?)
[ERROR] DatabasePersister - Could not persist com.sworddance.hypernormalize.dao.xml.XMLPropertyType(DataType: )
Feb 22, 2005 6:37:55 PM com.sworddance.hypernormalize.persistence.TransactionImpl rollback
INFO: Rolling back transaction


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 10:26 am 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
Doesn't look like a mapping exception, or Hibernate would fail on initialization.
Here's my guess:
<many-to-one name="propertyType" class="PropertyTypeInst" column="PROPERTY_TYPE" not-null="true" access="field" cascade="save-update"/>

When you just initialize and save it, propertyType is not being set, and since it is not-null, there is an error.
When you create the object and then insert it into a propertyType, it is being set, and so it saves fine.


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.