-->
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: Mangled id exception
PostPosted: Sat Aug 30, 2003 1:04 am 
Newbie

Joined: Wed Aug 27, 2003 1:33 pm
Posts: 3
I am still a newbie attempting to get the Cat example program running with an Oracle9i database.

The following code:

// Initialize Hibernate (Configuration and SessionFactory)
initHibernate();

// Prepare out
response.setContentType("text/html");
PrintWriter out = response.getWriter();

// Create some Cats
beginTransaction();
createCats(out);
endTransaction(true);

public void createCats(PrintWriter out)
throws HibernateException {


Cat princess = new Cat();
princess.setType('W');
princess.setSex('F');
princess.setWeight(7.4f);
session.save(princess);

Cat max = new Cat();
max.setType('D');
max.setSex('M');
max.setWeight(8.1f);
session.save(max);

Cat sophie = new Cat();
sophie.setType('D');
sophie.setSex('F');
sophie.setWeight(4.1f);
session.save(sophie);
}

private void initHibernate()
throws HibernateException {

// Load Configuration and build SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();
}

private void beginTransaction()
throws HibernateException {

session = sessionFactory.openSession();
transaction = session.beginTransaction();
}

private void endTransaction(boolean commit)
throws HibernateException {

if (commit) {
transaction.commit(); <==== Exception occurs here
} else {
// Don't commit the transaction, can be faster for read-only operations
transaction.rollback();
}
session.close();
}

==========================================

public class Cat {

private long id;
private String color;
private char sex, type;
private float weight;

public Cat() {
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

==========================================

<hibernate-mapping>

<class name="ex.Cat" table="CATS" discriminator-value="W">
<id name="id" column="id" type="int">
<generator class="sequence">
<param name="sequence">id_seq</param>
</generator>

</id>

<discriminator column="type" type="character"/>

<property name="color" not-null="true"/>
<property name="sex" not-null="true" update="false"/>
<property name="weight"/>

<subclass name="ex.DomesticCat" discriminator-value="D">
<property name="name" column="name" type="string"/>
</subclass>
</class>

==========================================

SQL> desc cats;
Name Null? Type
----------------------------------------- -------- ------------------
ID NOT NULL NUMBER(1)
SEX NOT NULL NUMBER(1)
WEIGHT NOT NULL NUMBER(1)
NAME VARCHAR2(30)

SQL> select * from user_sequences;

SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE
------------------------------ ---------- ---------- ------------ - - ----------
LAST_NUMBER
-----------
ID_SEQ 1 1.0000E+27 1 N N 20
41
==========================================

Generates this exception:

net.sf.hibernate.HibernateException: identifier of an instance of ex.Cat altered from 16 to 16

void net.sf.hibernate.impl.SessionImpl.flushEntities()

SessionImpl.java:2141

void net.sf.hibernate.impl.SessionImpl.flushEverything()

SessionImpl.java:2017

void net.sf.hibernate.impl.SessionImpl.flush()

SessionImpl.java:2004

void net.sf.hibernate.transaction.JDBCTransaction.commit()

JDBCTransaction.java:57

void ex.TestServlet.endTransaction(boolean)

TestServlet.java:131

I looked through the source code in SessionImpl.java and I am not sure why this is going off

if ( !entry.id.equals(oid) ) throw new HibernateException(
"identifier of an instance of " +
persister.getClassName() +
" altered from " +
entry.id +
" to " + oid
);

Since the value is 16 in both cases

Thanks, pugmaster


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2003 1:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You've mapped a long as type="int".


instanes of Long are never equal() to an Integer :)


good luck!


Top
 Profile  
 
 Post subject: Same error but slightly different
PostPosted: Thu Sep 11, 2003 2:08 pm 
Newbie

Joined: Thu Sep 11, 2003 2:03 pm
Posts: 1
I'm getting the same exception only the numbers are different
identifier of an instance of com.resqsoft.db.hibernate.JobCandidateHb altered from 410 to 411. The class and mapping file are both a long. What could be the cause of this?

Thanks for any help,
Jeff Cooper


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 2:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
you changed an identifier value


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.