-->
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.  [ 1 post ] 
Author Message
 Post subject: HibernateException in checkId b'caus of spaces in identifier
PostPosted: Wed Sep 29, 2004 11:53 am 
Newbie

Joined: Mon Sep 27, 2004 6:18 am
Posts: 1
Hi folks,

We are using Hibernate 2.1.6. Say we have the following situation:

A tire has a many-to-one relationship with a car. (from tire.hbm.xml)

<many-to-one name="car" class="com.company.component.library.model.main.Car" column="F_CAR_ID" cascade="save-update"/>

A car has a many-to-one relationship with the country in which it is manufactured . (from car.hbm.xml).

<many-to-one name="country" class="com.company.component.library.model.main.Country" column="F_Country"/>

If we want to delete a specific tire from the database by means of a named query:

FROM com.company.component.library.model.main.Tire
WHERE (object_id = :id)

in the following way:

- open session
- start transaction
- delete (statement)
- commit transaction
- close session

we get the following hibernate exception when implicitly flushing the session after a commit of the transaction.

net.sf.hibernate.HibernateException: identifier of an instance of com.company.component.library.model.main.Country
altered from 113
Code:
29 spaces
to 113
Code:
no spaces

at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2642)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2465)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2458)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2260)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)

In the constructor of the country we do a trim() of the id (String).

Why does hibernate gets the Country information in a delete and why is it performing the check? Why is the String id not trimmed when the id is requested from the database ? How can we avoid this problem without removing the trim in the constructor of country.

Thanks in advance,

Ron
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.