-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Object Keys different from DB keys ?
PostPosted: Mon Nov 22, 2004 8:02 am 
Newbie

Joined: Mon Nov 22, 2004 7:12 am
Posts: 2
Hello everybody,

I am working on an application using jboss 4.0.0 and hibernate 2.1.6 on Windows 2000 and I'm having a strange problem with my object keys that's drivng me nuts.


I have entered some values into my database by hand to have something to work with. Worked fine.
Then I changed the primary key of one of the objects. Now Hibernate doesn't find it anymore.

To check it, i changed the code to retrieve all Objects from the table and print the Key field. There I noticed that the values Hibernate had for the objects are different from those in the database. Hibernate kept the old value, therefore the object cannot be found. A restart of the application doesn't help, same for deleting jboss's temp-folders and the system's temp folder.

How can I make Hibernate use the changed keys ?

i am using the default ehcache.xml.

Thanks in advance,

Lars



Hibernate version:

2.1.6

Mapping documents:


<hibernate-mapping package="de.mit.backend.mappings">

<class name="Item" table="item">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>

<property name="providerid" not-null="true" column="providerid" type="java.lang.Integer" />
<property name="deleted" column="deleted" type="java.lang.Boolean" />
<property name="name" not-null="true" column="name" type="java.lang.String" />
<property name="locale" not-null="true" column="locale" type="java.lang.String" />

<many-to-one name="item" column="assignedto" class="Item" />
<many-to-one name="itemType" column="type" not-null="true" class="ItemType" />
<list name="metadata" lazy="false" inverse="true">
<key>
<column name="item" not-null="false"/>
</key>
<index column="ordernr" />
<one-to-many class="ItemMetadata"/>
</list>
</class>

<class name="ItemType" table="item_type">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="providerid" not-null="true" column="providerid" type="java.lang.Integer" />
<property name="name" not-null="true" column="name" type="java.lang.String" />
</class>

<class name="ItemMetadata" table="item_metadata">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<!-- property name="defaultobject" column="object" type="java.lang.Object" /-->
<property name="text" column="text" type="java.lang.String" />
<property name="number" column="number" type="java.lang.Integer" />
<property name="date" column="date" type="java.util.Date" />
<property name="ordernr" column="ordernr" type="java.lang.Integer" />
<property name="locale" not-null="true" column="locale" type="java.lang.String" />
<property name="name" not-null="true" column="name" type="java.lang.String" />
<property name="deleted" column="deleted" type="java.lang.Boolean" />
<property name="providerid" not-null="true" column="providerid" type="java.lang.Integer" />
<many-to-one name="item" column="item" not-null="true"/>
<many-to-one name="itemMetadatatype" not-null="true" column="type" class="de.mit.sirius.backend.mappings.ItemMetadatatype" />
</class>

<class name="ItemMetadatatype" table="item_metadatatype">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="providerid" not-null="true" column="providerid" type="java.lang.Integer" />
<property name="name" not-null="true" column="name" type="java.lang.String" />
<property name="defaulttext" column="defaulttext" type="java.lang.String" />
<property name="defaultnumber" column="defaultnumber" type="java.lang.Integer" />
<property name="defaultdate" column="defaultdate" type="java.util.Date" />

<!-- property name="defaultobject" column="object" type="java.lang.Object" /-->
</class>

</hibernate-mapping>


PostgreSQL Table Code:
CREATE TABLE item
(
id serial NOT NULL, (Generates IDs automatically when missing in insert)
"type" int4 NOT NULL,
assignedto int4,
locale text NOT NULL,
deleted bool,
providerid int4 NOT NULL,
name text NOT NULL,
restricted bool DEFAULT false,
CONSTRAINT pk_item PRIMARY KEY (id),
CONSTRAINT fk_item_tyoe FOREIGN KEY ("type") REFERENCES item_type (id) ON UPDATE RESTRICT ON DELETE RESTRICT
)
WITH OIDS;
ALTER TABLE item OWNER TO postgres;


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

No Exception

Name and version of the database you are using:

PostgreSQL 8.0 Beta 4

The generated SQL (show_sql=true):

select item0_.id as id3_, item0_.providerid as providerid3_, item0_.deleted as deleted3_, item0_.name as name3_, item0_.locale as locale3_, item0_.assignedto as assignedto3_, item0_.type as type3_, item1_.id as id0_, item1_.providerid as providerid0_, item1_.deleted as deleted0_, item1_.name as name0_, item1_.locale as locale0_, item1_.assignedto as assignedto0_, item1_.type as type0_, itemtype2_.id as id1_, itemtype2_.providerid as providerid1_, itemtype2_.name as name1_, itemtype3_.id as id2_, itemtype3_.providerid as providerid2_, itemtype3_.name as name2_ from item item0_ left outer join item item1_ on item0_.assignedto=item1_.id left outer join item_type itemtype2_ on item1_.type=itemtype2_.id left outer join item_type itemtype3_ on item0_.type=itemtype3_.id where item0_.id=?

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: Problem solved (OH THE EMBARASSMENT)
PostPosted: Mon Nov 22, 2004 8:28 am 
Newbie

Joined: Mon Nov 22, 2004 7:12 am
Posts: 2
When changing databases, i didn't update hibernate.cfg-xml.

*THUD* *THUD* *THUD* *THUD* ...

(Sound of my head banging repeatedly on my desk :-)


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