-->
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.  [ 4 posts ] 
Author Message
 Post subject: Experiencing proble with hibernate 2.1 and jcs cache
PostPosted: Wed Oct 01, 2003 2:31 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
I am getting an AssertionFailure - cannot cache a reference to an object with a null id when I try to do an update. Here is the sample code -

NB: This has been working fine for me in hibernate versions 2.0 - 2.03

I have the following two mappings

<class name="Customer" table="customers" polymorphism="explicit">

<cache usage="read-write"/>

<id name="id" unsaved-value="0">
<generator class="sequence">
<param name="sequence">customers_id_seq</param>
</generator>
</id>

<property name="postcode"/>
<many-to-one name="csOwner" class="Employee" column="cs_owner" />
</class>

and

<class name="Employee" table="staff">

<id name="id">
<generator class="sequence">
<param name="sequence">staff_id_seq</param>
</generator>
</id>

<property name="name"/>
</class>

the following main() throws the exception

Session session = null;
Customer customer = null;
SessionFactory factory = null;
try {
// build factory
factory = new Configuration().configure().buildSessionFactory();

System.out.println("Starting first session");
// first session gets customer instance
session = factory.openSession();
customer = (Customer) session.load(Customer.class, new Long(1275));
System.out.println("Loaded customer " + customer.getId() + " has owner " + customer.getCsOwner().getId());
session.flush();
session.connection().commit();
session.close();
System.out.println("Updating address field");
// update a field
customer.setPostcode("TESTING");
System.out.println("Starting second session");
// second session persists update
session = factory.openSession();
session.update(customer);
session.flush();
session.connection().commit();
session.close();

System.out.println("Finished");
factory.close();
} catch (Exception ex){
ex.printStackTrace();
} finally {
if(session!=null)session.close();
if(factory!=null)factory.close();
System.exit(0);
}

If i remove the cache entry in the customer mapping everything is OK, but other wise i get

net.sf.hibernate.AssertionFailure: cannot cache a reference to an object with a null id
at net.sf.hibernate.type.EntityType.disassemble(EntityType.java:89)
at net.sf.hibernate.impl.CacheEntry.disassemble(CacheEntry.java:36)
at net.sf.hibernate.impl.CacheEntry.<init>(CacheEntry.java:27)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:42)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
at com.lab.model.HibBug.main(HibBug.java:46)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Not sure if this would cause that problem, but your definition of unsaved-value is wrong.

Change:
<id name="id" unsaved-value="0">
to
<id name="id" unsaved-value="null">


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 2:50 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
No that makes no difference ( not that i would expect it to since hibernate allows me to define unsaved values to things other than null )


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 4:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
NB: This has been working fine for me in hibernate versions 2.0 - 2.03


Please submit a JIRA issue. Even if it is not a bug in the beta, I still need to know about any changed behaviour. TIA.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.