-->
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: Can a hibernate app share a database with another app
PostPosted: Mon Feb 06, 2006 7:55 am 
Newbie

Joined: Wed Jun 29, 2005 3:25 am
Posts: 2
Can a hibernate application share a database with another application? And be happy at the same time?


Here is my problem:
Let’s make a very simple version of my problem. I have a database with two tables, Person and Address.

Code:
Person:
+-----------+-------------+
| Name      | Type        |
+-----------+-------------+
| id        |int not null |
| name      |Varchar      |
+-----------+-------------+

Address:
+-----------+-------------+
| Name      | Type        |
+-----------+-------------+
| id        |int not null |
| person_id |int not null |
| street    |Varchar      |
| city      |Varchar      |
+-----------+-------------+



And I have a Java Servlet that can access the Oracle database thru Hibernate (let’s call it newApp) and another old application that can access the same database (let’s call it oldApp).

Now I find a person in newApp and show the person and the entire address to the client. In oldApp, I find the same person and delete on of the address.

In newApp, we have a refresh button so we can refresh the data from the database (we make a session.refresh(person)) and see if any data is changed in the database. Here comes the problems. Hibernate refreshes the data from the database by making the following selects:
select * from person where id = ?
select * from adresse where id in (?,?,?) (this person has 3 address)
BUT in oldApp, we have deleted one of the addresses, so one of the address’ id doesn’t exists anymore and we get the following exception

org.hibernate.UnresolvableObjectException: No row with the given identifier exists:

Is it possible to change the mapping (or something else) so hibernate refreshes the addressList when you refresh a person and not just refresh the address that it already knows about.

//Mads


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 10:02 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
From api doc of refresh:
Code:
"Re-read the state of the given instance from the underlying database. It is inadvisable to use this to implement long-running sessions that span many business tasks. This method is, however, useful in certain special circumstances. For example
* where a database trigger alters the object state upon insert or update
* after executing direct SQL (eg. a mass update) in the same session
* after inserting a Blob or Clob



You shouldn't use refresh in your case. Refresh assume the object might have been altered, not that it has been deleted.
You'd better do a
Code:
person = session.load(person.getClass(),person.getId())


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.