-->
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.  [ 3 posts ] 
Author Message
 Post subject: Simple Code experiencing Hibernate Exception on flush()
PostPosted: Sun Sep 21, 2003 11:44 pm 
Newbie

Joined: Sun Sep 21, 2003 11:22 pm
Posts: 8
Location: St. Paul, Minnesota
Trying to put together a quick test of Hibernate - working w/ latest version of Hibernate and Mysql 3.23.54 max

I have the following code and all is fine until I hit the flush(). When it's executed, I get the following exception:
*******
cirrus.hibernate.HibernateException: identifier of an instance of mtmdemo.Permission altered from 1 to 1.0
at cirrus.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:1724)
******
In the object (Permission) & database, the id field is identified as a double.. here is the code that is executed..

Thanks in advance! - PJ

*&*&*&* Code follows *&*&*&*

Transaction tx = null; // Transaction variable to hold our transaction
Datastore ds = Hibernate.createDatastore();

ds.storeClass(Permission.class).storeClass(User.class);
Session session = ds.buildSessionFactory().openSession();
tx = session.beginTransaction();

// Create and store a permission to create users:
Permission permission = new Permission();
permission.setName("user_add");
Long addID = (Long) session.save(permission);

// Create and store a permission to modify users:
permission = new Permission();
permission.setName("user_modify");
session.save(permission);

// Create and store a permission to delete users:
permission = new Permission();
permission.setName("user_delete");
Long delID = (Long) session.save(permission);

// Create a user and add give him some permissions:
User user = new User();
user.setName("Some User");
// Load the "add user" permission and give it to the user:
permission = (Permission) session.load(Permission.class, addID);
user.addPermission(permission);
permission.addUser(user); // associate the user with the permission as well
// Load the "delete user" permission and give it to the same user:
permission = (Permission) session.load(Permission.class, delID);
user.addPermission(permission);
permission.addUser(user);

// Store the user
session.save(user);
// Flush pending object inserts/deletes/updates:
session.flush();

tx.commit(); // Commit the transaction (if we got this far)
*&*&*&*& end of code *&*&*&*&


<hibernate-mapping>
<class name="mtmdemo.Permission" table="permissions">
<id name="ID" type="long" column="permissionid">
<generator class="native"/>
</id>
<property name="name" column="permissionname"/>
<set role="users" table="userpermissions" readonly="true" lazy="true">
<key column="permissionid"/>
<many-to-many class="mtmdemo.User" column="userid"/>
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Simple Code experiencing Hibernate Exception on flush()
PostPosted: Mon Sep 22, 2003 6:44 am 
Regular
Regular

Joined: Mon Sep 08, 2003 4:53 am
Posts: 70
Location: Germany
pjcrump wrote:
Trying to put together a quick test of Hibernate - working w/ latest version of Hibernate and Mysql 3.23.54 max

I have the following code and all is fine until I hit the flush(). When it's executed, I get the following exception:
*******
cirrus.hibernate.HibernateException: identifier of an instance of mtmdemo.Permission altered from 1 to 1.0
at cirrus.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:1724)
******


Are you sure, you are using the latest version of Hibernate? I think cirrus.hibernate.HibernateExpection is thrown by Hibernate 1.x. Since Hibernate 2.x I had expected a net.sf.hibernate.HibernateException!?!


Top
 Profile  
 
 Post subject: Corrected
PostPosted: Mon Sep 22, 2003 11:06 pm 
Newbie

Joined: Sun Sep 21, 2003 11:22 pm
Posts: 8
Location: St. Paul, Minnesota
What a bonehead.. I was using an old jar file. - thanks


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