The problem is that I have a ManyToOne with cascades specified, but cascades don't seems to work at all. Hibernate complains the associated object is transient instead of cascading the insertion.
Details follow:
Hibernate version:
3.2 cr1 and annotations 3.1 beta9
Mapping documents:
@Entity
@Table(name = "SCHEMATIC_TYPE")
public class SchematicType implements Comparable, Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(length = 50, name="NAME", nullable=false )
private String name;
...
}
@Entity
@Table(name = "FEATURE_TYPE")
public class FeatureType implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(length = 50, name = "FEATURE_NAME", nullable = false)
private String featureName;
@OneToMany(cascade={CascadeType.ALL})
@Cascade(value = { org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@JoinColumn(name = "FEATURE_TYPE_ID")
List<FeatureAttribute> featureAttributeList;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@Column(nullable = false)
SchematicType schematicType;
...
}
Code between sessionFactory.openSession() and session.close():
SchematicType st = new SchematicType(...);
FeatureType ft = new FeatureType("hello", st, ...)
s.saveOrUpdate(ft);
s.flush();
Full stack trace of any exception that occurs:
org.springframework.dao.InvalidDataAccessApiUsageException: za.co.bluesphere.sens.featuretype.model.SchematicType; nested exception is org.hibernate.TransientObjectException: za.co.bluesphere.sens.featuretype.model.SchematicType
org.hibernate.TransientObjectException: za.co.bluesphere.sens.featuretype.model.SchematicType
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:221)
at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:476)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:2900)
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:474)
at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:197)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:771)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:769)
at
...
Name and version of the database you are using:
Oracle 9.2
The generated SQL (show_sql=true):
Hibernate:
select
hibernate_sequence.nextval
from
dual
Debug level Hibernate log excerpt:
[INFO] Environment - -Hibernate 3.2 cr1
[INFO] Environment - -loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.Oracle9Dialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sens, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:oracle:thin:@andreaxp2fat:1521:andreaxp2fat, hibernate.show_sql=true, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
[INFO] Environment - -using java.io streams to persist binary types
[INFO] Environment - -Bytecode provider name : cglib
[INFO] Environment - -using JDK 1.4 java.sql.Timestamp handling
[INFO] AutoDiscoveryAnnotationSessionFactoryBean - -Building new Hibernate SessionFactory
[INFO] AnnotationBinder - -Binding entity from annotated class: za.co.bluesphere.sens.featuretype.model.SchematicType
[INFO] EntityBinder - -Bind entity za.co.bluesphere.sens.featuretype.model.SchematicType on table SCHEMATIC_TYPE
[INFO] AnnotationBinder - -Binding entity from annotated class: za.co.bluesphere.sens.featuretype.model.FeatureType
[INFO] EntityBinder - -Bind entity za.co.bluesphere.sens.featuretype.model.FeatureType on table FEATURE_TYPE
[INFO] AnnotationBinder - -Binding entity from annotated class: za.co.bluesphere.sens.featuretype.model.FeatureAttribute
[INFO] EntityBinder - -Bind entity za.co.bluesphere.sens.featuretype.model.FeatureAttribute on table FEATURE_ATTRIBUTE
[INFO] AnnotationBinder - -Binding entity from annotated class: za.co.bluesphere.sens.featuretype.model.EnumerationValue
[INFO] EntityBinder - -Bind entity za.co.bluesphere.sens.featuretype.model.EnumerationValue on table ENUM_VALUE
[INFO] CollectionBinder - -Mapping collection: za.co.bluesphere.sens.featuretype.model.FeatureAttribute.enumerationValues -> ENUM_VALUE
[INFO] CollectionBinder - -Mapping collection: za.co.bluesphere.sens.featuretype.model.FeatureType.featureAttributeList -> FEATURE_ATTRIBUTE
[INFO] DriverManagerConnectionProvider - -Using Hibernate built-in connection pool (not for production use!)
[INFO] DriverManagerConnectionProvider - -Hibernate connection pool size: 1
[INFO] DriverManagerConnectionProvider - -autocommit mode: false
[INFO] DriverManagerConnectionProvider - -using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@andreaxp2fat:1521:andreaxp2fat
[INFO] DriverManagerConnectionProvider - -connection properties: {user=sens, password=****}
[INFO] SettingsFactory - -RDBMS: Oracle, version: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
[INFO] SettingsFactory - -JDBC driver: Oracle JDBC driver, version: 9.0.1.0.0
[INFO] Dialect - -Using dialect: org.hibernate.dialect.Oracle9Dialect
[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 - -JDBC batch size: 15
[INFO] SettingsFactory - -JDBC batch updates for versioned data: enabled
[INFO] SettingsFactory - -Scrollable result sets: enabled
[INFO] SettingsFactory - -JDBC3 getGeneratedKeys(): disabled
[INFO] SettingsFactory - -Connection release mode: auto
[INFO] SettingsFactory - -Maximum outer join fetch depth: 1
[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.ast.ASTQueryTranslatorFactory
[INFO] ASTQueryTranslatorFactory - -Using ASTQueryTranslatorFactory
[INFO] SettingsFactory - -Query language substitutions: {no='N', yes='Y'}
[INFO] SettingsFactory - -Second-level cache: enabled
[INFO] SettingsFactory - -Query cache: disabled
[INFO] SettingsFactory - -Cache provider: org.hibernate.cache.HashtableCacheProvider
[INFO] SettingsFactory - -Optimize cache for minimal puts: disabled
[INFO] SettingsFactory - -Cache region prefix: hibernate.test
[INFO] SettingsFactory - -Structured second-level cache entries: disabled
[INFO] SettingsFactory - -Echoing all SQL to stdout
[INFO] SettingsFactory - -Statistics: disabled
[INFO] SettingsFactory - -Deleted entity synthetic identifier rollback: disabled
[INFO] SettingsFactory - -Default entity-mode: pojo
[INFO] SessionFactoryImpl - -building session factory
[INFO] SessionFactoryObjectFactory - -Not binding factory to JNDI, no JNDI name configured
[INFO] JdbcTransactionObjectSupport - -JDBC 3.0 Savepoint class is available
|