[Hibernate-JIRA] Created: (HHH-2204) transient field make Configuration deserializing error
by ronald feng (JIRA)
transient field make Configuration deserializing error
-------------------------------------------------------
Key: HHH-2204
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2204
Project: Hibernate3
Type: Bug
Components: build
Versions: 3.1.3
Environment: hibernate 3.1.3
database: HSQLDB
Reporter: ronald feng
[code]
Configuration configuration=null;
try {
Configuration configurationSerializable = new Configuration();
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(configurationSerializable);
oos.flush();
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
configuration = (Configuration) ois.readObject();
ois.close();
} catch (FileNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
if(configuration!=null)
{
SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
}
}
[/code]
protected transient Map typeDefs;
the typeDefs will be null after deserializing.
[code]Exception in thread "main" java.lang.NullPointerException
at org.hibernate.cfg.Mappings.getTypeDef(Mappings.java:376)
at org.hibernate.cfg.HbmBinder.bindSimpleValueType(HbmBinder.java:1161)
at org.hibernate.cfg.HbmBinder.bindSimpleValue(HbmBinder.java:1129)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:400)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:343)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
at org.rzeus.hibernate.test.TestSerializeAndTransient.main(TestSerializeAndTransient.java:50)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)[/code]
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
17 years, 9 months
[Hibernate-JIRA] Created: (HHH-3294) Version incorrectly incremented for unchanged persistent entity that is parent of a one to many relationship
by Raymond Chapman (JIRA)
Version incorrectly incremented for unchanged persistent entity that is parent of a one to many relationship
------------------------------------------------------------------------------------------------------------
Key: HHH-3294
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3294
Project: Hibernate3
Issue Type: Patch
Components: core
Affects Versions: 3.2.4.sp1
Environment: 3.2.4.sp1, Oracle 10g
Reporter: Raymond Chapman
Attachments: versionbumpissue.zip
Given a persisted parent entity and a single persisted child entity involved in a one to many relationship where children are defined in parent HBM file to include merge and persist cascade action, we find that loading the parent and child in a transaction followed by a merge of the parent (no updates performed on either child or parent), and then a transaction commit will increment the version of the parent by 1.
In attached zip I've isolated the problem in a new test testNoExtraUpdatesOnPersistentMergeVersionedWithCollection(), displayed below, added to org/hibernate/test/ops/MergeTest.java. It fails when parent is checked for updates following transaction commit. While the behavior was observed originally against 3.2.4.sp1, I can also reproduce in 3.2.6. In our system this issue causes org.hibernate.StaleObjectStateException exceptions when load is applied.
I believe I've tracked down the origin of the failure. The merge(persistentParent) call results in child collection of parent being cleared, and consequently marked dirty. This happens when org.hibernate.type.CollectionType method replaceElements() is invoked as part of processing cascade action for merge on parent. It seems dirty flag should be reset after call to this method by CollectionType.replace(), performed when original==target. I see a similar effort was applied to replaceElements() but unfortunately this has no impact for this particular test scenario. I've applied a change to CollectionType.replace() to reset dirty flag if 'original' object was not dirty upon method entry. This resolves the issue for both 3.2.4.sp1 and 3.2.6 and I don't see any adverse impact to execution of Hibernate tests against HSQL. The updated CollectionType class is supplied in attached zip (deltas displayed below).
Definition of children for parent in HBM definition OptLockEntity of org/hibernate/test/ops:
<set name="children"
inverse="true"
cascade="persist,merge,save-update,evict,delete">
<key column="parent"/>
<one-to-many class="VersionedEntity"/>
</set>
Index: test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- test/org/hibernate/test/ops/MergeTest.java (revision 14669)
+++ test/org/hibernate/test/ops/MergeTest.java (working copy)
@@ -248,6 +248,56 @@
cleanup();
}
+ public void testNoExtraUpdatesOnPersistentMergeVersionedWithCollection() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ VersionedEntity parent = new VersionedEntity( "parent", "parent" );
+ VersionedEntity child = new VersionedEntity( "child", "child" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ s.persist( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // parent is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ // load parent so that merge will follow entityIsPersistent path
+ VersionedEntity persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
+ // load children
+ VersionedEntity persistentChild = ( VersionedEntity ) persistentParent.getChildren().iterator().next();
+ VersionedEntity mergedParent = ( VersionedEntity ) s.merge( persistentParent ); // <-- This merge leads to failure
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ assertEquals( "unexpected parent version increment", parent.getVersion(), mergedParent.getVersion() );
+ VersionedEntity mergedChild = ( VersionedEntity ) mergedParent.getChildren().iterator().next();
+ assertEquals( "unexpected child version increment", child.getVersion(), mergedChild.getVersion() );
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node once it is loaded and
+ // make sure we get an update as a result...
+ s = openSession();
+ s.beginTransaction();
+ persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
+ persistentParent.setName( "new name" );
+ persistentParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
+ persistentParent = ( VersionedEntity ) s.merge( persistentParent );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 1 );
+ ///////////////////////////////////////////////////////////////////////
+
+// cleanup();
+ }
+
+
public void testPersistThenMergeInSameTxnWithVersion() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Index: src/org/hibernate/type/CollectionType.java
===================================================================
--- src/org/hibernate/type/CollectionType.java (revision 14669)
+++ src/org/hibernate/type/CollectionType.java (working copy)
@@ -521,7 +521,18 @@
//get the elements back into the target
//TODO: this is a little inefficient, don't need to do a whole
// deep replaceElements() call
- replaceElements( result, target, owner, copyCache, session );
+ if ( target instanceof PersistentCollection ) {
+ if ( ! ( ( PersistentCollection ) target ).isDirty() ) {
+ replaceElements( result, target, owner, copyCache, session );
+ ( ( PersistentCollection ) target ).clearDirty();
+ }
+ else {
+ replaceElements( result, target, owner, copyCache, session );
+ }
+ }
+ else {
+ replaceElements( result, target, owner, copyCache, session );
+ }
result = target;
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 9 months
[Hibernate-JIRA] Created: (EJB-368) Detached entity not reported consistently
by Henriette Harmse (JIRA)
Detached entity not reported consistently
-----------------------------------------
Key: EJB-368
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-368
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.2.GA
Environment: ejb3-persistence-1.0.1.GA.jar
hibernate-entitymanager-3.3.2.GA.jar
hibernate-3.2.6.ga.jar
postgresql-8.3-603.jdbc3.jar
jdk 1.5.0_13/jdk 1.6.0_06
Windows XP
Reporter: Henriette Harmse
Attachments: HibernateTest.zip
The attached code does not fail consistently with a "detached entity" exception.
Under jdk 1.5 (tested with jdk 1.5.0_10 & 1.5.0_13) it fails with a detached entity exception which is correct. Running the same code against jdk 6 (tested with jdk 1.6.0_06 & jdk 1.6.0_03) passes and the records are written to the database.
The same code works against jdk 1.5 (and jdk 6) as well when the <mapping-file>META-INF/emailAddress.xml</mapping-file> and <class>example.domain.EmailAddress</class> are commented out from the persistence.xml file.
The fact that this code does not fail consistently could cause developers to use Hibernate incorrectly which may only be apparent much later into the project.
In order to run the example:
1. Create Postgres database called "example".
2. Create "example" user with username and password "example"
3. Edit the run.cmd and build.cmd files to set your JAVA_HOME.
4. Run "build.cmd".
5. Run "run.cmd".
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 9 months
[Hibernate-JIRA] Created: (HHH-3019) LAZY 1:1 (self-) reference with Inheritance ---> WRONG INTERFACES implemented by Javassist/CGLIB created Proxies
by S.Schnabl (JIRA)
LAZY 1:1 (self-) reference with Inheritance ---> WRONG INTERFACES implemented by Javassist/CGLIB created Proxies
----------------------------------------------------------------------------------------------------------------
Key: HHH-3019
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3019
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.5, 3.2.4.sp1, 3.2.4
Environment: Win-XP, Jboss 4.2.2.GA, Java 1.6, Hibernate 3.2.4Sp1
Reporter: S.Schnabl
Priority: Blocker
Attachments: Hibernate_lazy_1-to-1_with-proxy_TestCase.rar
Hello, following simple testcase:
EntityC, EntityB, EntityA are interfaces and have their respective implementations EntityCImpl, EntityBImpl, EntityAImpl. Inheritance structure is following:
-> EntityC extends EntityB extends EntityA.
Now EntityA has a 1:1 reference for another Entity, which at least must implement Interface 'EntityA' itself. These relation is described like following:
@OneToOne(fetch = FetchType.LAZY, targetEntity = EntityAImpl.class)
public EntityA getNextEntity() {
return this.nextEntity;
}
Testcase: ( for complete testcase and entity structure see attached zip-file. Sorry, but only a jboss-variante attached due to short of time. Simply deploy the server.ear file from release-directory and run the src/client/TestCaseClient.java)
Mainly the testcase does the following:
// create a entityA
EntityA a = new EntityAImpl();
this.em.persist(a);
// create a EntityB, which inherits from EntityA
EntityB b = new EntityBImpl();
this.em.persist(b);
// link B to A
a.setNextEntity(b);
// load EntityA, which has an 1:1 attached EntityB(-Proxy!)
EntityA a = this.em.find(EntityAImpl.class, idEntityA);
// load attached EntityB - should be from expected type EntityB(-Proxy!)
Object b = a.getNextEntity();
// Now check, which Interfaces these EntityB implements: should be
// EntityA and EntityB, but NOT EntityC
if (b instanceof HibernateProxy)
System.out.println("Loaded object is instanceof " + HibernateProxy.class.getSimpleName()); // true
if (b instanceof EntityB)
System.out.println("Loaded object is instanceof " + EntityBImpl.class.getSimpleName()); // true
if (b instanceof EntityC)
System.out.println("Loaded object is instanceof " + EntityCImpl.class.getSimpleName()); // TRUE - ERROR !!!!!!!! That's a bug ! We loaded an EntityB which CANNOT be of Type EntityC !!!!
As you can see, the proxy implents wrongly the Interface EntityC, which must NOT implemented, cause we have only an EntityB linked to EntityA!!
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 9 months
[Hibernate-JIRA] Created: (HHH-3353) Id of an entity is not set when it is a proxy in a collection
by Pascal Perez (JIRA)
Id of an entity is not set when it is a proxy in a collection
-------------------------------------------------------------
Key: HHH-3353
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3353
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.1
Environment: Observed on MySQL 5, unit tested on HSQLDB.
Reporter: Pascal Perez
Attachments: entities.zip
In plain English:
With three entities, Item, Comment and Category such that
Item has multiple Comment (one to many)
Comment has one or no Category (many to one)
have one item with one comment that is linked to one category. Load the item, read the category's id. It's not being set by Hibernate.
In unit test (fails at the very last assertNotSame):
// creating an item
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Item item = new Item();
Comment comment = new Comment();
comment.item = item;
item.comments.add(comment);
comment.category = new Category();
session.save(item);
session.save(comment.category);
assertNotSame("after save, category's id must not be 0",
0, comment.category.id);
tx.commit();
session.close();
// load the item and read the rating's id
session = sessionFactory.openSession();
item = (Item) session.get(Item.class, item.id);
assertNotSame("after load, category's id must not be 0",
0, item.comments.iterator().next().category.id);
session.close();
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 9 months
[Hibernate-JIRA] Created: (HHH-3079) composite-id, sequence and merge call result in a NullPointerException
by Jean-Baptiste Lalanne (JIRA)
composite-id, sequence and merge call result in a NullPointerException
----------------------------------------------------------------------
Key: HHH-3079
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3079
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.5
Environment: Oracle 10/XE
Windows XP
JDK 1.5.0
Reporter: Jean-Baptiste Lalanne
Attachments: oneup-hibernate-test.zip
I got problem during the migration process from HB 2 to 3.2.5.
We use Oracle as DB, problem happens when calling merge on a persistent entity A. This instance A has a relation (one-to-many) to another entity B, this instance is transient and has a generated id (from an oracle sequence), it has also a one-to-many relation to a third entity C. This last one has a composite id that includes a reverse one-to-many link to B.
Here comes mapping definition, see attached eclipse project sample that runs with an Oracle XE :
<!-- entity A -->
<class name="EventImpl" table="EV_EVENT">
<id column="EVT_ID" name="id" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">SEQ_EV_ID</param>
</generator>
</id>
</class>
<!-- entity B -->
<class name="ScheduleImpl" table="EV_SCHEDULE">
<!-- primary key -->
<id column="SCH_ID" name="id" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">SEQ_EV_ID</param>
</generator>
</id>
<property column="LAB_ID" name="labId" not-null="true" type="java.lang.Long"/>
<set name="scheduleDetails" cascade="all-delete-orphan" lazy="false" inverse="true">
<key column="SCH_ID"/>
<one-to-many class="ScheduleDetailImpl"/>
</set>
</class>
<!-- entity C -->
<class name="ScheduleDetailImpl" table="EV_SCHEDULE_DETAIL">
<!-- Cache directive -->
<cache usage="read-write" />
<!-- Composite primary key -->
<composite-id name="id" class="ScheduleDetailImplPK">
<key-many-to-one
class="com.cegedim.oneup.events.srv.domain.schedule.impl.ScheduleImpl"
name="schedule"
column="SCH_ID"
/>
<key-property
column="LINE_RNK"
name="lineRnk"
type="java.lang.Long"
/>
</composite-id>
</class>
When calling merge on A i got this stacktrace, sounds like a bad propagation of the generated B PK during cascading. If i call saveOrUpdate all works fine, the HB2 code was calling the saveOrUpdateCopy and it worked fine. Does anybody got the same issue ? :
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:112)
at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:120)
at org.hibernate.type.EntityType.getHashCode(EntityType.java:279)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:189)
at org.hibernate.engine.EntityKey.generateHashCode(EntityKey.java:104)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:48)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:100)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:194)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:407)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:152)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:126)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at com.cegedim.oneup.events.srv.domain.Test.testMergeScheduleDetails(Test.java:67)
at com.cegedim.oneup.events.srv.domain.Test.run(Test.java:83)
at com.cegedim.oneup.events.srv.domain.Test.main(Test.java:126)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 9 months